This is a CloudFormation stack which includes a Lambda function and a CloudWatch event to create/delete A record when launching/terminating EC2 instance.
You need to install following tools before develop and deploy this CloudFormation stack.
- aws-sam-cli
- Run function locally, validate CloudFormation configuration and deploy.
- jq
- Jsonnet
- CloudFormation configuration is written in Jsonnet for templating and make it simple.
DLQ_NAME
: A name of DLQ to send a message when an invocation of function is failed.DNS_SUFFIX
: A suffix of DNS record.- If this value is
.apne1.aws.example.com
and launched instance name isfoo-001
, an A recordfoo-001.apne1.aws.example.com
will be registered.
- If this value is
HOSTED_ZONE_ID
: A Hosted zone ID manipulated by this function.LAMBDA_ROLE
: A role ARN to attach this function.- You should allow following IAM actions to the role.
route53:ChangeResourceRecordSets
ec2:DescribeInstances
sqs:SendMessage
- Need to send a message to a dead letter queue.
- You should allow following IAM actions to the role.
TEST_INSTANCE_ID
: An instance ID for testing. This ID is used to emulate CloudWatch Events and an A record is determined by the instance Name tag. Therefore, you need to specify actual EC2 instance ID.
SAM_ARTIFACT_BUCKET
: A S3 bucket to put an artifact.STACK_NAME
: A CloudFormation stack name you want to create.
This project uses a Docker image provided by LambCI because make an environment building binary same as running environment.
Therefore, you should create a Docker image before develop and deploy.
make init
After changing code, you can build a debug binary and run the Lambda function locally with following make tasks.
make build
make run-create-record # Emulate launching an EC2 instance
make run-delete-record # Emulate terminating and EC2 instance
You can build a release binary and package it with CloudFormation template. That is a simple wrapper to generate CloudFormation configuration from Jsonnet template and execute sam validate
, sam package
and sam deploy
commands.
make release-build
make package
make plan # This task shows a changeset. It can fail when the CloudFormation stack is not created yet.
make deploy
Generated CloudFormation configuration will create a Lambda function and a CloudWatch event invoking the function.
MIT