Deploying applications to ECS Fargate with AWS CDK and Typescript

Aditya Nama
3 min readOct 2, 2022

You will learn how to deploy VPC, CDN, ALB, and ECS Fargate in this blog.

Pre-requisite:

  1. AWS IAM user with administrative privileges
  2. Registered Domain(like example.com) from Route53
  3. Public ACM Certificate for you domain

4. AWS Command-Line Interface Setup

5. Understanding of the services and AWS CDK

and the code.

The code is divided into two different stacks, as follows:

  1. InfraStack includes a VPC with flow logs.
  2. ApplicationStack includes ALB, CDN, ECS Cluster, and Fargate.
InfraStack Template in CloudFormation Designer

Virtual private clouds (VPC)
A virtual private cloud (VPC) is a network that closely matches the conventional network you would run in your own data centre.

The IANA has designated the following IPv4 address ranges as being exclusive to private internets and as such, they are not publicly routable on the global internet:

  • 10.0.0.0/8 IP addresses: 10.0.0.0–10.255.255.255
  • 172.16.0.0/12 IP addresses: 172.16.0.0–172.31.255.255
  • 192.168.0.0/16 IP addresses: 192.168.0.0–192.168.255.255

Please take note that only a fraction of the address ranges “172” and “192” are reserved for private usage. The remaining addresses are routable on the worldwide Internet since they are regarded as “public”.

Creating a VPC with flow logs

ApplicationStack Template in CloudFormation Designer

Creating an ALB with HTTP Listener

Creating a CDN with ALB as origin and attached ACM certificate.

By adding Amazon ECS Exec, it will be possible to communicate with containers directly without having to open ports for incoming traffic or maintain SSH keys or deal with the host container operating system.

Reference:

Creating a s3Bucket and a KMS Key for Encrypted Communication and Logging

Creating ECS Cluster with Command Configurations and Conatiner Insights.

Creating an ECS Fargate Service with AutoScaling, Task Definition, Container, Target Group, HTTPS Listener

After a successfull deployment you can use AWS Cloudshell to exec using the command given below:

aws ecs execute-command --cluster cluster-name \
--task task-id \
--container container-name \
--interactive \
--command "/bin/sh"
AWS CloudShell

Add an A Record in your Route53 hosted zone for the domain.

Route53
Welcome to nginx!

Conclusion

Please share your thoughts about this blog post in the comments box below. Reach out to me on Twitter at @adiintify if you have any questions or require access to the entire repository.

--

--