Example Website Workload – AWS Elastic Container Service (AWS) with ALB, Route53 and Certificate

AWS Docker

The below gives a simple example showing how you can deploy a containerised workload: a NGINX web server in this example which has two (or more) containers (tasks) running on AWS Fargate, presented behind a “Service” definition which is then presented to the Internet via an Application Load Balancer (ALB) where a certificate is obtained and added to the ALB, and AWS Route53 is used to create the DNS record automatically to point at the ALB.

The example offers limited customisation, deploys the EU-WEST-2 Region (London) with two subnets in different Availability Zones: EU-WEST-2A and EU-WEST-2B.

The example uses the domain tristanself.co.uk, which has its nameservers running within AWS Route53, allowing records to be added, changed and removed programatically. However you may substitute in your own domain name as required, however you must ensure that have obtained the AWS Route53 Hosted Zone ID first, which along with the domain name needs to be entered into the variables.tf file.

The example uses a local Terraform state storage, however you may easily swap this to use remote state, see the documentation https://geekmungus.co.uk/?p=4120 if you require it.

Repository

The example Terraform definitions can be found within Gitlab:

Deployment

Once you have cloned the repository, you need to update the following variables within the variables.tf file:

  • route53zone – Add the AWS Route53 Hosted Zone ID you wish to use with your application.
  • domainname – Add the domain name (excluding subdomains) which you wish to use for your application. The Terraform definition adds a www.domainname.com record for you automatically.

The deployment can then be completed with:

terraform apply [--auto-approve]

Leave a Reply

Your email address will not be published. Required fields are marked *