CDK Fargat Docker starter kit
This repository shows an example of how to deploy a simple docker image to a Fargate cluster using AWS CDK.
Read more of CDK at https://docs.aws.amazon.com/CDK/latest/userguide/what-is.html
Features:
- Fargate cluster with multiple availability zones
- Nginx server serving static site (just an example of a docker image)
- Running multiple containers on different context paths
- Pass environment parameters to the container
- Configure a domain namem certificate and a HTTPS listener for the service
- Creates ALB redirect from HTTP to the HTTPS endpoint
- Resource tagging
Configure required AWS account
Check that your AWS account is configured. Assume the role in the shell:
# Install from https://github.com/remind101/assume-role
eval $(assume-role your-aws-role)
Initial setup
First you need to have AWS CDK installed and bootstrap the project on wanted account.
# Install or update CDK globally
npm i -g aws-cdk
# Initialize the environment
cdk bootstrap account-id/region
Domain and certificate setup
- Create a hosted zone (domain name) in AWS Route 53.
- Use AWS Certificate Manager to create a domain certificate
Take a note of the certificated id which is configured in bin/cdk-fargate-docker-starter.ts
.
Incremental deployments
After you have made your changes to the stack, run.
npm run build && cdk deploy
Other commands
npm run build
compile typescript to jsnpm run watch
watch for changes and compilecdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk synth
emits the synthesized CloudFormation template