Sidecar that adds a route53 record on container start, removes it on SIGHUP shutdown.
- Takes the IP address from EC2 or ECS metadata (or
IPADDRESSenvironment) - Creates a weighted A record pointing to
DNSwith TTLDNSTTLin theHOSTEDZONE - When SIGHUP happens, it removes the created record
- Then waits for the record to SYNC in route53 servers
- Finally it waits for DNS TTL time to expire
- Then exits 0
If you want to just add a record and exit, you can use the -register flag. This will add the record and exit immediately.
And to just remove the record, you can use the -unregister flag, this will remove the record and exit immediately.
Environment variables:
IPADDRESSThe ip address, or set aspublic-ipv4(default) to get it from instance metadata,ecsto get it from ECS container metadataDNSThe fully qualified DNS name to setDNSTTLThe TTL time for the DNS A record entry (default 10 seconds)HOSTEDZONEThe AWS Route53 Hosted Zone ID
Test from command line:
make build
./route53-sidecar -dns="test.example.com" -hostedzone=ABCDEFGHIJKLM4 -ipaddress=127.0.0.1
Use the existing docker image locally:
docker run -v ~/.aws:/root/.aws defangio/route53-sidecar -dns="test.example.com" -hostedzone=ABCDEFGHIJKLM4 -ipaddress=127.0.0.1
Build your own docker image:
make docker
Policies required for AWS ECS Role:
- PolicyName: route53
PolicyDocument:
Statement:
- Effect: Allow
Action:
- route53:ChangeResourceRecordSets
Resource: !Sub arn:aws:route53:::hostedzone/${HOSTEDZONEID}
- PolicyName: route53changes
PolicyDocument:
Statement:
- Effect: Allow
Action:
- route53:GetChange
Resource: "*"