How to deploy a container image to Amazon Elastic Container Service (ECS) with Fargate: a beginner’s tutorial [Part 2]

26-Mar-2025. 9 min read

aws Amazon Elastic Container Service (ECS)

Welcome to my 90s Webpage! This page is best viewed with Netscape Navigator!

Amazon Elastic Container Service (ECS) is a fully managed container orchestration service that simplifies the deployment, management, and scaling of containerized applications on AWS. It manages containers without the need to learn Kubernetes. With Fargate, resource management can also be serverless. In this post, you will learn how to deploy a built container image from Amazon Elastic Container Registry (ECR) to Amazon Elastic Container Service (ECS) provisioned with Fargate.

The goal is to do the bare minimum to get a URL/IP from a container image on ECR (image built and pushed in part 1 of this series), let’s get going!

Rainbow Divider

Table of contents

  1. What is Amazon Elastic Container Service (ECS)
  2. Create an Elastic Container Service cluster
  3. Create a task definition for ECS
  4. Create an ECS Service
  5. Important note
  6. Conclusion
Divider

What is Amazon Elastic Container Service (ECS)

Amazon ECS is a fully managed container orchestration service that helps you to more efficiently deploy, manage, and scale containerized applications. You can provision the underlying resource with Fargate or Elastic Compute 2 (EC2) instances.

With Fargate, you can use Amazon ECS to run containers without having to manage servers or clusters of Amazon EC2 instances.

Below is a diagram of how Amazon ECS with Fargate fits in the pipeline with AWS CodePipeline, ECR, and other services including Docker in the mix: (Image placeholder)

Computer Computer

You can also use the AWS CLI to create the cluster, service, and task definition. For this tutorial, however, you will use the AWS console UI to keep things simple.

Rainbow Divider

Create an Elastic Container Service cluster

First, you must create an Amazon Elastic Container Service (ECS) cluster to deploy your Docker Image. For this, after logging in to your AWS console with a user having the correct IAM permissions, search for ecs on the search bar and click on the Clusters link under Top Features as seen below: (Image Placeholder)

Progress

After the clusters listing page loads, click on the Create Cluster orange button on the top right of the page:

7 Upspot

Then, in the form that loads, type in the cluster's name. I am using dev-cluster as an example. In the Infrastructure section, make sure AWS Fargate (serverless) is checked, as follows: (Image Placeholder)

Don’t change any of the other optional settings and scroll to the bottom of the form, where you will see the Create button, click that:

Under Construction

It might take a couple of minutes for the cluster to be created, and it will show up on the Clusters listing page as seen below: (Image Placeholder)

Important Alert

Hurray! Your ECS Cluster with Fargate has been created. In the next section, you will create a task definition.

Rainbow Divider

Create a task definition for ECS

A task is your application's blueprint. It can be created from a JSON file or the AWS Web UI. There are many parameters for a task, but you will only focus on the important ones for the tutorial's scope.

To create a task definition, click on Task definitions as seen in the previous screenshot, it will take you to the Task definitions listing page. Here, click on the Create new task definition orange button and select Create new task definition as seen below: (Image Placeholder)

Stars

On the task definition form, put in the Task definition family as nodejs-apps and make sure you have AWS Fargate selected in the Launch type of Infrastructure requirements:

IE Logo Netscape Navigator Logo

In the task size section, select CPU as .5 vCPU and Memory as 1 GB. As we are running a simple Hello World Node.js application, these resources would be more than enough. Then, select the Task role and Task execution role as ecsTaskExecutionRole.

Now scroll down to the Container-1 section and name the app as hello-world, for the Image URL part, copy the image URI you pushed in part 1 of this series from the container registry page as shown below: (Image Placeholder)

Heart

Then paste the URI in the Image URI field, as it is a single container task; this container will be Essential Container- Yes. In the port mapping section, expose port 3000 in the Container port field with the Protocol being TCP, name the port nodejs-3000, and keep App Protocol as HTTP as selected. It will look like the following: (Image Placeholder)

No Frames

Scroll down to the Environment variables and add an environment variable called PORT with the value 3000:

After that, scroll to the bottom of the form and click the Create button:

You will see the service definition has been created: (Image Placeholder)

Rainbow Divider

Until now, you have only created a service definition, not a service, so no containers are running. In the next section, you will create a service with a task that will bring up the container.

Create an ESC Service

To create a service, click Clusters on the previous screenshot and then click on the cluster name, which should be dev-cluster. In the cluster detail page, on the Services tab, click the Create button on the bottom right of the page to create a service:

Yahoo Week

On the create service form, select the Compute options as Launch type with FARGATE as Launch type and the Platform version as LATEST:

In the Deployment Configuration section, Application type would be pre-selected as Service, in the Family field, select in nodejs-apps and select the Revision to be LATEST. Then name the service hello-world-service, then leave the other settings as-is like Replica has Desired tasks of 1:

Then scroll down to the Networking section, this is the important part. Expand it, make sure the VPC is selected as is. In the Subnets section click Clear current selection and from the drop-down, choose only one subnet that has us-east-1a.

In the Security group section, choose Create new security group. In the Security group name field, type in port-3000-open-from-anywhere. Similarly, type in Open port 3000 from anywhere in the Security group description field.

After that, in the Inbound rule for security groups part, choose Customized TCP as Type; in the Port Range field, type in 3000, and select 'Anywhere' for the source field. Also, make sure that the Public IP is Turned On:

Web Trips

After that, scroll to the bottom of the form and click Create to create the service.

It will take some time for the service to come up, you can click on the Service name hello-world-service:

Under Construction

Then, on the Tasks tab on the service page, click on the task ID:

On the task page, click on the Networking Tab and click the open address beside the Public IP as shown below: (Image Placeholder)

When the IP opens in a new tab browser (if it is Chrome, allow the tab to load it insecurely without HTTPs), then append :3000 to the IP as the Hello World Node.js app is set to run on 3000 with the PORT environment variable, you should see the app run by printing Hello World! on the browser:

Congratulations, your Node.js Hello World container is now running on ECS with Fargate. You should read about the difference between an ESCTask and a service.

Rainbow Divider

Important note

This is a simple example: in a real-life, production-ready application, you would have added a Load Balancer and some DNS records. You would also configure the Security groups, Subnets, VPCs, and IAM settings much more precisely.

Funky

You would have written some form of CI/CD pipeline to deploy the new changes automatically. You would have also added some monitoring and logging to the application.

Web Trips

Delete the cluster, service definition, and container registry if you don’t need them anymore.

Rainbow Divider

Conclusion

As a recap, you learned about Amazon Elastic Container Service (ECS) and how to provision it with Fargate to have serverless resources. Then, this tutorial taught you how to create an ECS task definition. After that, you deployed a service with the correct parameters to expose the service via a public IP without using a Load Balancer. Keep updating your AWS knowledge!

Geshan Manandhar | 26-Mar-2025

« How to create an Amazon Elastic Container Registry (ECR) and push a docker image to it [Part 1]

Divider
Under Construction New! Generate your own 90s page here! Under Construction