I recently co-hosted a developer workshop at the Melbourne AWS Programming & Tools Meetup that I wanted to share with anybody who wants to learn how to create reusable CloudFormation templates for managing AWS resources in a modular way.
The workshop focussed on how to create a VPC with both private and public subnets, and how to deploy bastion and ECS components into these subnets, using Cfhighlander, a feature rich tool & DSL for infrastructure coders that came out of the base2Services R&D lab. Additionally, the workshop covered how to deploy a single nginx service into an ECS cluster using CloudFormation.
More advanced users can also try and deploy a custom-built image to ECR, and then configure ECS service component to use it.
Try it for yourself. You can follow the workshop by visiting the GitHub link below, and completing the steps outlined on this page.
Workshop: github.com/theonestack/cfhighlander-workshops/tree/master/ecs-nginx
Preperation
For successfull completion of all of the steps you will need the Docker image theonestack/workshop-tools:light. If you wish to go the extra step (advanced) section below, you will need the theonestack/workshop-tools:full Dockerfile.
To pull the docker image, execute below from your shell
docker pull theonestack/workshop-tools:light
To start the docker container from the image with interactive prompt, execute below from your shell. It will mount your AWS credentials to the container
docker run -it -e AWS_REGION=ap-southeast-2 -e AWS_DEFAULT_REGION=ap-southeast-2 -w /src -v $PWD:/src -v $HOME/.aws:/root/.aws theonestack/workshop-tools:light bash
You will also need the latest cfhighlander gem. Install it using gem command:
gem install cfhighlander
cfhighlander help
cfhighlander cfcompile
Step 2
- Create local key and upload to AWS
- Add bastion component
- Configure bastion component with custom keypair
- Deploy, update stack, and login to bastion via SSH
Step 3
- Add ECS component
- Add Loadbalanacer component
- Deploy, update stack, visit the web url
Step 4
- Add Nginx as service on ECS component
- Deploy, update stack, visit the web url
Extra Step
- Build custom docker image & push to ECR
- Configure ECS Service component to use custom docker images