Main logic is forked from fsalum/scripts, reworked a bit.
This Lambda will get the list of all HostedZones per account, iterate over them and clean up stale Route53 entries. The stale state is defined by:
- correlating IP addresses (private and public) of running EC2 instances with A entries in Route53
- correlating public and private DNS of EC2 intances with CNAME entries in Route53
- Clone the repo
- Initialize Virtualenv (highly advised)
virtualenv .
- Install requirements
pip install -r requirements.txt
- Put dependencies into deployment ZIP
cd ./lib/python2.7/site-packages
zip -ur10 ~/<path_to_zip>/<name.zip> *
- Put main.py into deployment ZIP
zip -u ~/<path_to_zip>/<name.zip> main.py
- Register Lambda function:
aws lambda create-function \
--region <aws_region> \
--function-name <lambda_function_name> \
--zip-file fileb://<path_to_zip>/<name.zip> \
--role arn:aws:iam:<role_name> \
--handler main.lambda_handler \
--runtime python2.7 \
--timeout 60 \
--memory-size 128 \
--profile <profile-name>
- Additionally, I'd advise setting up CloudWatch event, that will trigger Lambda on schedule.
TODO: move to boto3 or better Golang.