Using CDK for Fargate load-balanced-service using Typescript



In this post, I will share how to create AWS Fargate service using sample provide by AWS.

Basically in term of server-less computing this is equivalent to running containers without worrying about the underlying architecture.

From AWS the definition of Fargate is as follows.

AWS Fargate is a compute engine for Amazon ECS that allows you to run containers without having to manage servers or clusters.


If wanted to explore further what AWS Fargate is then please have a look on the below link from AWS.

https://aws.amazon.com/fargate/.


This is two part post, in first I will share how to create Fargate service by using the ecs-patterns provided by the AWS CDK team, which will create all the VPC networking infrastructure for you like private, public subnets, routes in the route tables, Internet gateway and NAT gateway.

In the second scenario, if you already have the VPC created for you, that is the case for many people.
I will use the ec2.Vpc.fromLookup method to import my VPC on already created VPC.

So, lets build service in Fargate by first way.

Step 1.

Initialization my CDK app as type script.



Step 2.

The code that will generate the Fargate Stack. It is also available on AWS samples GitHub.

https://github.com/aws-samples/aws-cdk-examples/tree/master/typescript/ecs/fargate-load-balanced-service/



Step 3.

Installing the required packages and compiling the code using npm run build.




Step 4.

Now deploying the stack using cdk deploy. In case you do not see any profile parameter, I have export the AWS_PROFILE so that cdk uses as my default profile. This can be verified by using cdk doctor command.





Step 5.

Verifying that my fargate service stack is created in the cloud formation console.


Step 6.

Now destroying the stack via cdk destroy command.




Step 7.

Verifying it in the cloud formation console that stack is deleted.



In the next blog, I will do it in the VPC which I had created outside the cdk stack.

Comments

Popular Posts