This builds the infrastructure for a three-tier web application in AWS.
The following components are built:
- A VPC with a public subnet and 2 private subnets.
- An ECS cluster with autoscaling in the middle private subnet.
- An RDS DB instance in the bottom private subnet with scalable storage.
- A reverse web proxy container in front of a web application container in ECS with the ability to scale.
- An public facing application load-balancer in front of the reverse proxy.
- There is an assumption that AWS credentials are available.
Use the following steps to deploy the stack.
- Clone this repository
git clone https://github.com/sudo-justinwilson/three-tier-web-app.git
- Change to the repo directory:
cd ${/PATH/TO/REPO}
-
Install Terraform by following instructions here
-
Once Terraform is installed and the terraform command is available, run the following commands to build the environment
$ terraform init
$ terraform plan
$ terraform apply
Note:
- This infrastructure is built in the ap-southeast-2 region by default. To change the region, edit the
./variables.tf
. - I have encountered an error which prevents the downloading of the
terraform-aws-modules/vpc/aws
Terraform module. This error was fixed by upgrading to Terraform version 0.12.19. See this bug for more details.
terraform apply
will return multiple outputs, including analb_dns_name
output, which is the DNS record that points to the application load-balancer. Point your browser at the DNS record to see the web application.
The reverse web proxy is an Nginx Docker container. The nginx configuration is stored here on Github. Any pushes to this repository trigger a new build a new container version here in Docker Hub, making a new container image available.
We can then deploy the ECS service revision with the following aws
command (assumes awscli is installed) to deploy the new image to the ECS cluster:
$ aws ecs update-service --cluster arn:aws:ecs:ap-southeast-2:853057580641:cluster/three-tier_ecs_cluster --service arn:aws:ecs:ap-southeast-2:853057580641:service/three-tier-service --force-new-deployment
- Replace the
--service
value with theecs_service_arn
output value
Each directory in the 'modules/' directory is a Terraform module, that can be reused in other projects.
- ecs-cluster
- db (RDS)
- alb
- service (The Docker containers)
Once we're done testing, we can tear-down the environment with the following command:
$ terraform destroy
- Terraform - Used to automate the building of infrastructure
- Docker - Application containerization.
- Nginx - Reverse web proxy.
Submit bugs & feature requests via Github
- Justin Wilson - Initial work - Github
This project is licensed under the GPL3.0 License - see the LICENSE.md file for details