top of page

Tutorial blog to host containers on a serverless infrastructure managed by Amazon ECS

Learning objective:

  • Learn to create Amazon ECS clusters.

  • Learn to create a Task definition for an application.

  • Learn to create a Service from the Task definition.

  • Learn to run the Service on the Amazon ECS Clusters.

Step 1: In AWS management console, search for Amazon ECS service.

Click on Create cluster.

Under Cluster Configuration,

Give Cluster Name as my-ECS-cluster.

Keep the rest as default and choose Create option.

You can see your Cluster is created.

Step 2: In the left panel choose Task definitions.

Click on Create new task definition dropdown and select Create new task definition with json.

Replace the code with the following given code.


"family": "sample-fargate",

"networkMode": "awsvpc",

"containerDefinitions": [


"name": "fargate-app",

"image": "",

"portMappings": [


"containerPort": 80,

"hostPort": 80,

"protocol": "tcp"



"essential": true,

"entryPoint": [




"command": [

"/bin/sh -c \"echo '<html> <head> <title>ECS App from Cloud-PlusPlus</title> <style>body {margin-top: 40px; background-color: #333;} </style> </head><body> <div style=color:white;text-align:center> <h1> ECS App from Cloud-PlusPlus </h1> <h2>Congratulations!</h2> <p>Your application is now running on a container in Amazon ECS.</p> </div></body></html>' > /usr/local/apache2/htdocs/index.html && httpd-foreground\""




"requiresCompatibilities": [



"cpu": "256",

"memory": "512"


After pasting the code, choose to create.

You can see your task definition has been created.

Step 3: Go back to Cluster and select your my-ECS-cluster and scroll down to Services and click on Create.

Scroll down to Deployment configuration and in Family, choose your task definition which you created in the previous step.

Give the Service name as my-ECS-fargate

Scroll down and expand Networking section.

In the Security group, remove the default security group using the cross sign and select use an existing security group and select WebServer-SG.

If you don’t have the WebServer-SG group then select Create a new security group

Under Security group details, give Security group name as WebServer-SG.

Security group description as Security group for Web Servers.

In Inbound rules for security groups,

Type: SSH

Source: Custom


Then select add rule and give the following details,

Type: HTTP

Source: Custom


Scroll down and click on Create.

You can see your service is created under Cluster.

Step 4: In the Services tab, select the Task tab.

Under task tab choose the service you created.

On the task page, in the Configuration section, under Public IP, choose Open address or copy it and open in new tab.

You can see the expected output.

Note: Delete the Service, deregister your Task definition and then delete your Cluster if no longer needed.

Download PDF • 603KB

Was this document helpful? How can we make this document better. Please provide your insights. You can download PDF version for reference.

For your aws certification needs or for aws learning contact us.


Atchaya B
Atchaya B
Mar 11

Easy to understand sir.


Gokul M
Gokul M
Mar 11

well defined


Very useful sir


Easy to the concept sir


Mar 11

Understandable blog

bottom of page