Member-only story
Demystifying AWS CDK’s ECS Pattern
Demystifying AWS CDK’s ECS Pattern
AWS CDK is my first choice when choosing an IaC for AWS (actually, it’s a lie; it’s SST). Using the same programming language for IaC and application development is convenient, allowing me to use the same tools without switching contexts.
Another powerful asset is L3-Constructs or patterns
. L3- constructs simplify multiple resources for common tasks. One of them is the ECS-Pattern
.
However, they abstract away many resources, and in this blog post, I am going to demystify the ApplicationLoadBalancedFargateService
construct.
ApplicationLoadBalancedFargateService
Let’s break down the verbose construct ApplicationLoadBalancedFargateService
into their resources and what code you may need.
Minimal
Below is the minimal code that deploys an Application Load Balancer, a Fargate ECS Cluster and task, Target Groups, and a Listener on port 80. Depending on the deployment region, the code deploys a VPC and at least two private and public subnets.
const service = new ApplicationLoadBalancedFargateService(stack, "AlbFargateService", {
// You have to define a task image option
taskImageOptions: {
image…