AWS ECS reverse proxy using HA Proxy
- In case of dynamic port mapping, you can set HA-Proxy revere proxy container linking your app container.
- Environment variables for linking with app :
LINK_APP
,LINK_PORT
- Task definition (taskdef.json) example
"containerDefinitions": [
// 1. reverse proxy container
{
"name": "<APP_NAME>-rp",
"image": "gnokoheat/ecs-reverse-proxy:latest",
"essential": true,
"memoryReservation": 128,
"portMappings": [
{
"hostPort": 0,
"containerPort": 80,
"protocol": "tcp"
}
],
"links": [
"<APP_NAME>"
],
"environment": [
{
"name": "LINK_PORT",
"value": "<SERVICE_PORT>"
},
{
"name": "LINK_APP",
"value": "<APP_NAME>"
}
]
},
// 2. app container
{
"name": "<APP_NAME>",
...
}
]
- Get the docker hub image
docker pull gnokoheat/ecs-reverse-proxy:latest
- ECS Node.js app example : https://github.com/gnokoheat/ecs-nodejs-app-example
- Infra code (Terraform) for this app : https://github.com/gnokoheat/ecs-with-codepipeline-example-by-terraform