How to Create Task Definitions for Amazon ECS Cluster on AWS

A task definition is required to run Docker containers in Amazon ECS. Docker image to use with each container in task.

The task definition is a text file, in JSON format, that describes one or more containers, up to a maximum of ten, that form your application.

  • Login to aws portal.
  • Click on Services.

 

Fig 1

 

  • Under Containers select Elastic Container Registry.

 

Fig 20

 

  • Click on Task Definitions.

 

Fig 2

 

  • Click on Create New Task Definition.

 

Fig. 3

 

  • Select Launch type compatibility.
  • Click on Next step.

 

Fig. 4

 

  • Provide Task Definition Name.
  • Select existing Task role. By default task role is none.
  • Select Network Mode. By default network mode is bridge.

 

Fig. 5

 

  • Provide Task memory & Task cpu size.

 

Fig. 6

 

  • Click on Add container.

 

Fig. 7

 

  • Provide container name.
  • Provide image URI from ECR.
  • Provide Soft & hard memory limits. Soft limit is smaller than hard limit.
  • Provide port mapping.

 

Fig. 8

 

  • We can add storage.
  • We can send log to Cloudwatch.

 

Fig 9

 

  • Click on Add.

 

Fig 10

 

  • We can Add volume.
  • Click on Add volume.

 

Fig 11

 

  • Provide volume name.
  • Select volume type like EFS.
  • Provide Source Path.
  • Click on Add.

 

Fig 12

 

  • Provide Tag key name & value.
  • Click on Create.

 

Fig 13

 

  • After sometime Task definition is created successfully.

 

Fig 14

 

Create Task Definition using Shell

aws ecs  register-task-definition –family <value> –task-role-arn <value> –execution-role-arn <value>–network-mode <value> –container-definitions –name <value>  –image <value> –volumes <value> –cpu <value> –memory <value>

Leave a Reply