This folder contains Terraform configurations to deploy Docker images of the rails-frontend and sinatra-backend example microservices using Amazon's EC2 Container Service (ECS).
NOTE: Following these instructions will deploy code into your AWS account, including several t2.micro
instances
and two ELBs. All of this qualifies for the AWS Free Tier, but if you've already used
up your credits, running this code may cost you money.
- Sign up for an AWS account. If this is your first time using AWS Marketplace, head over to the ECS AMI Marketplace page and accept the terms of service.
- Install Terraform.
cd terraform-configurations
- Open
vars.tf
, set the environment variables specified at the top of the file, and feel free to tweak any of the other variables to your liking.
-
Configure your AWS credentials as environment variables:
export AWS_ACCESS_KEY_ID=... export AWS_SECRET_ACCESS_KEY=...
-
terraform init
-
terraform plan
-
If the plan looks good, run
terraform apply
to deploy the code into your AWS account. -
Wait a few minutes for everything to deploy. You can monitor the state of the ECS cluster using the ECS Console.
After terraform apply
completes, it will output the URLs of the ELBs of the rails-frontend and sinatra-backend apps.
Every time you want to deploy a new version of one of the microservices, you need to:
- Build a new version of the Docker image for that microservice by following the "How to use your own Docker images"
instructions in the root README (or better yet, create a CI job that builds a new image after every
commit). Set the
rails_frontend_image
andrails_frontend_version
orsinatra_backend_image
andsinatra_backend_version
variables interraform.tfvars
to the image name and version of the new Docker image you just created. - Deploy the new Docker image with Terraform by following the "Deploying" instructions above.