Using Terraform to deploy microservices that communicate with each other
MIT License
This project is a simple example of using Terraform to deploy two microservices to AWS (GCP coming soon!) that can communicate with each other via service discovery. The two microservices are a frontend webserver (using Next.js) and a backend API server (using Flask). You can use any framework/libraries you want for these microservices, what's provided here is just a starting point!
fe
in ECR repository console: https://[YOUR-REGION].console.aws.amazon.com/ecr/create-repository
api
in ECR repository console: https://[YOUR-REGION].console.aws.amazon.com/ecr/create-repository
[YOUR_DOCKER_REPO_ID].dkr.ecr.[YOUR-REGION].amazonaws.com
TF_VAR_docker_repo
in your terminal.export TF_VAR_docker_repo=[YOUR_DOCKER_REPO_ID]
aws ecr get-login-password --region [YOUR-REGION] | docker login --username AWS --password-stdin [YOUR_DOCKER_REPO_ID].dkr.ecr.us-west-2.amazonaws.com
./deploy.sh
Terraform will show you a load balancer URL when it has finished deploying. Wait about 60 seconds before visiting this as it can take time for all of the resources to come online. When it does, you should see "Data from API server route /api/foo: bar
" in your browser.
./destroy.sh
./dev.sh
Visit http://localhost:3000
to see the frontend server running!
Coming soon!
Basic Terraform setup: https://github.com/bradford-hamilton/terraform-ecs-fargate