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
- Host header or path pattern matching for routing
- Fixed response for unrouted requests
- Pass environment variables/parameters to containers
- Configure a domain name with a TLS certificate and a HTTPS listener for the service
- Application load balancer (ALB) redirect from HTTP to the HTTPS endpoint
- Logging
- Resource tagging
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)
First you need to have the needed build tools and the AWS CDK installed. After everything is installed you can bootstrap the project on wanted account.
- Install Node https://nodejs.org
- Install Docker https://www.docker.com/get-started
brew install node awscli
# Install or update CDK globally
npm i -g aws-cdk
# Initial build
npm run build
# Initialize the environment
cdk bootstrap aws://account-id/region
- Create a hosted zone (domain name) in AWS Route 53.
- Use AWS Certificate Manager to create a domain certificate for dev and prod domains.
Take a note of the certificated ARN's that are needed for the deployment.
Check that the stack builds.
npm run build
Bootstrap the account.
cdk bootstrap aws://<account>/eu-west-1 -c certificateIdentifier=e3da8de9-ec36-4c75-addd-cc62701eac3a -c domainName=olmi.be -c subdomainName=site-dev -c environment=dev
Deploy the dev version
cdk deploy -c certificateIdentifier=e3da8de9-ec36-4c75-addd-cc62701eac3a -c domainName=olmi.be -c subdomainName=site-dev -c environment=dev
Change the parameters to deploy a prod version:
cdk deploy -c certificateIdentifier=2ff0d9f4-98be-477a-a29f-86d871d5e31f -c domainName=olmi.be -c subdomainName=site-prod -c environment=prod
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