Amazon ECS
User Guide for AWS Fargate (API Version 2014-11-13)

Creating a Task Definition

Before you can run Docker containers on Amazon ECS, you must create a task definition. You can define multiple containers and data volumes in a task definition. For more information about the parameters available in a task definition, see Task Definition Parameters.

To create a new task definition

  1. Open the Amazon ECS console at https://console.aws.amazon.com/ecs/.

  2. In the navigation pane, choose Task Definitions, Create new Task Definition.

  3. On the Select launch type compatibilities page, choose FARGATE, Next step.

    Note

    The Fargate launch type is not compatible with Windows containers.

  4. (Optional) If you have a JSON representation of your task definition, complete the following steps:

    1. On the Configure task and container definitions page, scroll to the bottom of the page and choose Configure via JSON.

    2. Paste your task definition JSON into the text area and choose Save.

    3. Verify your information and choose Create.

    Scroll to the bottom of the page and choose Configure via JSON.

  5. For Task Definition Name, type a name for your task definition. Up to 255 letters (uppercase and lowercase), numbers, hyphens, and underscores are allowed.

  6. For Task execution IAM role, either select your task execution role or choose Create new role so that the console can create one for you. For more information, seeAmazon ECS Task Execution IAM Role.

  7. For Task size, choose a value for Task memory (GB) and Task CPU (vCPU). The table below shows the valid combinations.

    CPU value Memory value
    256 (.25 vCPU) 512 MB, 1 GB, 2 GB
    512 (.5 vCPU) 1 GB, 2 GB, 3 GB, 4 GB
    1024 (1 vCPU) 2 GB, 3 GB, 4 GB, 5 GB, 6 GB, 7 GB, 8 GB
    2048 (2 vCPU) Between 4 GB and 16 GB in 1 GB increments
    4096 (4 vCPU) Between 8 GB and 30 GB in 1 GB increments
  8. For each container in your task definition, complete the following steps:

    1. Choose Add container.

    2. Fill out each required field and any optional fields to use in your container definitions. More container definition parameters are available in the Advanced container configuration menu. For more information, see Task Definition Parameters.

    3. Choose Add to add your container to the task definition.

  9. (Optional) To define data volumes for your task, choose Add volume. For more information, see Using Data Volumes in Tasks.

    1. For Name, type a name for your volume. Up to 255 letters (uppercase and lowercase), numbers, hyphens, and underscores are allowed.

  10. In the Tags section, specify the key and value for each tag to associate with the task definition. For more information, see Tagging Your Amazon ECS Resources.

  11. Choose Create.

Task Definition Template

An empty task definition template is shown below. You can use this template to create your task definition, which can then be pasted into the console JSON input area or saved to a file and used with the AWS CLI --cli-input-json option. For more information, see Task Definition Parameters.

{ "family": "", "taskRoleArn": "", "executionRoleArn": "", "networkMode": "awsvpc", "containerDefinitions": [ { "name": "", "image": "", "repositoryCredentials": { "credentialsParameter": "" }, "secrets": [ { "name": "", "valueFrom": "" } ], "cpu": 0, "memory": 0, "memoryReservation": 0, "links": [ "" ], "portMappings": [ { "containerPort": 0, "hostPort": 0, "protocol": "tcp" } ], "essential": true, "entryPoint": [ "" ], "command": [ "" ], "environment": [ { "name": "", "value": "" } ], "mountPoints": [ { "sourceVolume": "", "containerPath": "", "readOnly": true } ], "volumesFrom": [ { "sourceContainer": "", "readOnly": true } ], "linuxParameters": { "capabilities": { "add": [ "" ], "drop": [ "" ] }, "devices": [ { "hostPath": "", "containerPath": "", "permissions": [ "mknod" ] } ], "initProcessEnabled": true, "sharedMemorySize": 0, "tmpfs": [ { "containerPath": "", "size": 0, "mountOptions": [ "" ] } ] }, "hostname": "", "user": "", "workingDirectory": "", "disableNetworking": true, "privileged": true, "readonlyRootFilesystem": true, "dnsServers": [ "" ], "dnsSearchDomains": [ "" ], "extraHosts": [ { "hostname": "", "ipAddress": "" } ], "dockerSecurityOptions": [ "" ], "dockerLabels": { "KeyName": "" }, "ulimits": [ { "name": "rttime", "softLimit": 0, "hardLimit": 0 } ], "logConfiguration": { "logDriver": "json-file", "options": { "KeyName": "" } }, "healthCheck": { "command": [ "" ], "interval": 0, "timeout": 0, "retries": 0, "startPeriod": 0 } } ], "volumes": [ { "name": "", "host": { "sourcePath": "" }, "dockerVolumeConfiguration": { "scope": "shared", "autoprovision": true, "driver": "", "driverOpts": { "KeyName": "" }, "labels": { "KeyName": "" } } } ], "placementConstraints": [ { "type": "memberOf", "expression": "" } ], "requiresCompatibilities": [ "EC2" ], "tags": [ { "key": "string", "value": "string" } ], "cpu": "", "memory": "" }

You can generate this task definition template using the following AWS CLI command:

aws ecs register-task-definition --generate-cli-skeleton

On this page: