Skip to content

Instantly share code, notes, and snippets.

@davidejones
Created February 24, 2025 18:03
Show Gist options
  • Select an option

  • Save davidejones/d90bc2b0f0c10e48794643a6f99b94a8 to your computer and use it in GitHub Desktop.

Select an option

Save davidejones/d90bc2b0f0c10e48794643a6f99b94a8 to your computer and use it in GitHub Desktop.
Traefik App runner

Setup

Image

  • Create an ecr registry called mytraefik
  • Update app1 and app2 server urls in dynamic_conf.yml to point to other apprunner urls you already have
  • Update .example.com usage in dynamic_conf.yml to a domain you have and will link to
  • Build image locally docker image build -t mytraefik:latest .
  • Tag image docker tag mytraefik:latest <yourawsaccount>.dkr.ecr.us-east-1.amazonaws.com/mytraefik:latest
  • Push image to ecr docker push <yourawsaccount>.dkr.ecr.us-east-1.amazonaws.com/mytraefik:latest

Apprunner

  • Create a new app in apprunner called mytraefik
  • Make sure port 80 is set
  • Link a custom domain the same one you use in the dynamic_conf.yml config and enter as a wildcard e.g *.example.com

Once deployed you should be able to visit app1.example.com and app2.example.com but have the apprunner containers you already have be served to you

FROM traefik:v3.3.3
COPY traefik.yml /etc/traefik/traefik.yml
COPY dynamic_conf.yml /etc/traefik/dynamic_conf.yml
EXPOSE 80
ENTRYPOINT ["/entrypoint.sh"]
CMD ["traefik"]
## Dynamic configuration
http:
# Add the routers
routers:
app1:
entrypoints: http
rule: "Host(`app1.example.com`)"
service: "app1"
app2:
entrypoints: http
rule: "Host(`app2.example.com`)"
service: "app2"
# Add the services
services:
app1:
loadBalancer:
passHostHeader: false
servers:
- url: https://12345.us-east-1.awsapprunner.com
app2:
loadBalancer:
passHostHeader: false
servers:
- url: https://67890.us-east-1.awsapprunner.com
providers:
file:
filename: /etc/traefik/dynamic_conf.yml
entryPoints:
http:
address: ":80"
https:
address: ":443"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment