26-Mar-2025. 9 min read
aws Amazon Elastic Container Service (ECS)
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!
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)
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.
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 on the search bar and click on the Clusters link under Top Features as seen below: (Image Placeholder)
After the clusters listing page loads, click on the Create Cluster orange button on the top right of the page:
Then, in the form that loads, type in the cluster's name. I am using 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:
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)
Hurray! Your ECS Cluster with Fargate has been created. In the next section, you will create a task definition.
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)
On the task definition form, put in the Task definition family as and make sure you have AWS Fargate selected in the Launch type of Infrastructure requirements:
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 , 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)
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 , and keep App Protocol as HTTP as selected. It will look like the following: (Image Placeholder)
Scroll down to the Environment variables and add an environment variable called 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)
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.
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:
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 , 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 . Similarly, type in 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:
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:
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.
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.
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.
Delete the cluster, service definition, and container registry if you don’t need them anymore.
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.
Geshan Manandhar | 26-Mar-2025
« How to create an Amazon Elastic Container Registry (ECR) and push a docker image to it [Part 1]