Step-by-Step Guide to Deploy Containerized Applications to AWS Fargate
AWS Fargate is a serverless compute engine for Amazon ECS and Amazon EKS. With Fargate, you can effortlessly build, run, and scale containerized applications without managing the underlying infrastructure. Let’s take a look at how you can deploy these applications.
How to Deploy a Containerized Application to AWS Fargate
The below steps apply to any programming language or library. However, we assume the code is written in Python FastAPI.
Install FastAPI and Uvicorn. Write the code in the main.py file and run the command pip freeze > requirements.txt to generate the requirements.txt file containing the application’s dependencies.
Next, write the Dockerfile. In this file, observe which port the application will run on. You will need this information when configuring the AWS Application Load Balancer (ALB) later.
Next comes the container build and push process. On the ECS page, create a repository. Then authenticate your Docker client to your registry. Finally, build a Docker image, tag it with the repository’s URL, and then push it to the repository. At this point, your container image will be stored in Amazon Elastic Container Registry (ECR).
On Amazon ECS, navigate to task definitions and specify the configurations for Docker image, container CPU and memory requirements, networking mode, and instance type. Also provide the task definition family name, container name, and image URI and set the container port to the number identified in Step 2. Make sure to choose AWS Fargate for the app environment and fill in the OS field.
Create a cluster, provide the cluster name, and choose the VPC and subnets. The cluster will already be configured for AWS Fargate by default. Then you can set up a load balancer and target group. Under “load balancer types”, select Application Load Balancer.
Fill in the details for basic configuration and network mapping. For the latter, use the default VPC and select at least two AWS Availability Zones (AZ).
Create a security group and give it a name and description. Add a new rule for inbound rules. Choose HTTP under type and Anywhere under source. Leave the outbound rules section intact.
Create the target group and populate the details for the basic configuration, including the target group name and port number (see Step 2). Leave the section on register targets untouched.
Go to the ECS console and choose your cluster (Step 5). Choose Fargate for Launch type and fill in the OS and service name. Also use the task definition (Step 4). Configure the network by choosing the default VPC and subnets (same as the load balancer). Then create a new security group.
This is where you will attach services to the load balancer. Choose Application Load Balancer and click on Add to load balancer to confirm the container name and port. Also select the target group you created in Step 7. Then go to review and create. You can also set up auto scaling if required.
To allow load balancer access, modify the ECS service’s security group. Edit inbound rules and choose the load balancer’s security group. Finally, go back to the load balancer and open the DNS name in the new tab.
We hope you found this step-by-step guide useful. For more information on how to leverage AWS Fargate for your containerized applications, talk to the Fargate specialists at Axcess.io.