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": "public.ecr.aws/docker/library/httpd:latest",

"portMappings": [

{

"containerPort": 80,

"hostPort": 80,

"protocol": "tcp"

}

],

"essential": true,

"entryPoint": [

"sh",

"-c"

],

"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": [

"FARGATE"

],

"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

Values: 0.0.0.0/0

Then select add rule and give the following details,

Type: HTTP

Source: Custom

Values: 0.0.0.0/0

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.



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.

12 Yorum


Atchaya B
Atchaya B
11 Mar

Easy to understand sir.

Beğen

Gokul M
Gokul M
11 Mar

well defined

Beğen

Very useful sir

Beğen

Easy to the concept sir

Beğen

Gokulnath
Gokulnath
11 Mar

Understandable blog

Beğen
bottom of page