TITLE: Create ECS Task Set with AWS CLI DESCRIPTION: This AWS CLI command creates a new task set for an Amazon ECS service. It specifies the target cluster, service name, task definition ARN (with version), and network configuration using `awsvpcConfiguration`, including subnets and security groups. This example is tailored for services using an external deployment controller. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/create-task-set.rst#_snippet_0 LANGUAGE: Bash CODE: ``` aws ecs create-task-set \ --cluster MyCluster \ --service MyService \ --task-definition MyTaskDefinition:2 \ --network-configuration "awsvpcConfiguration={subnets=[subnet-12344321],securityGroups=[sg-12344321]}" ``` ---------------------------------------- TITLE: JSON Output for AWS CLI Create Task Set DESCRIPTION: This JSON object represents the successful response from the `aws ecs create-task-set` command. It contains detailed information about the newly created task set, such as its unique ID, Amazon Resource Name (ARN), current status, associated task definition, resource counts, timestamps, launch type, network configuration, and scaling parameters. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/create-task-set.rst#_snippet_1 LANGUAGE: JSON CODE: ``` { "taskSet": { "id": "ecs-svc/1234567890123456789", "taskSetArn": "arn:aws:ecs:us-west-2:123456789012:task-set/MyCluster/MyService/ecs-svc/1234567890123456789", "status": "ACTIVE", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/MyTaskDefinition:2", "computedDesiredCount": 0, "pendingCount": 0, "runningCount": 0, "createdAt": 1557128360.711, "updatedAt": 1557128360.711, "launchType": "EC2", "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-12344321" ], "securityGroups": [ "sg-12344321" ], "assignPublicIp": "DISABLED" } }, "loadBalancers": [], "serviceRegistries": [], "scale": { "value": 0.0, "unit": "PERCENT" }, "stabilityStatus": "STABILIZING", "stabilityStatusAt": 1557128360.711 } } ``` ---------------------------------------- TITLE: Create AWS ECS Service with EC2 Launch Type DESCRIPTION: This example illustrates how to create an Amazon ECS service utilizing the EC2 launch type. It defines the cluster, service name, task definition, and desired count for the service. The service is configured to maintain a single instance of the specified task definition. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/create-service.rst#_snippet_1 LANGUAGE: aws-cli CODE: ``` aws ecs create-service \ --cluster MyCluster \ --service-name ecs-simple-service \ --task-definition sleep360:2 \ --desired-count 1 ``` LANGUAGE: json CODE: ``` { "service": { "serviceArn": "arn:aws:ecs:us-west-2:123456789012:service/MyCluster/ecs-simple-service", "serviceName": "ecs-simple-service", "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster", "loadBalancers": [], "serviceRegistries": [], "status": "ACTIVE", "desiredCount": 1, "runningCount": 0, "pendingCount": 0, "launchType": "EC2", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/sleep360:2", "deploymentConfiguration": { "maximumPercent": 200, "minimumHealthyPercent": 100 }, "deployments": [ { ``` ---------------------------------------- TITLE: Create ECS Service with EBS Volume Configuration using AWS CLI DESCRIPTION: This AWS CLI command demonstrates how to create an Amazon ECS service and configure Amazon EBS volumes for its tasks. It utilizes the `--cli-input-json` option to pass a JSON file containing the service definition, including volume configurations. An Amazon ECS infrastructure role with `AmazonECSInfrastructureRolePolicyForVolumes` is required for this operation. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/create-service.rst#_snippet_4 LANGUAGE: aws-cli CODE: ``` aws ecs create-service \ --cli-input-json file://ecs-simple-service-ebs.json ``` ---------------------------------------- TITLE: Describe a Single ECS Task using AWS CLI DESCRIPTION: This example demonstrates how to retrieve details for a single Amazon ECS task using the 'aws ecs describe-tasks' command. The task can be specified by its full ARN or ID. The output provides comprehensive information about the task, its containers, network bindings, and status. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/describe-tasks.rst#_snippet_0 LANGUAGE: bash CODE: ``` aws ecs describe-tasks \ --cluster MyCluster \ --tasks arn:aws:ecs:us-east-1:123456789012:task/MyCluster/4d590253bb114126b7afa7b58EXAMPLE ``` LANGUAGE: json CODE: ``` { "tasks": [ { "attachments": [], "attributes": [ { "name": "ecs.cpu-architecture", "value": "x86_64" } ], "availabilityZone": "us-east-1b", "clusterArn": "arn:aws:ecs:us-east-1:123456789012:cluster/MyCluster", "connectivity": "CONNECTED", "connectivityAt": "2021-08-11T12:21:26.681000-04:00", "containerInstanceArn": "arn:aws:ecs:us-east-1:123456789012:container-instance/test/025c7e2c5e054a6790a29fc1fEXAMPLE", "containers": [ { "containerArn": "arn:aws:ecs:us-east-1:123456789012:container/MyCluster/4d590253bb114126b7afa7b58eea9221/a992d1cc-ea46-474a-b6e8-24688EXAMPLE", "taskArn": "arn:aws:ecs:us-east-1:123456789012:task/MyCluster/4d590253bb114126b7afa7b58EXAMPLE", "name": "simple-app", "image": "httpd:2.4", "runtimeId": "91251eed27db90006ad67b1a08187290869f216557717dd5c39b37c94EXAMPLE", "lastStatus": "RUNNING", "networkBindings": [ { "bindIP": "0.0.0.0", "containerPort": 80, "hostPort": 80, "protocol": "tcp" } ], "networkInterfaces": [], "healthStatus": "UNKNOWN", "cpu": "10", "memory": "300" } ], "cpu": "10", "createdAt": "2021-08-11T12:21:26.681000-04:00", "desiredStatus": "RUNNING", "enableExecuteCommand": false, "group": "service:testupdate", "healthStatus": "UNKNOWN", "lastStatus": "RUNNING", "launchType": "EC2", "memory": "300", "overrides": { "containerOverrides": [ { "name": "simple-app" } ], "inferenceAcceleratorOverrides": [] }, "pullStartedAt": "2021-08-11T12:21:28.234000-04:00", "pullStoppedAt": "2021-08-11T12:21:33.793000-04:00", "startedAt": "2021-08-11T12:21:34.945000-04:00", "startedBy": "ecs-svc/968695068243EXAMPLE", "tags": [], "taskArn": "arn:aws:ecs:us-east-1:123456789012:task/MyCluster/4d590253bb114126b7afa7b58eea9221", "taskDefinitionArn": "arn:aws:ecs:us-east-1:123456789012:task-definition/console-sample-app-static2:1", "version": 2 } ], "failures": [] } ``` ---------------------------------------- TITLE: Configure Amazon EBS volume for AWS ECS task at start DESCRIPTION: This example shows how to start an AWS ECS task and configure an encrypted Amazon EBS volume using the `aws ecs start-task` command with the `--cli-input-json` option. It requires an Amazon ECS infrastructure role with the `AmazonECSInfrastructureRolePolicyForVolumes` managed policy. The task definition must have the same volume name as specified in the JSON input file. The output shows the task details including the EBS volume attachment. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/start-task.rst#_snippet_1 LANGUAGE: bash CODE: ``` aws ecs start-task \ --cli-input-json file://ebs.json \ --container-instances 765936fadbdd46b5991a4bd70c2a43d4 ``` LANGUAGE: json CODE: ``` { "cluster": "default", "taskDefinition": "mytaskdef", "networkConfiguration":{ "awsvpcConfiguration":{ "assignPublicIp": "ENABLED", "securityGroups": ["sg-12344321"], "subnets":["subnet-12344321"] } }, "volumeConfigurations": [ { "name": "myEBSVolume", "managedEBSVolume": { "volumeType": "gp3", "sizeInGiB": 100, "roleArn":"arn:aws:iam::123456789012:role/ecsInfrastructureRole", "encrypted": true, "kmsKeyId": "arn:aws:kms:region:123456789012:key/1234abcd-12ab-34cd-56ef-1234567890ab" } } ] } ``` LANGUAGE: json CODE: ``` { "tasks": [ { "attachments": [ { "id": "aea29489-9dcd-49f1-8164-4d91566e1113", "type": "ElasticNetworkInterface", "status": "PRECREATED", "details": [ { "name": "subnetId", "value": "subnet-12344321" } ] }, { "id": "f29e1222-9a1e-410f-b499-a12a7cd6d42e", "type": "AmazonElasticBlockStorage", "status": "CREATED", "details": [ { "name": "roleArn", "value": "arn:aws:iam::123456789012:role/ecsInfrastructureRole" }, { "name": "volumeName", "value": "myEBSVolume" }, { "name": "deleteOnTermination", "value": "true" } ] } ] } ] } ``` ---------------------------------------- TITLE: Describe Multiple ECS Tasks using AWS CLI DESCRIPTION: This example shows how to retrieve details for multiple Amazon ECS tasks simultaneously using the 'aws ecs describe-tasks' command. Tasks are specified by their full IDs. The command returns a list of task objects, each containing detailed information. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/describe-tasks.rst#_snippet_1 LANGUAGE: bash CODE: ``` aws ecs describe-tasks \ --cluster MyCluster \ --tasks "74de0355a10a4f979ac495c14EXAMPLE" "d789e94343414c25b9f6bd59eEXAMPLE" ``` LANGUAGE: json CODE: ``` { "tasks": [ { "attachments": [ { "id": "d9e7735a-16aa-4128-bc7a-b2d51EXAMPLE", "type": "ElasticNetworkInterface", "status": "ATTACHED", "details": [ { "name": "subnetId", "value": "subnet-0d0eab1bb3EXAMPLE" }, { "name": "networkInterfaceId", "value": "eni-0fa40520aeEXAMPLE" }, { "name": "macAddress", "value": "" ``` ---------------------------------------- TITLE: Start a new AWS ECS task with default settings DESCRIPTION: This example demonstrates how to start a new task using the `aws ecs start-task` command. It uses the latest revision of a specified task definition (`sleep360`) on a given container instance in the default cluster. The output shows the details of the newly started task, including its ARN, status, and container information. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/start-task.rst#_snippet_0 LANGUAGE: bash CODE: ``` aws ecs start-task \ --task-definition sleep360 \ --container-instances 765936fadbdd46b5991a4bd70c2a43d4 ``` LANGUAGE: json CODE: ``` { "tasks": [ { "taskArn": "arn:aws:ecs:us-west-2:123456789012:task/default/666fdccc2e2d4b6894dd422f4eeee8f8", "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/default", "taskDefinitionArn": "arn:aws:ecs:us-west-2:123456789012:task-definition/sleep360:3", "containerInstanceArn": "arn:aws:ecs:us-west-2:123456789012:container-instance/default/765936fadbdd46b5991a4bd70c2a43d4", "overrides": { "containerOverrides": [ { "name": "sleep" } ] }, "lastStatus": "PENDING", "desiredStatus": "RUNNING", "cpu": "128", "memory": "128", "containers": [ { "containerArn": "arn:aws:ecs:us-west-2:123456789012:container/75f11ed4-8a3d-4f26-a33b-ad1db9e02d41", "taskArn": "arn:aws:ecs:us-west-2:123456789012:task/default/666fdccc2e2d4b6894dd422f4eeee8f8", "name": "sleep", "lastStatus": "PENDING", "networkInterfaces": [], "cpu": "10", "memory": "10" } ], "version": 1, "createdAt": 1563421494.186, "group": "family:sleep360", "launchType": "EC2", "attachments": [], "tags": [] } ], "failures": [] } ``` ---------------------------------------- TITLE: Enable ECS Task Protection with AWS CLI DESCRIPTION: This snippet shows how to enable task protection for an Amazon ECS task using the `aws ecs update-task-protection` command. Task protection prevents termination during scale-in events from Deployments or Service AutoScaling. Users can specify a custom expiration period from 1 to 2,880 minutes; otherwise, it defaults to 2 hours. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/update-task-protection.rst#_snippet_0 LANGUAGE: aws-cli CODE: ``` aws ecs update-task-protection \ --cluster ECS-project-update-cluster \ --tasks c43ed3b1331041f289316f958adb6a24 \ --protection-enabled \ --expires-in-minutes 300 ``` LANGUAGE: JSON CODE: ``` { "protectedTasks": [ { "taskArn": "arn:aws:ecs:us-west-2:123456789012:task/c43ed3b1331041f289316f958adb6a24", "protectionEnabled": true, "expirationDate": "2024-09-14T19:53:36.687000-05:00" } ], "failures": [] } ``` ---------------------------------------- TITLE: Create AWS ECS Service with Fargate Launch Type DESCRIPTION: This example demonstrates how to create an Amazon ECS service configured to use the Fargate launch type. It specifies the cluster, service name, task definition, desired count, and detailed network configuration including subnets, security groups, and public IP assignment. The service is also tagged with multiple key-value pairs. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/create-service.rst#_snippet_0 LANGUAGE: aws-cli CODE: ``` aws ecs create-service \ --cluster MyCluster \ --service-name MyService \ --task-definition sample-fargate:1 \ --desired-count 2 \ --launch-type FARGATE \ --platform-version LATEST \ --network-configuration 'awsvpcConfiguration={subnets=[subnet-12344321],securityGroups=[sg-12344321],assignPublicIp=ENABLED}' \ --tags key=key1,value=value1 key=key2,value=value2 key=key3,value=value3 ``` LANGUAGE: json CODE: ``` { "service": { "serviceArn": "arn:aws:ecs:us-west-2:123456789012:service/MyCluster/MyService", "serviceName": "MyService", "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster", "loadBalancers": [], "serviceRegistries": [], "status": "ACTIVE", "desiredCount": 2, "runningCount": 0, "pendingCount": 0, "launchType": "FARGATE", "platformVersion": "LATEST", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/sample-fargate:1", "deploymentConfiguration": { "maximumPercent": 200, "minimumHealthyPercent": 100 }, "deployments": [ { "id": "ecs-svc/1234567890123456789", "status": "PRIMARY", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/sample-fargate:1", "desiredCount": 2, "pendingCount": 0, "runningCount": 0, "createdAt": 1557119253.821, "updatedAt": 1557119253.821, "launchType": "FARGATE", "platformVersion": "1.3.0", "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-12344321" ], "securityGroups": [ "sg-12344321" ], "assignPublicIp": "ENABLED" } } } ], "roleArn": "arn:aws:iam::123456789012:role/aws-service-role/ecs.amazonaws.com/AWSServiceRoleForECS", "events": [], "createdAt": 1557119253.821, "placementConstraints": [], "placementStrategy": [], "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-12344321" ], "securityGroups": [ "sg-12344321" ], "assignPublicIp": "ENABLED" } }, "schedulingStrategy": "REPLICA", "tags": [ { "key": "key1", "value": "value1" }, { "key": "key2", "value": "value2" }, { "key": "key3", "value": "value3" } ], "enableECSManagedTags": false, "propagateTags": "NONE" } } ``` ---------------------------------------- TITLE: List All ECS Tasks in a Cluster using AWS CLI DESCRIPTION: This example demonstrates how to use the `aws ecs list-tasks` command to retrieve a list of all running tasks within a specified Amazon ECS cluster. It shows the basic syntax for listing tasks without additional filters. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/list-tasks.rst#_snippet_0 LANGUAGE: bash CODE: ``` aws ecs list-tasks --cluster default ``` ---------------------------------------- TITLE: Register ECS Task Definition via JSON File DESCRIPTION: Demonstrates how to register an Amazon ECS task definition using the AWS CLI by referencing a local JSON file for container definitions. Includes the AWS CLI command, the content of the input JSON file, and the expected JSON output from the command. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/register-task-definition.rst#_snippet_0 LANGUAGE: AWS CLI CODE: ``` aws ecs register-task-definition \ --cli-input-json file:///sleep360.json ``` LANGUAGE: JSON CODE: ``` { "containerDefinitions": [ { "name": "sleep", "image": "busybox", "cpu": 10, "command": [ "sleep", "360" ], "memory": 10, "essential": true } ], "family": "sleep360" } ``` LANGUAGE: JSON CODE: ``` { "taskDefinition": { "status": "ACTIVE", "family": "sleep360", "placementConstraints": [], "compatibilities": [ "EXTERNAL", "EC2" ], "volumes": [], "taskDefinitionArn": "arn:aws:ecs:us-east-1:123456789012:task-definition/sleep360:1", "containerDefinitions": [ { "environment": [], "name": "sleep", "mountPoints": [], "image": "busybox", "cpu": 10, "portMappings": [], "command": [ "sleep", "360" ], "memory": 10, "essential": true, "volumesFrom": [] } ], "revision": 1 } } ``` ---------------------------------------- TITLE: Disable ECS Task Protection with AWS CLI DESCRIPTION: This snippet demonstrates how to disable task protection for an Amazon ECS task using the `aws ecs update-task-protection` command with the `--no-protection-enabled` flag. Disabling protection allows tasks to be terminated during scale-in from Deployments or Service AutoScaling. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/update-task-protection.rst#_snippet_1 LANGUAGE: aws-cli CODE: ``` aws ecs update-task-protection \ --cluster ECS-project-update-cluster \ --tasks c43ed3b1331041f289316f958adb6a24 \ --no-protection-enabled ``` LANGUAGE: JSON CODE: ``` { "protectedTasks": [ { "taskArn": "arn:aws:ecs:us-west-2:123456789012:task/c43ed3b1331041f289316f958adb6a24", "protectionEnabled": false } ], "failures": [] } ``` ---------------------------------------- TITLE: Run ECS Task on Default Cluster with AWS CLI DESCRIPTION: This example demonstrates how to run an Amazon ECS task on the default cluster using the AWS CLI. It includes the use of a client token for idempotency. The output shows the details of the launched task, including its ARN, status, and container information. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/run-task.rst#_snippet_0 LANGUAGE: aws-cli CODE: ``` aws ecs run-task \ --cluster default \ --task-definition sleep360:1 \ --client-token 550e8400-e29b-41d4-a716-446655440000 ``` LANGUAGE: json CODE: ``` { "tasks": [ { "attachments": [], "attributes": [ { "name": "ecs.cpu-architecture", "value": "x86_64" } ], "availabilityZone": "us-east-1b", "capacityProviderName": "example-capacity-provider", "clusterArn": "arn:aws:ecs:us-east-1:123456789012:cluster/default", "containerInstanceArn": "arn:aws:ecs:us-east-1:123456789012:container-instance/default/bc4d2ec611d04bb7bb97e83ceEXAMPLE", "containers": [ { "containerArn": "arn:aws:ecs:us-east-1:123456789012:container/default/d6f51cc5bbc94a47969c92035e9f66f8/75853d2d-711e-458a-8362-0f0aEXAMPLE", "taskArn": "arn:aws:ecs:us-east-1:123456789012:task/default/d6f51cc5bbc94a47969c9203EXAMPLE", "name": "sleep", "image": "busybox", "lastStatus": "PENDING", "networkInterfaces": [], "cpu": "10", "memory": "10" } ], "cpu": "10", "createdAt": "2023-11-21T16:59:34.403000-05:00", "desiredStatus": "RUNNING", "enableExecuteCommand": false, "group": "family:sleep360", "lastStatus": "PENDING", "launchType": "EC2", "memory": "10", "overrides": { "containerOverrides": [ { "name": "sleep" } ], "inferenceAcceleratorOverrides": [] }, "tags": [], "taskArn": "arn:aws:ecs:us-east-1:123456789012:task/default/d6f51cc5bbc94a47969c9203EXAMPLE", "taskDefinitionArn": "arn:aws:ecs:us-east-1:123456789012:task-definition/sleep360:1", "version": 1 } ], "failures": [] } ``` ---------------------------------------- TITLE: Register ECS Task Definition via Inline JSON String DESCRIPTION: Illustrates how to register an Amazon ECS task definition using the AWS CLI by directly embedding the container definitions as an escaped JSON string parameter. This method avoids the need for a separate JSON file and produces identical output to the file-based method. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/register-task-definition.rst#_snippet_1 LANGUAGE: AWS CLI CODE: ``` aws ecs register-task-definition \ --family sleep360 \ --container-definitions "[{\"name\":\"sleep\",\"image\":\"busybox\",\"cpu\":10,\"command\":[\"sleep\",\"360\"],\"memory\":10,\"essential\":true}]" ``` ---------------------------------------- TITLE: List all AWS ECS Task Definitions using AWS CLI DESCRIPTION: This command lists all registered Amazon ECS task definitions in your AWS account. It provides a comprehensive list of all task definition ARNs, useful for auditing or general overview. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/list-task-definitions.rst#_snippet_0 LANGUAGE: bash CODE: ``` aws ecs list-task-definitions ``` LANGUAGE: json CODE: ``` { "taskDefinitionArns": [ "arn:aws:ecs:us-west-2:123456789012:task-definition/sleep300:2", "arn:aws:ecs:us-west-2:123456789012:task-definition/sleep360:1", "arn:aws:ecs:us-west-2:123456789012:task-definition/wordpress:3", "arn:aws:ecs:us-west-2:123456789012:task-definition/wordpress:4", "arn:aws:ecs:us-west-2:123456789012:task-definition/wordpress:5", "arn:aws:ecs:us-west-2:123456789012:task-definition/wordpress:6" ] } ``` ---------------------------------------- TITLE: JSON Input for ECS Service EBS Volume Configuration DESCRIPTION: This JSON file (`ecs-simple-service-ebs.json`) defines the parameters for creating an Amazon ECS service with attached EBS volumes. It specifies the cluster, task definition, service name, desired count, network configuration, and crucially, the `volumeConfigurations` array for defining EBS properties like name, role ARN, volume type, size, IOPS, throughput, and filesystem type. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/create-service.rst#_snippet_5 LANGUAGE: json CODE: ``` { "cluster": "mycluster", "taskDefinition": "mytaskdef", "serviceName": "ecs-simple-service-ebs", "desiredCount": 2, "launchType": "FARGATE", "networkConfiguration":{ "awsvpcConfiguration":{ "assignPublicIp": "ENABLED", "securityGroups": ["sg-12344321"], "subnets":["subnet-12344321"] } }, "volumeConfigurations": [ { "name": "myEbsVolume", "managedEBSVolume": { "roleArn":"arn:aws:iam::123456789012:role/ecsInfrastructureRole", "volumeType": "gp3", "sizeInGiB": 100, "iops": 3000, "throughput": 125, "filesystemType": "ext4" } } ] } ``` ---------------------------------------- TITLE: Deregister AWS ECS Task Definition using CLI DESCRIPTION: This AWS CLI command deregisters a specific revision of an Amazon ECS task definition. It targets the 'curler' task definition with revision '1', marking it as INACTIVE. This action prevents new tasks from being launched using this specific task definition revision. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/deregister-task-definition.rst#_snippet_0 LANGUAGE: aws cli CODE: ``` aws ecs deregister-task-definition --task-definition curler:1 ``` ---------------------------------------- TITLE: Describe an ECS Task Definition using AWS CLI DESCRIPTION: This AWS CLI command retrieves the detailed configuration of a specified Amazon ECS task definition. It requires the task definition's family and revision (e.g., `hello_world:8`) to fetch comprehensive information about its containers, volumes, and other properties. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/describe-task-definition.rst#_snippet_0 LANGUAGE: aws cli CODE: ``` aws ecs describe-task-definition \ --task-definition hello_world:8 ``` ---------------------------------------- TITLE: Retrieve ECS Task Protection Status with AWS CLI DESCRIPTION: This AWS CLI command queries the protection status of a specific Amazon ECS task. It requires the cluster name and the task ID, returning a JSON object indicating if the task is protected from termination and any failures encountered. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/get-task-protection.rst#_snippet_0 LANGUAGE: AWS CLI CODE: ``` aws ecs get-task-protection \ --cluster ECS-project-update-cluster \ --tasks c43ed3b1331041f289316f958adb6a24 { "protectedTasks": [ { "taskArn": "arn:aws:ecs:us-west-2:123456789012:task/c43ed3b1331041f289316f958adb6a24", "protectionEnabled": false } ], "failures": [] } ``` ---------------------------------------- TITLE: Stop an AWS ECS Task using AWS CLI DESCRIPTION: This command stops a running Amazon ECS task in the default cluster. It requires the task ID as input and returns a JSON object detailing the stopped task's properties and status. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/stop-task.rst#_snippet_0 LANGUAGE: aws cli CODE: ``` aws ecs stop-task \ --task 666fdccc2e2d4b6894dd422f4eeee8f8 ``` LANGUAGE: JSON CODE: ``` { "task": { "taskArn": "arn:aws:ecs:us-west-2:130757420319:task/default/666fdccc2e2d4b6894dd422f4eeee8f8", "clusterArn": "arn:aws:ecs:us-west-2:130757420319:cluster/default", "taskDefinitionArn": "arn:aws:ecs:us-west-2:130757420319:task-definition/sleep360:3", "containerInstanceArn": "arn:aws:ecs:us-west-2:130757420319:container-instance/default/765936fadbdd46b5991a4bd70c2a43d4", "overrides": { "containerOverrides": [] }, "lastStatus": "STOPPED", "desiredStatus": "STOPPED", "cpu": "128", "memory": "128", "containers": [], "version": 2, "stoppedReason": "Taskfailedtostart", "stopCode": "TaskFailedToStart", "connectivity": "CONNECTED", "connectivityAt": 1563421494.186, "pullStartedAt": 1563421494.252, "pullStoppedAt": 1563421496.252, "executionStoppedAt": 1563421497, "createdAt": 1563421494.186, "stoppingAt": 1563421497.252, "stoppedAt": 1563421497.252, "group": "family:sleep360", "launchType": "EC2", "attachments": [], "tags": [] } } ``` ---------------------------------------- TITLE: Update AWS ECS Task Set Scale with CLI DESCRIPTION: This AWS CLI command updates the scale of an existing Amazon ECS task set. It requires specifying the cluster name, service name, task set ARN, and the desired scale value (e.g., 50 percent). This command is essential for dynamically adjusting the number of tasks running within a specific task set. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/update-task-set.rst#_snippet_0 LANGUAGE: AWS CLI CODE: ``` aws ecs update-task-set \ --cluster MyCluster \ --service MyService \ --task-set arn:aws:ecs:us-west-2:123456789012:task-set/MyCluster/MyService/ecs-svc/1234567890123456789 \ --scale value=50,unit=PERCENT ``` ---------------------------------------- TITLE: AWS ECS Task Object Example and Structure DESCRIPTION: An example of the JSON structure returned for an Amazon ECS task, illustrating the various fields and their typical values. This includes details about attachments, attributes, container instances, individual containers, CPU/memory, and task overrides. The APIDOC section provides a structured overview of the object's properties and inferred types. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/start-task.rst#_snippet_2 LANGUAGE: JSON CODE: ``` { "tasks": [ { "attachments": [ { "id": "12345678-90ab-cdef-1234-567890abcdef", "type": "ElasticNetworkInterface", "status": "ATTACHED", "details": [ { "name": "subnetId", "value": "subnet-0abcdef1234567890" }, { "name": "networkInterfaceId", "value": "eni-0abcdef1234567890" }, { "name": "privateDnsName", "value": "ip-10-0-0-1.us-west-2.compute.internal" }, { "name": "privateIpAddress", "value": "10.0.0.1" } ] } ], "attributes": [ { "name": "ecs.cpu-architecture", "value": "arm64" } ], "availabilityZone": "us-west-2c", "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/default", "containerInstanceArn": "arn:aws:ecs:us-west-2:123456789012:container-instance/default/765936fadbdd46b5991a4bd70c2a43d4", "containers": [ { "containerArn": "arn:aws:ecs:us-west-2:123456789012:container/default/bb122ace3ed84add92c00a351a03c69e/a4a9ed10-51c7-4567-9653-50e71b94f867", "taskArn": "arn:aws:ecs:us-west-2:123456789012:task/default/bb122ace3ed84add92c00a351a03c69e", "name": "container-using-ebs", "image": "amazonlinux:2", "lastStatus": "PENDING", "networkInterfaces": [], "cpu": "0" } ], "cpu": "1024", "createdAt": "2025-01-23T14:51:05.191000-06:00", "desiredStatus": "RUNNING", "enableExecuteCommand": false, "group": "family:mytaskdef", "lastStatus": "PROVISIONING", "launchType": "EC2", "memory": "3072", "overrides": { "containerOverrides": [ { "name": "container-using-ebs" } ], "inferenceAcceleratorOverrides": [] }, "tags": [], "taskArn": "arn:aws:ecs:us-west-2:123456789012:task/default/bb122ace3ed84add92c00a351a03c69e", "taskDefinitionArn": "arn:aws:ecs:us-west-2:123456789012:task-definition/mytaskdef:4", "version": 1 } ], "failures": [] } ``` LANGUAGE: APIDOC CODE: ``` TasksResponse: tasks: array of Task objects Task: attachments: array of Attachment objects Attachment: id: string type: string status: string details: array of Detail objects Detail: name: string value: string attributes: array of Attribute objects Attribute: name: string value: string availabilityZone: string clusterArn: string (ARN) containerInstanceArn: string (ARN) containers: array of Container objects Container: containerArn: string (ARN) taskArn: string (ARN) name: string image: string lastStatus: string networkInterfaces: array cpu: string (numeric string) cpu: string (numeric string) createdAt: string (ISO 8601 timestamp) desiredStatus: string enableExecuteCommand: boolean group: string lastStatus: string launchType: string memory: string (numeric string) overrides: Overrides object Overrides: containerOverrides: array of ContainerOverride objects ContainerOverride: name: string inferenceAcceleratorOverrides: array tags: array taskArn: string (ARN) taskDefinitionArn: string (ARN) version: integer failures: array of Failure objects ``` ---------------------------------------- TITLE: AWS CLI ECS Task Description JSON Output DESCRIPTION: This snippet shows a typical JSON response when querying an Amazon ECS task's details using the AWS CLI. It includes information about task attachments (like EBS volumes), attributes, container details, resource allocations (CPU, memory), and status, demonstrating how an EBS volume attachment is represented. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/run-task.rst#_snippet_2 LANGUAGE: JSON CODE: ``` { "tasks": [ { "attachments": [ { "details": [ { "name": "roleArn", "value": "arn:aws:iam::123456789012:role/ecsInfrastructureRole" }, { "name": "volumeName", "value": "myEBSVolume" }, { "name": "deleteOnTermination", "value": "true" } ] } ], "attributes": [ { "name": "ecs.cpu-architecture", "value": "x86_64" } ], "availabilityZone": "us-west-2b", "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/default", "containers": [ { "containerArn": "arn:aws:ecs:us-west-2:123456789012:container/default/7f1fbd3629434cc4b82d72d2f09b67c9/e21962a2-f328-4699-98a3-5161ac2c186a", "taskArn": "arn:aws:ecs:us-west-2:123456789012:task/default/7f1fbd3629434cc4b82d72d2f09b67c9", "name": "container-using-ebs", "image": "amazonlinux:2", "lastStatus": "PENDING", "networkInterfaces": [], "cpu": "0" } ], "cpu": "1024", "createdAt": "2025-01-23T10:29:46.650000-06:00", "desiredStatus": "RUNNING", "enableExecuteCommand": false, "group": "family:mytaskdef", "lastStatus": "PROVISIONING", "launchType ``` ---------------------------------------- TITLE: Configure Amazon EBS Volume for Fargate Task with AWS CLI DESCRIPTION: This example shows how to configure an encrypted Amazon EBS volume for a Fargate task on the default cluster using the AWS CLI. It requires an Amazon ECS infrastructure role with `AmazonECSInfrastructureRolePolicyForVolumes` and a task definition with the same volume name. The command uses `--cli-input-json` to pass a JSON file for configuration. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/run-task.rst#_snippet_1 LANGUAGE: aws-cli CODE: ``` aws ecs run-task \ --cli-input-json file://ebs.json ``` LANGUAGE: json CODE: ``` { "cluster": "default", "taskDefinition": "mytaskdef", "launchType": "FARGATE", "networkConfiguration":{ "awsvpcConfiguration":{ "assignPublicIp": "ENABLED", "securityGroups": ["sg-12344321"], "subnets":["subnet-12344321"] } }, "volumeConfigurations": [ { "name": "myEBSVolume", "managedEBSVolume": { "volumeType": "gp3", "sizeInGiB": 100, "roleArn":"arn:aws:iam::1111222333:role/ecsInfrastructureRole", "encrypted": true, "kmsKeyId": "arn:aws:kms:region:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab" } } ] } ``` LANGUAGE: json CODE: ``` { "tasks": [ { "attachments": [ { "id": "ce868693-15ca-4083-91ac-f782f64000c9", "type": "ElasticNetworkInterface", "status": "PRECREATED", "details": [ { "name": "subnetId", "value": "subnet-070982705451dad82" } ] }, { "id": "a17ed863-786c-4372-b5b3-b23e53f37877", "type": "AmazonElasticBlockStorage", "status": "CREATED", "details": [ { "name": "roleArn" ``` ---------------------------------------- TITLE: AWS ECS Service/Task Definition JSON Configuration Fragment DESCRIPTION: A partial JSON configuration snippet for an AWS ECS service or task definition, showcasing parameters like security group assignment, public IP settings, health check grace period, scheduling strategy, and tag propagation. This snippet is part of a larger ECS service or task definition JSON, as found in the AWS CLI context. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/create-service.rst#_snippet_7 LANGUAGE: JSON CODE: ``` "securityGroups": [ "sg-12344321" ], "assignPublicIp": "DISABLED" } }, "healthCheckGracePeriodSeconds": 0, "schedulingStrategy": "REPLICA", "deploymentController": { "type": "ECS" }, "createdBy": "arn:aws:iam::123456789012:user/AIDACKCEVSQ6C2EXAMPLE", "enableECSManagedTags": false, "propagateTags": "NONE", "enableExecuteCommand": false, "availabilityZoneRebalancing": "DISABLED" } } ``` ---------------------------------------- TITLE: Create AWS ECS Service Behind Load Balancer with JSON Input DESCRIPTION: This example demonstrates creating an Amazon ECS service configured to run behind a load balancer. It utilizes the AWS CLI `create-service` command with the `--cli-input-json` option, referencing an external JSON file. The example includes the CLI command, the content of the JSON input file (`ecs-simple-service-elb.json`), and the resulting JSON output from the command. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/create-service.rst#_snippet_3 LANGUAGE: aws-cli CODE: ``` aws ecs create-service \ --cluster MyCluster \ --service-name ecs-simple-service-elb \ --cli-input-json file://ecs-simple-service-elb.json ``` LANGUAGE: json CODE: ``` { "serviceName": "ecs-simple-service-elb", "taskDefinition": "ecs-demo", "loadBalancers": [ { "loadBalancerName": "EC2Contai-EcsElast-123456789012", "containerName": "simple-demo", "containerPort": 80 } ], "desiredCount": 10, "role": "ecsServiceRole" } ``` LANGUAGE: json CODE: ``` { "service": { "status": "ACTIVE", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/ecs-demo:1", "pendingCount": 0, "loadBalancers": [ { "containerName": "ecs-demo", "containerPort": 80, "loadBalancerName": "EC2Contai-EcsElast-123456789012" } ], "roleArn": "arn:aws:iam::123456789012:role/ecsServiceRole", "desiredCount": 10, "serviceName": "ecs-simple-service-elb", "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster", "serviceArn": "arn:aws:ecs:us-west-2:123456789012:service/ecs-simple-service-elb", "deployments": [ { "status": "PRIMARY", "pendingCount": 0, "createdAt": 1428100239.123, "desiredCount": 10, "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/ecs-demo:1", "updatedAt": 1428100239.123, "id": "ecs-svc/1234567890123456789", "runningCount": 0 } ], "events": [], "runningCount": 0 } } ``` ---------------------------------------- TITLE: Update AWS ECS Service Task Definition DESCRIPTION: This snippet illustrates how to modify an existing Amazon ECS service to use a different task definition. The `aws ecs update-service` command is used, specifying the target cluster, service name, and the new task definition. The accompanying JSON provides a detailed example of the command's successful output, showing the updated service configuration. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/update-service.rst#_snippet_0 LANGUAGE: aws-cli CODE: ``` aws ecs update-service \ --cluster test \ --service my-http-service \ --task-definition amazon-ecs-sample ``` LANGUAGE: json CODE: ``` { "service": { "serviceArn": "arn:aws:ecs:us-west-2:123456789012:service/test/my-http-service", "serviceName": "my-http-service", "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/test", "loadBalancers": [], "serviceRegistries": [], "status": "ACTIVE", "desiredCount": 2, "runningCount": 2, "pendingCount": 0, "launchType": "FARGATE", "platformVersion": "1.4.0", "platformFamily": "Linux", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/amazon-ecs-sample:2", "deploymentConfiguration": { "deploymentCircuitBreaker": { "enable": true, "rollback": true }, "maximumPercent": 200, "minimumHealthyPercent": 100, "alarms": { "alarmNames": [], "rollback": false, "enable": false } }, "deployments": [ { "id": "ecs-svc/7419115625193919142", "status": "PRIMARY", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/amazon-ecs-sample:2", "desiredCount": 0, "pendingCount": 0, "runningCount": 0, "failedTasks": 0, "createdAt": "2025-02-21T13:26:02.734000-06:00", "updatedAt": "2025-02-21T13:26:02.734000-06:00", "launchType": "FARGATE", "platformVersion": "1.4.0", "platformFamily": "Linux", "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-12344321" ], "securityGroups": [ "sg-12344321" ], "assignPublicIp": "ENABLED" } }, "rolloutState": "IN_PROGRESS", "rolloutStateReason": "ECS deployment ecs-svc/7419115625193919142 in progress." }, { "id": "ecs-svc/1709597507655421668", "status": "ACTIVE", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/old-amazon-ecs-sample:4", "desiredCount": 2, "pendingCount": 0, "runningCount": 2, "failedTasks": 0, "createdAt": "2025-01-24T11:13:07.621000-06:00", "updatedAt": "2025-02-02T16:11:30.838000-06:00", "launchType": "FARGATE", "platformVersion": "1.4.0", "platformFamily": "Linux", "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-12344321" ], "securityGroups": [ "sg-12344321" ], "assignPublicIp": "ENABLED" } }, "rolloutState": "COMPLETED", "rolloutStateReason": "ECS deployment ecs-svc/1709597507655421668 completed." } ], "roleArn": "arn:aws:iam::123456789012:role/aws-service-role/ecs.amazonaws.com/AWSServiceRoleForECS", "events": [ { "id": "e40b4d1c-80d9-4834-aaf3-6a268e530e17", "createdAt": "2025-02-21T10:31:26.037000-06:00", "message": "(my-http-service) has reached a steady state." }, { "id": "6ac069ad-fc8b-4e49-a35d-b5574a964c8e", "createdAt": "2025-02-21T04:31:22.703000-06:00", "message": "(my-http-service) has reached a steady state." }, { "id": "265f7d37-dfd1-4880-a846-ec486f341919", "createdAt": "2025-02-20T22:31:22.514000-06:00", "message": "(my-http-service) has reached a steady state." } ] } } ``` ---------------------------------------- TITLE: Example AWS ECS DescribeTasks API Response DESCRIPTION: This JSON object represents a typical response from an AWS ECS API call, such as `DescribeTasks`. It contains a list of `tasks`, where each task object provides comprehensive details including its ARN, current status, associated cluster, launch type, resource allocations (CPU, memory), and detailed information about its running containers, including their images, network configurations, and health status. It also includes a `failures` array for any tasks that could not be described. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/describe-tasks.rst#_snippet_3 LANGUAGE: JSON CODE: ``` { "tasks": [ { "availabilityZone": "us-east-1b", "clusterArn": "arn:aws:ecs:us-east-1:123456789012:cluster/MyCluster", "connectivity": "CONNECTED", "connectivityAt": "2021-12-20T12:13:35.243000-05:00", "containers": [ { "containerArn": "arn:aws:ecs:us-east-1:123456789012:container/MyCluster/d789e94343414c25b9f6bd59eEXAMPLE/9afef792-609b-43a5-bb6a-3efdbEXAMPLE", "taskArn": "arn:aws:ecs:us-east-1:123456789012:task/MyCluster/d789e94343414c25b9f6bd59eEXAMPLE", "name": "web", "image": "nginx", "runtimeId": "d789e94343414c25b9f6bd59eEXAMPLE-265927825", "lastStatus": "RUNNING", "networkBindings": [], "networkInterfaces": [ { "attachmentId": "214eb5a9-45cd-4bf8-87bc-57fefEXAMPLE", "privateIpv4Address": "10.0.1.41" } ], "healthStatus": "UNKNOWN", "cpu": "99", "memory": "100" } ], "cpu": "256", "createdAt": "2021-12-20T12:13:20.226000-05:00", "desiredStatus": "RUNNING", "enableExecuteCommand": false, "group": "service:tdsevicetag", "healthStatus": "UNKNOWN", "lastStatus": "RUNNING", "launchType": "FARGATE", "memory": "512", "overrides": { "containerOverrides": [ { "name": "web" } ], "inferenceAcceleratorOverrides": [] }, "platformVersion": "1.4.0", "platformFamily": "Linux", "pullStartedAt": "2021-12-20T12:13:44.611000-05:00", "pullStoppedAt": "2021-12-20T12:13:48.251000-05:00", "startedAt": "2021-12-20T12:13:49.326000-05:00", "startedBy": "ecs-svc/988401040018EXAMPLE", "tags": [], "taskArn": "arn:aws:ecs:us-east-1:123456789012:task/MyCluster/d789e94343414c25b9f6bd59eEXAMPLE", "taskDefinitionArn": "arn:aws:ecs:us-east-1:123456789012:task-definition/webserver:2", "version": 3, "ephemeralStorage": { "sizeInGiB": 20 } } ], "failures": [] } ``` ---------------------------------------- TITLE: List All AWS ECS Task Definition Families DESCRIPTION: This AWS CLI command retrieves a list of all registered Amazon ECS task definition families in the current AWS region. It provides a complete overview of all available task definition groups. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/list-task-definition-families.rst#_snippet_0 LANGUAGE: Bash CODE: ``` aws ecs list-task-definition-families ``` LANGUAGE: JSON CODE: ``` { "families": [ "node-js-app", "web-timer", "hpcc", "hpcc-c4-8xlarge" ] } ``` ---------------------------------------- TITLE: Update Primary Task Set for ECS Service (AWS CLI) DESCRIPTION: This AWS CLI command updates the primary task set for an Amazon ECS service within a specified cluster. It requires the cluster name, service name, and the ARN of the new primary task set to be designated as primary. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/update-service-primary-task-set.rst#_snippet_0 LANGUAGE: aws-cli CODE: ``` aws ecs update-service-primary-task-set \ --cluster MyCluster \ --service MyService \ --primary-task-set arn:aws:ecs:us-west-2:123456789012:task-set/MyCluster/MyService/ecs-svc/1234567890123456789 ``` ---------------------------------------- TITLE: AWS CLI: Wait for Multiple ECS Tasks to Stop DESCRIPTION: This command uses `aws ecs wait tasks-stopped` to pause execution until multiple specified Amazon ECS tasks simultaneously reach a stopped state. It supports providing multiple task IDs or ARNs as arguments, and produces no output upon completion. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/wait/task-stopped.rst#_snippet_1 LANGUAGE: AWS CLI CODE: ``` aws ecs wait tasks-stopped \ --cluster MyCluster \ --tasks 2c196f0a00dd4f58b7c8897a5c7bce13 4d590253bb114126b7afa7b58EXAMPLE ``` ---------------------------------------- TITLE: Create AWS ECS Service with External Deployment Controller DESCRIPTION: This example demonstrates how to create an Amazon ECS service using the AWS CLI, specifying an external deployment controller. It shows the `create-service` command and the expected JSON output for the created service, highlighting the `deploymentController` type as `EXTERNAL`. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/create-service.rst#_snippet_2 LANGUAGE: aws-cli CODE: ``` aws ecs create-service \ --cluster MyCluster \ --service-name MyService \ --deployment-controller type=EXTERNAL \ --desired-count 1 ``` LANGUAGE: json CODE: ``` { "service": { "serviceArn": "arn:aws:ecs:us-west-2:123456789012:service/MyCluster/MyService", "serviceName": "MyService", "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster", "loadBalancers": [], "serviceRegistries": [], "status": "ACTIVE", "desiredCount": 1, "runningCount": 0, "pendingCount": 0, "launchType": "EC2", "deploymentConfiguration": { "maximumPercent": 200, "minimumHealthyPercent": 100 }, "taskSets": [], "deployments": [], "roleArn": "arn:aws:iam::123456789012:role/aws-service-role/ecs.amazonaws.com/AWSServiceRoleForECS", "events": [], "createdAt": 1557128207.101, "placementConstraints": [], "placementStrategy": [], "schedulingStrategy": "REPLICA", "deploymentController": { "type": "EXTERNAL" }, "enableECSManagedTags": false, "propagateTags": "NONE" } } ``` ---------------------------------------- TITLE: Example AWS ECS Task JSON Object DESCRIPTION: This JSON snippet illustrates the comprehensive structure of a single Amazon ECS Task object. It includes details such as network interface attachments, task attributes (e.g., CPU architecture), cluster and task ARNs, connectivity status, container specifics (image, status, network bindings), resource allocations (CPU, memory), lifecycle timestamps, launch type (e.g., Fargate), overrides, platform version, and ephemeral storage configuration. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/describe-tasks.rst#_snippet_2 LANGUAGE: JSON CODE: ``` { "attachments": [ { "id": "d9e7735a-16aa-4128-bc7a-b2d51EXAMPLE", "type": "ElasticNetworkInterface", "status": "ATTACHED", "details": [ { "name": "subnetId", "value": "subnet-0d0eab1bb3EXAMPLE" }, { "name": "networkInterfaceId", "value": "eni-064c7766daEXAMPLE" }, { "name": "macAddress", "value": "0e:89:76:28:07:b3" }, { "name": "privateDnsName", "value": "ip-10-0-1-184.ec2.internal" }, { "name": "privateIPv4Address", "value": "10.0.1.184" } ] } ], "attributes": [ { "name": "ecs.cpu-architecture", "value": "x86_64" } ], "availabilityZone": "us-east-1b", "clusterArn": "arn:aws:ecs:us-east-1:123456789012:cluster/MyCluster", "connectivity": "CONNECTED", "connectivityAt": "20 ``` ---------------------------------------- TITLE: Create AWS IoT Wireless Gateway Task using AWS CLI DESCRIPTION: This snippet demonstrates how to create a task for a wireless gateway using the `aws iotwireless create-wireless-gateway-task` command. It requires a unique task ID and a wireless gateway task definition ID. The command initiates the task creation process and returns a JSON object indicating the status and the task definition ID. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/iotwireless/create-wireless-gateway-task.rst#_snippet_0 LANGUAGE: Bash CODE: ``` aws iotwireless create-wireless-gateway-task \ --id "12345678-a1b2-3c45-67d8-e90fa1b2c34d" \ --wireless-gateway-task-definition-id "aa000102-0304-b0cd-ef56-a1b23cde456a" ``` LANGUAGE: JSON CODE: ``` { "WirelessGatewayTaskDefinitionId": "aa204003-0604-30fb-ac82-a4f95aaf450a", "Status": "Success" } ``` ---------------------------------------- TITLE: Wait for ECS Task to be Running using AWS CLI DESCRIPTION: This example demonstrates how to use the `aws ecs wait tasks-running` command to pause the execution of a script or process until a specified Amazon ECS task transitions into a `RUNNING` state. It requires the cluster name and the ARN of the task to monitor. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/wait/tasks-running.rst#_snippet_0 LANGUAGE: CLI CODE: ``` aws ecs wait tasks-running \ --cluster MyCluster \ --tasks arn:aws:ecs:us-west-2:123456789012:task/a1b2c3d4-5678-90ab-cdef-44444EXAMPLE ``` ---------------------------------------- TITLE: AWS CLI: Wait for a Single ECS Task to Stop DESCRIPTION: This command uses `aws ecs wait tasks-stopped` to pause execution until a single specified Amazon ECS task transitions to a stopped state. It accepts either the task ID or its full ARN as input, and produces no output upon completion. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/wait/task-stopped.rst#_snippet_0 LANGUAGE: AWS CLI CODE: ``` aws ecs wait tasks-stopped \ --cluster MyCluster \ --tasks 2c196f0a00dd4f58b7c8897a5c7bce13 ``` ---------------------------------------- TITLE: Delete AWS ECS Task Definition using AWS CLI DESCRIPTION: This snippet demonstrates how to delete an inactive Amazon ECS task definition using the AWS Command Line Interface (CLI). It specifies the task definition by its name and revision. The output shows the details of the deleted task definition, including its ARN, family, revision, and status, confirming the deletion is in progress. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/delete-task-definitions.rst#_snippet_0 LANGUAGE: aws cli CODE: ``` aws ecs delete-task-definitions \ --task-definition curltest:1 ``` LANGUAGE: json CODE: ``` { "taskDefinitions": [ { "taskDefinitionArn": "arn:aws:ecs:us-east-1:123456789012:task-definition/curltest:1", "containerDefinitions": [ { "name": "ctest", "image": "mreferre/eksutils", "cpu": 0, "portMappings": [], "essential": true, "entryPoint": [ "sh", "-c" ], "command": [ "curl ${ECS_CONTAINER_METADATA_URI_V4}/task" ], "environment": [], "mountPoints": [], "volumesFrom": [], "logConfiguration": { "logDriver": "awslogs", "options": { "awslogs-create-group": "true", "awslogs-group": "/ecs/curltest", "awslogs-region": "us-east-1", "awslogs-stream-prefix": "ecs" } } } ], "family": "curltest", "taskRoleArn": "arn:aws:iam::123456789012:role/ecsTaskExecutionRole", "executionRoleArn": "arn:aws:iam::123456789012:role/ecsTaskExecutionRole", "networkMode": "awsvpc", "revision": 1, "volumes": [], "status": "DELETE_IN_PROGRESS", "compatibilities": [ "EC2", "FARGATE" ], "requiresCompatibilities": [ "FARGATE" ], "cpu": "256", "memory": "512", "registeredAt": "2021-09-10T12:56:24.704000+00:00", "deregisteredAt": "2023-03-14T15:20:59.419000+00:00", "registeredBy": "arn:aws:sts::123456789012:assumed-role/Admin/jdoe" } ], "failures": [] } ``` ---------------------------------------- TITLE: Delete an AWS ECS Task Set with AWS CLI DESCRIPTION: This example demonstrates how to delete an Amazon ECS task set using the AWS CLI. It shows the use of the `delete-task-set` command with parameters for cluster, service, and task set ARN. The `--force` parameter is included to allow deletion even if the task set is not scaled to zero. The snippet also includes the expected JSON output from the command. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/delete-task-set.rst#_snippet_0 LANGUAGE: Shell CODE: ``` aws ecs delete-task-set \ --cluster MyCluster \ --service MyService \ --task-set arn:aws:ecs:us-west-2:123456789012:task-set/MyCluster/MyService/ecs-svc/1234567890123456789 \ --force ``` LANGUAGE: JSON CODE: ``` { "taskSet": { "id": "ecs-svc/1234567890123456789", "taskSetArn": "arn:aws:ecs:us-west-2:123456789012:task-set/MyCluster/MyService/ecs-svc/1234567890123456789", "status": "DRAINING", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/sample-fargate:2", "computedDesiredCount": 0, "pendingCount": 0, "runningCount": 0, "createdAt": 1557130260.276, "updatedAt": 1557130290.707, "launchType": "EC2", "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-12345678" ], "securityGroups": [ "sg-12345678" ], "assignPublicIp": "DISABLED" } }, "loadBalancers": [], "serviceRegistries": [], "scale": { "value": 0.0, "unit": "PERCENT" }, "stabilityStatus": "STABILIZING", "stabilityStatusAt": 1557130290.707 } } ``` ---------------------------------------- TITLE: List ECS Tasks on a Specific Container Instance using AWS CLI DESCRIPTION: This example illustrates how to filter the `aws ecs list-tasks` command to show only tasks running on a particular container instance. It uses the `--container-instance` flag with the instance's UUID to narrow down the results. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/list-tasks.rst#_snippet_1 LANGUAGE: bash CODE: ``` aws ecs list-tasks --cluster default --container-instance a1b2c3d4-5678-90ab-cdef-33333EXAMPLE ``` ---------------------------------------- TITLE: Filter AWS ECS Task Definition Families by Prefix DESCRIPTION: This AWS CLI command allows filtering the registered Amazon ECS task definition families. It returns only those families whose names begin with the specified prefix, enabling targeted searches for specific task definition groups. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/list-task-definition-families.rst#_snippet_1 LANGUAGE: Bash CODE: ``` aws ecs list-task-definition-families --family-prefix hpcc ``` LANGUAGE: JSON CODE: ``` { "families": [ "hpcc", "hpcc-c4-8xlarge" ] } ``` ---------------------------------------- TITLE: Describe an AWS ECS Task Set DESCRIPTION: This snippet illustrates how to use the AWS CLI `describe-task-sets` command to fetch comprehensive details about a specific task set in an Amazon ECS service. It requires the cluster name, service name, and the task set ARN as parameters. The command's output is a JSON object containing the task set's status, ARN, definition, scaling, network configuration, and other relevant metadata. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/describe-task-sets.rst#_snippet_0 LANGUAGE: AWS CLI CODE: ``` aws ecs describe-task-sets \ --cluster MyCluster \ --service MyService \ --task-sets arn:aws:ecs:us-west-2:123456789012:task-set/MyCluster/MyService/ecs-svc/1234567890123456789 ``` LANGUAGE: JSON CODE: ``` { "taskSets": [ { "id": "ecs-svc/1234567890123456789", "taskSetArn": "arn:aws:ecs:us-west-2:123456789012:task-set/MyCluster/MyService/ecs-svc/1234567890123456789", "status": "ACTIVE", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/sample-fargate:2", "computedDesiredCount": 0, "pendingCount": 0, "runningCount": 0, "createdAt": 1557207715.195, "updatedAt": 1557207740.014, "launchType": "EC2", "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-12344321" ], "securityGroups": [ "sg-1234431" ], "assignPublicIp": "DISABLED" } }, "loadBalancers": [], "serviceRegistries": [], "scale": { "value": 0.0, "unit": "PERCENT" }, "stabilityStatus": "STEADY_STATE", "stabilityStatusAt": 1557207740.014 } ], "failures": [] } ``` ---------------------------------------- TITLE: Create an ECS Cluster with CloudWatch Container Insights DESCRIPTION: This example demonstrates how to create a new Amazon ECS cluster named 'MyCluster' using the AWS CLI. It configures the cluster to enable CloudWatch Container Insights with enhanced observability, providing detailed metrics and logs for your containerized applications. The output shows the ARN, name, status, and settings of the newly created cluster. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/create-cluster.rst#_snippet_0 LANGUAGE: aws-cli CODE: ``` aws ecs create-cluster \ --cluster-name MyCluster \ --settings name=containerInsights,value=enhanced ``` LANGUAGE: json CODE: ``` { "cluster": { "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster", "clusterName": "MyCluster", "status": "ACTIVE", "registeredContainerInstancesCount": 0, "pendingTasksCount": 0, "runningTasksCount": 0, "activeServicesCount": 0, "statistics": [], "settings": [ { "name": "containerInsights", "value": "enhanced" } ], "tags": [] } } ``` ---------------------------------------- TITLE: List AWS ECS Task Definitions by Family Prefix using AWS CLI DESCRIPTION: This command lists Amazon ECS task definition revisions belonging to a specified family. It filters the results to show only task definitions with a matching family prefix, such as 'wordpress', which is useful for managing specific application deployments. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/list-task-definitions.rst#_snippet_1 LANGUAGE: bash CODE: ``` aws ecs list-task-definitions --family-prefix wordpress ``` LANGUAGE: json CODE: ``` { "taskDefinitionArns": [ "arn:aws:ecs:us-west-2:123456789012:task-definition/wordpress:3", "arn:aws:ecs:us-west-2:123456789012:task-definition/wordpress:4", "arn:aws:ecs:us-west-2:123456789012:task-definition/wordpress:5", "arn:aws:ecs:us-west-2:123456789012:task-definition/wordpress:6" ] } ``` ---------------------------------------- TITLE: Update AWS ECS Service Desired Count using AWS CLI DESCRIPTION: This example demonstrates how to update the desired task count for an Amazon ECS service using the AWS CLI. It targets a specific cluster and service to scale the number of running tasks to 2. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/update-service.rst#_snippet_2 LANGUAGE: aws-cli CODE: ``` aws ecs update-service \ --cluster MyCluster \ --service my-http-service \ --desired-count 2 ``` ---------------------------------------- TITLE: Example JSON Output for describe-task-definition DESCRIPTION: This JSON object illustrates the typical output returned by the `aws ecs describe-task-definition` command. It provides a complete representation of the task definition, including `taskDefinitionArn`, `containerDefinitions` (with details like `image`, `cpu`, `memory`, `portMappings`), `family`, `revision`, and `status`. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/describe-task-definition.rst#_snippet_1 LANGUAGE: json CODE: ``` { "taskDefinition": { "taskDefinitionArn": "arn:aws:ecs:us-east-1:012345678910:task-definition/hello_world:8", "containerDefinitions": [ { "cpu": 10, "environment": [], "essential": true, "image": "wordpress", "links": [ "mysql" ] , "memory": 500, "mountPoints": [], "name": "wordpress", "portMappings": [ { "containerPort": 80, "hostPort": 80 } ], "volumesFrom": [] }, { "cpu": 10, "environment": [ { "name": "MYSQL_ROOT_PASSWORD", "value": "password" } ], "essential": true, "image": "mysql", "memory": 500, "mountPoints": [], "name": "mysql", "portMappings": [], "volumesFrom": [] } ], "family": "hello_world", "revision": 8, "volumes": [], "status": "ACTIVE", "placementConstraints": [], "compatibilities": [ "EXTERNAL", "EC2" ], "registeredAt": "2024-06-21T11:15:12.669000-05:00", "registeredBy": "arn:aws:sts::012345678910:assumed-role/demo-role/jane-doe" }, "tags": [] } ``` ---------------------------------------- TITLE: Create AWS IoT Wireless Gateway Task Definition using CLI DESCRIPTION: This AWS CLI command initiates the creation of a wireless gateway task definition. It references an external JSON file for configuration details, enabling the automatic creation of tasks for gateways based on specified criteria. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/iotwireless/create-wireless-gateway-task-definition.rst#_snippet_0 LANGUAGE: aws-cli CODE: ``` aws iotwireless create-wireless-gateway-task-definition \ --cli-input-json file://input.json ``` ---------------------------------------- TITLE: Update ECS Container Instance State with AWS CLI DESCRIPTION: This command changes the status of a specified Amazon ECS container instance to 'DRAINING'. When an instance is draining, the Amazon ECS service scheduler no longer places new tasks on it, and existing tasks are allowed to complete. The output shows the updated container instance details in JSON format. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/update-container-instances-state.rst#_snippet_0 LANGUAGE: CLI CODE: ``` aws ecs update-container-instances-state \ --container-instances 765936fadbdd46b5991a4bd70c2a43d4 \ --status DRAINING ``` LANGUAGE: JSON CODE: ``` { "containerInstances": [ { "containerInstanceArn": "arn:aws:ecs:us-west-2:130757420319:container-instance/default/765936fadbdd46b5991a4bd70c2a43d4", "ec2InstanceId": "i-013d87ffbb4d513bf", "version": 4390, "versionInfo": { "agentVersion": "1.29.0", "agentHash": "a190a73f", "dockerVersion": "DockerVersion:18.06.1-ce" }, "remainingResources": [ { "name": "CPU", "type": "INTEGER", "doubleValue": 0, "longValue": 0, "integerValue": 1536 }, { "name": "MEMORY", "type": "INTEGER", "doubleValue": 0, "longValue": 0, "integerValue": 2681 }, { "name": "PORTS", "type": "STRINGSET", "doubleValue": 0, "longValue": 0, "integerValue": 0, "stringSetValue": [ "22", "2376", "2375", "51678", "51679" ] }, { "name": "PORTS_UDP", "type": "STRINGSET", "doubleValue": 0, "longValue": 0, "integerValue": 0, "stringSetValue": [] } ], "registeredResources": [ { "name": "CPU", "type": "INTEGER", "doubleValue": 0, "longValue": 0, "integerValue": 2048 }, { "name": "MEMORY", "type": "INTEGER", "doubleValue": 0, "longValue": 0, "integerValue": 3705 }, { "name": "PORTS", "type": "STRINGSET", "doubleValue": 0, "longValue": 0, "integerValue": 0, "stringSetValue": [ "22", "2376", "2375", "51678", "51679" ] }, { "name": "PORTS_UDP", "type": "STRINGSET", "doubleValue": 0, "longValue": 0, "integerValue": 0, "stringSetValue": [] } ], "status": "DRAINING", "agentConnected": true, "runningTasksCount": 2, "pendingTasksCount": 0, "attributes": [ { "name": "ecs.capability.secrets.asm.environment-variables" }, { "name": "ecs.capability.branch-cni-plugin-version", "value": "e0703516-" }, { "name": "ecs.ami-id", "value": "ami-00e0090ac21971297" }, { "name": "ecs.capability.secrets.asm.bootstrap.log-driver" }, { "name": "com.amazonaws.ecs.capability.logging-driver.none" }, { "name": "ecs.capability.ecr-endpoint" }, { "name": "ecs.capability.docker-plugin.local" }, { "name": "ecs.capability.task-cpu-mem-limit" }, { "name": "ecs.capability.secrets.ssm.bootstrap.log-driver" } ] } ] } ``` ---------------------------------------- TITLE: Create an ECS Cluster with Multiple Tags DESCRIPTION: This example shows how to create an Amazon ECS cluster and apply multiple tags to it using the AWS CLI. Tags are key-value pairs that help you manage, identify, organize, search for, and filter resources. The example demonstrates the basic command structure for including tags during cluster creation. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/create-cluster.rst#_snippet_2 LANGUAGE: aws-cli CODE: ``` aws ecs create-cluster \ --cluster-name MyCluster \ ``` ---------------------------------------- TITLE: Create an ECS Cluster with Capacity Providers and Default Strategy DESCRIPTION: This example illustrates how to create an Amazon ECS cluster and associate it with existing capacity providers. It also specifies a default capacity provider strategy to distribute tasks evenly across 'MyCapacityProvider1' and 'MyCapacityProvider2'. The output details the cluster's status, associated capacity providers, and the configured default strategy, including attachment information for scaling plans. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/create-cluster.rst#_snippet_1 LANGUAGE: aws-cli CODE: ``` aws ecs create-cluster \ --cluster-name MyCluster \ --capacity-providers MyCapacityProvider1 MyCapacityProvider2 \ --default-capacity-provider-strategy capacityProvider=MyCapacityProvider1,weight=1 capacityProvider=MyCapacityProvider2,weight=1 ``` LANGUAGE: json CODE: ``` { "cluster": { "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster", "clusterName": "MyCluster", "status": "PROVISIONING", "registeredContainerInstancesCount": 0, "pendingTasksCount": 0, "runningTasksCount": 0, "activeServicesCount": 0, "statistics": [], "settings": [ { "name": "containerInsights", "value": "enabled" } ], "capacityProviders": [ "MyCapacityProvider1", "MyCapacityProvider2" ], "defaultCapacityProviderStrategy": [ { "capacityProvider": "MyCapacityProvider1", "weight": 1, "base": 0 }, { "capacityProvider": "MyCapacityProvider2", "weight": 1, "base": 0 } ], "attachments": [ { "id": "0fb0c8f4-6edd-4de1-9b09-17e470ee1918", "type": "asp", "status": "PRECREATED", "details": [ { "name": "capacityProviderName", "value": "MyCapacityProvider1" }, { "name": "scalingPlanName", "value": "ECSManagedAutoScalingPlan-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" } ] }, { "id": "ae592060-2382-4663-9476-b015c685593c", "type": "asp", "status": "PRECREATED", "details": [ { "name": "capacityProviderName", "value": "MyCapacityProvider2" }, { "name": "scalingPlanName", "value": "ECSManagedAutoScalingPlan-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222" } ] } ], "attachmentsStatus": "UPDATE_IN_PROGRESS" } } ``` ---------------------------------------- TITLE: Example Output of ECS Service Creation with EBS Volumes DESCRIPTION: This JSON output represents the response from the `aws ecs create-service` command after successfully initiating the service creation. It includes details about the newly created service, its ARN, status, deployment configuration, and confirms the `volumeConfigurations` applied to the service. SOURCE: https://github.com/aws/aws-cli/blob/develop/awscli/examples/ecs/create-service.rst#_snippet_6 LANGUAGE: json CODE: ``` { "service": { "serviceArn": "arn:aws:ecs:us-west-2:123456789012:service/mycluster/ecs-simple-service-ebs", "serviceName": "ecs-simple-service-ebs", "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/mycluster", "loadBalancers": [], "serviceRegistries": [], "status": "ACTIVE", "desiredCount": 2, "runningCount": 0, "pendingCount": 0, "launchType": "EC2", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/mytaskdef:3", "deploymentConfiguration": { "deploymentCircuitBreaker": { "enable": false, "rollback": false }, "maximumPercent": 200, "minimumHealthyPercent": 100 }, "deployments": [ { "id": "ecs-svc/7851020056849183687", "status": "PRIMARY", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/mytaskdef:3", "desiredCount": 0, "pendingCount": 0, "runningCount": 0, "failedTasks": 0, "createdAt": "2025-01-21T11:32:38.034000-06:00", "updatedAt": "2025-01-21T11:32:38.034000-06:00", "launchType": "EC2", "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-12344321" ], "securityGroups": [ "sg-12344321" ], "assignPublicIp": "DISABLED" } }, "rolloutState": "IN_PROGRESS", "rolloutStateReason": "ECS deployment ecs-svc/7851020056849183687 in progress.", "volumeConfigurations": [ { "name": "myEBSVolume", "managedEBSVolume": { "volumeType": "gp3", "sizeInGiB": 100, "iops": 3000, "throughput": 125, "roleArn": "arn:aws:iam::123456789012:role/ecsInfrastructureRole", "filesystemType": "ext4" } } ] } ], "roleArn": "arn:aws:iam::123456789012:role/aws-service-role/ecs.amazonaws.com/AWSServiceRoleForECS", "events": [], "createdAt": "2025-01-21T11:32:38.034000-06:00", "placementConstraints": [], "placementStrategy": [], "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-12344321" ] } } } } ```