Amazon ECS examples using Amazon CLI
The following code examples show you how to perform actions and implement common scenarios by using the Amazon Command Line Interface with Amazon ECS.
Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.
Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.
Topics
Actions
The following code example shows how to use capacity-provider-update.
- Amazon CLI
- 
             
                    Update the capacity provider in an ECS cluster The following update-capacity-providerexample shows how we can modify the parameters of the capacity provider in an ECS cluster.aws ecs update-capacity-provider \ --nameInfra-ECS-Cluster-ECS-project-update-cluster-d6bb6d5b-EC2CapacityProvider-3fIpdkLywwFt\ --auto-scaling-group-provider"managedScaling={status=DISABLED,targetCapacity=50,minimumScalingStepSize=2,maximumScalingStepSize=30,instanceWarmupPeriod=200},managedTerminationProtection=DISABLED,managedDraining=DISABLED"Output: { "capacityProvider": { "capacityProviderArn": "arn:aws:ecs:us-west-2:123456789012:capacity-provider/Infra-ECS-Cluster-ECS-project-update-cluster-d6bb6d5b-EC2CapacityProvider-3fIpdkLywwFt", "name": "Infra-ECS-Cluster-ECS-project-update-cluster-d6bb6d5b-EC2CapacityProvider-3fIpdkLywwFt", "status": "ACTIVE", "autoScalingGroupProvider": { "autoScalingGroupArn": "arn:aws:autoscaling:us-west-2:123456789012:autoScalingGroup:424941d1-b43f-4a17-adbb-08b6a6e397e1:autoScalingGroupName/Infra-ECS-Cluster-ECS-project-update-cluster-d6bb6d5b-ECSAutoScalingGroup-f44jrQHS2nRB", "managedScaling": { "status": "ENABLED", "targetCapacity": 100, "minimumScalingStepSize": 1, "maximumScalingStepSize": 10000, "instanceWarmupPeriod": 300 }, "managedTerminationProtection": "DISABLED", "managedDraining": "ENABLED" }, "updateStatus": "UPDATE_IN_PROGRESS", "tags": [] } }For more information on Capacity Provider, see Amazon ECS capacity providers for the EC2 launch type in the Amazon ECS Developer Guide. - 
                    For API details, see CapacityProviderUpdate in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use create-capacity-provider.
- Amazon CLI
- 
             
                    To create a capacity provider The following create-capacity-provider example creates a capacity provider that uses an Auto Scaling group named MyASG, has managed scaling and managed termination protection enabled. This configuration is used for Amazon ECS cluster auto scaling. aws ecs create-capacity-provider \ --name"MyCapacityProvider"\ --auto-scaling-group-provider"autoScalingGroupArn=arn:aws:autoscaling:us-east-1:123456789012:autoScalingGroup:57ffcb94-11f0-4d6d-bf60-3bac5EXAMPLE:autoScalingGroupName/MyASG,managedScaling={status=ENABLED,targetCapacity=100},managedTerminationProtection=ENABLED"Output: { "capacityProvider": { "capacityProviderArn": "arn:aws:ecs:us-east-1:123456789012:capacity-provider/MyCapacityProvider", "name": "MyCapacityProvider", "status": "ACTIVE", "autoScalingGroupProvider": { "autoScalingGroupArn": "arn:aws:autoscaling:us-east-1:132456789012:autoScalingGroup:57ffcb94-11f0-4d6d-bf60-3bac5EXAMPLE:autoScalingGroupName/MyASG", "managedScaling": { "status": "ENABLED", "targetCapacity": 100, "minimumScalingStepSize": 1, "maximumScalingStepSize": 10000, "instanceWarmupPeriod": 300 }, "managedTerminationProtection": "ENABLED" }, "tags": [] }For more information, see Amazon ECS cluster auto scaling in the Amazon ECS Developer Guide. - 
                    For API details, see CreateCapacityProvider in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use create-cluster.
- Amazon CLI
- 
             
                    Example 1: To create a new cluster The following create-clusterexample creates a cluster namedMyClusterand enables CloudWatch Container Insights with enhanced observability.aws ecs create-cluster \ --cluster-nameMyCluster\ --settingsname=containerInsights,value=enhancedOutput: { "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": [] } }For more information, see Creating a Cluster in the Amazon ECS Developer Guide. Example 2: To create a new cluster using capacity providers The following create-clusterexample creates a cluster and associates two existing capacity providers with it. Thecreate-capacity-providercommand is used to create a capacity provider. Specifying a default capacity provider strategy is optional, but recommended. In this example, we create a cluster namedMyClusterand associate theMyCapacityProvider1andMyCapacityProvider2capacity providers with it. A default capacity provider strategy is specified that spreads the tasks evenly across both capacity providers.aws ecs create-cluster \ --cluster-nameMyCluster\ --capacity-providersMyCapacityProvider1MyCapacityProvider2\ --default-capacity-provider-strategycapacityProvider=MyCapacityProvider1,weight=1capacityProvider=MyCapacityProvider2,weight=1Output: { "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" } }For more information, see Cluster capacity providers in the Amazon ECS Developer Guide. Example 3: To create a new cluster with multiple tags The following create-clusterexample creates a cluster with multiple tags. For more information about adding tags using shorthand syntax, see Using Shorthand Syntax with the Amazon Command Line Interfacein the Amazon CLI User Guide. aws ecs create-cluster \ --cluster-nameMyCluster\ --tagskey=key1,value=value1key=key2,value=value2Output: { "cluster": { "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster", "clusterName": "MyCluster", "status": "ACTIVE", "registeredContainerInstancesCount": 0, "pendingTasksCount": 0, "runningTasksCount": 0, "activeServicesCount": 0, "statistics": [], "tags": [ { "key": "key1", "value": "value1" }, { "key": "key2", "value": "value2" } ] } }For more information, see Creating a Cluster in the Amazon ECS Developer Guide. - 
                    For API details, see CreateCluster in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use create-service.
- Amazon CLI
- 
             
                    Example 1: To create a service with a Fargate task The following create-serviceexample shows how to create a service using a Fargate task.aws ecs create-service \ --clusterMyCluster\ --service-nameMyService\ --task-definitionsample-fargate:1\ --desired-count2\ --launch-typeFARGATE\ --platform-versionLATEST\ --network-configuration 'awsvpcConfiguration={subnets=[subnet-12344321],securityGroups=[sg-12344321],assignPublicIp=ENABLED}' \ --tagskey=key1,value=value1key=key2,value=value2key=key3,value=value3Output: { "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" } }For more information, see Creating a Service in the Amazon ECS Developer Guide. Example 2: To create a service using the EC2 launch type The following create-serviceexample shows how to create a service calledecs-simple-servicewith a task that uses the EC2 launch type. The service uses thesleep360task definition and it maintains 1 instantiation of the task.aws ecs create-service \ --clusterMyCluster\ --service-nameecs-simple-service\ --task-definitionsleep360:2\ --desired-count1Output: { "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": [ { "id": "ecs-svc/1234567890123456789", "status": "PRIMARY", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/sleep360:2", "desiredCount": 1, "pendingCount": 0, "runningCount": 0, "createdAt": 1557206498.798, "updatedAt": 1557206498.798, "launchType": "EC2" } ], "events": [], "createdAt": 1557206498.798, "placementConstraints": [], "placementStrategy": [], "schedulingStrategy": "REPLICA", "enableECSManagedTags": false, "propagateTags": "NONE" } }For more information, see Creating a Service in the Amazon ECS Developer Guide. Example 3: To create a service that uses an external deployment controller The following create-serviceexample creates a service that uses an external deployment controller.aws ecs create-service \ --clusterMyCluster\ --service-nameMyService\ --deployment-controllertype=EXTERNAL\ --desired-count1Output: { "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" } }For more information, see Creating a Service in the Amazon ECS Developer Guide. Example 4: To create a new service behind a load balancer The following create-serviceexample shows how to create a service that is behind a load balancer. You must have a load balancer configured in the same Region as your container instance. This example uses the--cli-input-jsonoption and a JSON input file calledecs-simple-service-elb.jsonwith the following content.aws ecs create-service \ --clusterMyCluster\ --service-nameecs-simple-service-elb\ --cli-input-jsonfile://ecs-simple-service-elb.jsonContents of ecs-simple-service-elb.json:{ "serviceName": "ecs-simple-service-elb", "taskDefinition": "ecs-demo", "loadBalancers": [ { "loadBalancerName": "EC2Contai-EcsElast-123456789012", "containerName": "simple-demo", "containerPort": 80 } ], "desiredCount": 10, "role": "ecsServiceRole" }Output: { "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 } }For more information, see Use load balancing to distribute Amazon ECS service traffic in the Amazon ECS Developer Guide. Example 5: To configure Amazon EBS volumes at service creation The following create-serviceexample shows how to configure Amazon EBS volumes for each task managed by the service. You must have an Amazon ECS infrastructure role configured with theAmazonECSInfrastructureRolePolicyForVolumesmanaged policy attached. You must specify a task definition with the same volume name as in thecreate-servicerequest. This example uses the--cli-input-jsonoption and a JSON input file calledecs-simple-service-ebs.jsonwith the following content.aws ecs create-service \ --cli-input-jsonfile://ecs-simple-service-ebs.jsonContents of ecs-simple-service-ebs.json:{ "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" } } ] }Output: { "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" ], "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" } }For more information, see Use Amazon EBS volumes with Amazon ECS in the Amazon ECS Developer Guide. - 
                    For API details, see CreateService in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use create-task-set.
- Amazon CLI
- 
             
                    To create a task set The following create-task-setexample creates a task set in a service that uses an external deployment controller.aws ecs create-task-set \ --clusterMyCluster\ --serviceMyService\ --task-definitionMyTaskDefinition:2\ --network-configuration"awsvpcConfiguration={subnets=[subnet-12344321],securityGroups=[sg-12344321]}"Output: { "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 } }- 
                    For API details, see CreateTaskSet in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use delete-account-setting.
- Amazon CLI
- 
             
                    To delete the account settings for a specific IAM user or IAM role The following example delete-account-settingdeletes the account settings for the specific IAM user or IAM role.aws ecs delete-account-setting \ --nameserviceLongArnFormat\ --principal-arnarn:aws:iam::123456789012:user/MyUserOutput: { "setting": { "name": "serviceLongArnFormat", "value": "enabled", "principalArn": "arn:aws:iam::123456789012:user/MyUser" } }For more information, see Amazon Resource Names (ARNs) and IDs in the Amazon ECS Developer Guide. - 
                    For API details, see DeleteAccountSetting in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use delete-attributes.
- Amazon CLI
- 
             
                    To delete one or more custom attributes from an Amazon ECS resource The following delete-attributesdeletes an attribute with the namestackfrom a container instance.aws ecs delete-attributes \ --attributesname=stack,targetId=arn:aws:ecs:us-west-2:130757420319:container-instance/1c3be8ed-df30-47b4-8f1e-6e68ebd01f34Output: { "attributes": [ { "name": "stack", "targetId": "arn:aws:ecs:us-west-2:130757420319:container-instance/1c3be8ed-df30-47b4-8f1e-6e68ebd01f34", "value": "production" } ] }- 
                    For API details, see DeleteAttributes in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use delete-capacity-provider.
- Amazon CLI
- 
             
                    Example 1: To delete a capacity provider using the Amazon Resource Name (ARN) The following delete-capacity-providerexample deletes a capacity provider by specifying the Amazon Resource Name (ARN) of the capacity provider. The ARN as well as the status of the capacity provider deletion can be retrieved using thedescribe-capacity-providerscommand.aws ecs delete-capacity-provider \ --capacity-providerarn:aws:ecs:us-west-2:123456789012:capacity-provider/ExampleCapacityProviderOutput: { "capacityProvider": { "capacityProviderArn": "arn:aws:ecs:us-west-2:123456789012:capacity-provider/ExampleCapacityProvider", "name": "ExampleCapacityProvider", "status": "ACTIVE", "autoScalingGroupProvider": { "autoScalingGroupArn": "arn:aws:autoscaling:us-west-2:123456789012:autoScalingGroup:a1b2c3d4-5678-90ab-cdef-EXAMPLE11111:autoScalingGroupName/MyAutoScalingGroup", "managedScaling": { "status": "ENABLED", "targetCapacity": 100, "minimumScalingStepSize": 1, "maximumScalingStepSize": 10000 }, "managedTerminationProtection": "DISABLED" }, "updateStatus": "DELETE_IN_PROGRESS", "tags": [] } }For more information, see Cluster capacity providers in the Amazon ECS Developer Guide. Example 2: To delete a capacity provider using the name The following delete-capacity-providerexample deletes a capacity provider by specifying the short name of the capacity provider. The short name as well as the status of the capacity provider deletion can be retrieved using thedescribe-capacity-providerscommand.aws ecs delete-capacity-provider \ --capacity-providerExampleCapacityProviderOutput: { "capacityProvider": { "capacityProviderArn": "arn:aws:ecs:us-west-2:123456789012:capacity-provider/ExampleCapacityProvider", "name": "ExampleCapacityProvider", "status": "ACTIVE", "autoScalingGroupProvider": { "autoScalingGroupArn": "arn:aws:autoscaling:us-west-2:123456789012:autoScalingGroup:a1b2c3d4-5678-90ab-cdef-EXAMPLE11111:autoScalingGroupName/MyAutoScalingGroup", "managedScaling": { "status": "ENABLED", "targetCapacity": 100, "minimumScalingStepSize": 1, "maximumScalingStepSize": 10000 }, "managedTerminationProtection": "DISABLED" }, "updateStatus": "DELETE_IN_PROGRESS", "tags": [] } }For more information, see Cluster capacity providers in the Amazon ECS Developer Guide. - 
                    For API details, see DeleteCapacityProvider in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use delete-cluster.
- Amazon CLI
- 
             
                    To delete an empty cluster The following delete-clusterexample deletes the specified empty cluster.aws ecs delete-cluster --clusterMyClusterOutput: { "cluster": { "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster", "status": "INACTIVE", "clusterName": "MyCluster", "registeredContainerInstancesCount": 0, "pendingTasksCount": 0, "runningTasksCount": 0, "activeServicesCount": 0 "statistics": [], "tags": [] } }For more information, see Deleting a Cluster in the Amazon ECS Developer Guide. - 
                    For API details, see DeleteCluster in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use delete-service.
- Amazon CLI
- 
             
                    To delete a service The following ecs delete-serviceexample deletes the specified service from a cluster. You can include the--forceparameter to delete a service even if it has not been scaled to zero tasks.aws ecs delete-service --clusterMyCluster--serviceMyService1--forceFor more information, see Deleting a Service in the Amazon ECS Developer Guide. - 
                    For API details, see DeleteService in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use delete-task-definitions.
- Amazon CLI
- 
             
                    To delete a task definition The following delete-task-definitionsexample deletes an INACTIVE task definition.aws ecs delete-task-definitions \ --task-definitioncurltest:1Output: { "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": [] }For more information, see Amazon ECS Task Definitions in the Amazon ECS Developer Guide. - 
                    For API details, see DeleteTaskDefinitions in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use delete-task-set.
- Amazon CLI
- 
             
                    To delete a task set The following delete-task-setexample shows how to delete a task set. You can include the--forceparameter to delete a task set even if it has not been scaled to zero.aws ecs delete-task-set \ --clusterMyCluster\ --serviceMyService\ --task-setarn:aws:ecs:us-west-2:123456789012:task-set/MyCluster/MyService/ecs-svc/1234567890123456789\ --forceOutput: { "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 } }- 
                    For API details, see DeleteTaskSet in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use deregister-container-instance.
- Amazon CLI
- 
             
                    To deregister a container instance from a cluster The following deregister-container-instanceexample deregisters a container instance from the specified cluster. If there are still tasks running in the container instance, you must either stop those tasks before deregistering, or use the--forceoption.aws ecs deregister-container-instance \ --clusterarn:aws:ecs:us-west-2:123456789012:cluster/MyCluster\ --container-instancearn:aws:ecs:us-west-2:123456789012:container-instance/a1b2c3d4-5678-90ab-cdef-11111EXAMPLE\ --forceOutput: { "containerInstance": { "remainingResources": [ { "integerValue": 1024, "doubleValue": 0.0, "type": "INTEGER", "longValue": 0, "name": "CPU" }, { "integerValue": 985, "doubleValue": 0.0, "type": "INTEGER", "longValue": 0, "name": "MEMORY" }, { "type": "STRINGSET", "integerValue": 0, "name": "PORTS", "stringSetValue": [ "22", "2376", "2375", "51678", "51679" ], "longValue": 0, "doubleValue": 0.0 }, { "type": "STRINGSET", "integerValue": 0, "name": "PORTS_UDP", "stringSetValue": [], "longValue": 0, "doubleValue": 0.0 } ], "agentConnected": true, "attributes": [ { "name": "ecs.capability.secrets.asm.environment-variables" }, { "name": "com.amazonaws.ecs.capability.logging-driver.syslog" }, { "value": "ami-01a82c3fce2c3ba58", "name": "ecs.ami-id" }, { "name": "ecs.capability.secrets.asm.bootstrap.log-driver" }, { "name": "com.amazonaws.ecs.capability.logging-driver.none" }, { "name": "ecs.capability.ecr-endpoint" }, { "name": "com.amazonaws.ecs.capability.logging-driver.json-file" }, { "value": "vpc-1234567890123467", "name": "ecs.vpc-id" }, { "name": "ecs.capability.execution-role-awslogs" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.17" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.18" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.19" }, { "name": "ecs.capability.docker-plugin.local" }, { "name": "ecs.capability.task-eni" }, { "name": "ecs.capability.task-cpu-mem-limit" }, { "name": "ecs.capability.secrets.ssm.bootstrap.log-driver" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.30" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.31" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.32" }, { "name": "ecs.capability.execution-role-ecr-pull" }, { "name": "ecs.capability.container-health-check" }, { "value": "subnet-1234567890123467", "name": "ecs.subnet-id" }, { "value": "us-west-2a", "name": "ecs.availability-zone" }, { "value": "t2.micro", "name": "ecs.instance-type" }, { "name": "com.amazonaws.ecs.capability.task-iam-role-network-host" }, { "name": "ecs.capability.aws-appmesh" }, { "name": "com.amazonaws.ecs.capability.logging-driver.awslogs" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.24" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.25" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.26" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.27" }, { "name": "com.amazonaws.ecs.capability.privileged-container" }, { "name": "ecs.capability.container-ordering" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.28" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.29" }, { "value": "x86_64", "name": "ecs.cpu-architecture" }, { "value": "93f43776-2018.10.0", "name": "ecs.capability.cni-plugin-version" }, { "name": "ecs.capability.secrets.ssm.environment-variables" }, { "name": "ecs.capability.pid-ipc-namespace-sharing" }, { "name": "com.amazonaws.ecs.capability.ecr-auth" }, { "value": "linux", "name": "ecs.os-type" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.20" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.21" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.22" }, { "name": "ecs.capability.task-eia" }, { "name": "ecs.capability.private-registry-authentication.secretsmanager" }, { "name": "com.amazonaws.ecs.capability.task-iam-role" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.23" } ], "pendingTasksCount": 0, "tags": [], "containerInstanceArn": "arn:aws:ecs:us-west-2:123456789012:container-instance/a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "registeredResources": [ { "integerValue": 1024, "doubleValue": 0.0, "type": "INTEGER", "longValue": 0, "name": "CPU" }, { "integerValue": 985, "doubleValue": 0.0, "type": "INTEGER", "longValue": 0, "name": "MEMORY" }, { "type": "STRINGSET", "integerValue": 0, "name": "PORTS", "stringSetValue": [ "22", "2376", "2375", "51678", "51679" ], "longValue": 0, "doubleValue": 0.0 }, { "type": "STRINGSET", "integerValue": 0, "name": "PORTS_UDP", "stringSetValue": [], "longValue": 0, "doubleValue": 0.0 } ], "status": "INACTIVE", "registeredAt": 1557768075.681, "version": 4, "versionInfo": { "agentVersion": "1.27.0", "agentHash": "aabe65ee", "dockerVersion": "DockerVersion: 18.06.1-ce" }, "attachments": [], "runningTasksCount": 0, "ec2InstanceId": "i-12345678901234678" } }For more information, see Deregister a Container Instance in the ECS Developer Guide. - 
                    For API details, see DeregisterContainerInstance in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use deregister-task-definition.
- Amazon CLI
- 
             
                    To deregister a task definition The following deregister-task-definitionexample deregisters the first revision of thecurlertask definition in your default region.aws ecs deregister-task-definition --task-definitioncurler:1Note that in the resulting output, the task definition status shows INACTIVE:{ "taskDefinition": { "status": "INACTIVE", "family": "curler", "volumes": [], "taskDefinitionArn": "arn:aws:ecs:us-west-2:123456789012:task-definition/curler:1", "containerDefinitions": [ { "environment": [], "name": "curler", "mountPoints": [], "image": "curl:latest", "cpu": 100, "portMappings": [], "entryPoint": [], "memory": 256, "command": [ "curl -v http://example.com/" ], "essential": true, "volumesFrom": [] } ], "revision": 1 } }For more information, see Amazon ECS Task Definitions in the Amazon ECS Developer Guide. - 
                    For API details, see DeregisterTaskDefinition in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use describe-capacity-providers.
- Amazon CLI
- 
             
                    Example 1: To describe all capacity providers The following describe-capacity-providersexample retrieves details about all capacity providers.aws ecs describe-capacity-providersOutput: { "capacityProviders": [ { "capacityProviderArn": "arn:aws:ecs:us-west-2:123456789012:capacity-provider/MyCapacityProvider", "name": "MyCapacityProvider", "status": "ACTIVE", "autoScalingGroupProvider": { "autoScalingGroupArn": "arn:aws:autoscaling:us-west-2:123456789012:autoScalingGroup:a1b2c3d4-5678-90ab-cdef-EXAMPLE11111:autoScalingGroupName/MyAutoScalingGroup", "managedScaling": { "status": "ENABLED", "targetCapacity": 100, "minimumScalingStepSize": 1, "maximumScalingStepSize": 1000 }, "managedTerminationProtection": "ENABLED" }, "tags": [] }, { "capacityProviderArn": "arn:aws:ecs:us-west-2:123456789012:capacity-provider/FARGATE", "name": "FARGATE", "status": "ACTIVE", "tags": [] }, { "capacityProviderArn": "arn:aws:ecs:us-west-2:123456789012:capacity-provider/FARGATE_SPOT", "name": "FARGATE_SPOT", "status": "ACTIVE", "tags": [] } ] }For more information, see Cluster capacity providers in the Amazon ECS Developer Guide. Example 2: To describe a specific capacity providers The following describe-capacity-providersexample retrieves details about a specific capacity provider. Using the--include TAGSparameter will add the tags associated with the capacity provider to the output.aws ecs describe-capacity-providers \ --capacity-providersMyCapacityProvider\ --includeTAGSOutput: { "capacityProviders": [ { "capacityProviderArn": "arn:aws:ecs:us-west-2:123456789012:capacity-provider/MyCapacityProvider", "name": "MyCapacityProvider", "status": "ACTIVE", "autoScalingGroupProvider": { "autoScalingGroupArn": "arn:aws:autoscaling:us-west-2:123456789012:autoScalingGroup:a1b2c3d4-5678-90ab-cdef-EXAMPLE11111:autoScalingGroupName/MyAutoScalingGroup", "managedScaling": { "status": "ENABLED", "targetCapacity": 100, "minimumScalingStepSize": 1, "maximumScalingStepSize": 1000 }, "managedTerminationProtection": "ENABLED" }, "tags": [ { "key": "environment", "value": "production" } ] } ] }For more information, see Cluster capacity providers in the Amazon ECS Developer Guide. - 
                    For API details, see DescribeCapacityProviders in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use describe-clusters.
- Amazon CLI
- 
             
                    Example 1: To describe a cluster The following describe-clustersexample retrieves details about the specified cluster.aws ecs describe-clusters \ --clusterdefaultOutput: { "clusters": [ { "status": "ACTIVE", "clusterName": "default", "registeredContainerInstancesCount": 0, "pendingTasksCount": 0, "runningTasksCount": 0, "activeServicesCount": 1, "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/default" } ], "failures": [] }For more information, see Amazon ECS Clusters in the Amazon ECS Developer Guide. Example 2: To describe a cluster with the attachment option The following describe-clustersexample specifies the ATTACHMENTS option. It retrieves details about the specified cluster and a list of resources attached to the cluster in the form of attachments. When using a capacity provider with a cluster, the resources, either AutoScaling plans or scaling policies, will be represented as asp or as_policy ATTACHMENTS.aws ecs describe-clusters \ --includeATTACHMENTS\ --clusterssampleClusterOutput: { "clusters": [ { "clusterArn": "arn:aws:ecs:af-south-1:123456789222:cluster/sampleCluster", "clusterName": "sampleCluster", "status": "ACTIVE", "registeredContainerInstancesCount": 0, "runningTasksCount": 0, "pendingTasksCount": 0, "activeServicesCount": 0, "statistics": [], "tags": [], "settings": [], "capacityProviders": [ "sampleCapacityProvider" ], "defaultCapacityProviderStrategy": [], "attachments": [ { "id": "a1b2c3d4-5678-901b-cdef-EXAMPLE22222", "type": "as_policy", "status": "CREATED", "details": [ { "name": "capacityProviderName", "value": "sampleCapacityProvider" }, { "name": "scalingPolicyName", "value": "ECSManagedAutoScalingPolicy-3048e262-fe39-4eaf-826d-6f975d303188" } ] } ], "attachmentsStatus": "UPDATE_COMPLETE" } ], "failures": [] }For more information, see Amazon ECS Clusters in the Amazon ECS Developer Guide. - 
                    For API details, see DescribeClusters in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use describe-container-instances.
- Amazon CLI
- 
             
                    To describe container instance The following describe-container-instancesexample retrieves details for a container instance in theupdatecluster, using the container instance UUID as an identifier.aws ecs describe-container-instances \ --clusterupdate\ --container-instancesa1b2c3d4-5678-90ab-cdef-11111EXAMPLEOutput: { "failures": [], "containerInstances": [ { "status": "ACTIVE", "registeredResources": [ { "integerValue": 2048, "longValue": 0, "type": "INTEGER", "name": "CPU", "doubleValue": 0.0 }, { "integerValue": 3955, "longValue": 0, "type": "INTEGER", "name": "MEMORY", "doubleValue": 0.0 }, { "name": "PORTS", "longValue": 0, "doubleValue": 0.0, "stringSetValue": [ "22", "2376", "2375", "51678" ], "type": "STRINGSET", "integerValue": 0 } ], "ec2InstanceId": "i-A1B2C3D4", "agentConnected": true, "containerInstanceArn": "arn:aws:ecs:us-west-2:123456789012:container-instance/a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "pendingTasksCount": 0, "remainingResources": [ { "integerValue": 2048, "longValue": 0, "type": "INTEGER", "name": "CPU", "doubleValue": 0.0 }, { "integerValue": 3955, "longValue": 0, "type": "INTEGER", "name": "MEMORY", "doubleValue": 0.0 }, { "name": "PORTS", "longValue": 0, "doubleValue": 0.0, "stringSetValue": [ "22", "2376", "2375", "51678" ], "type": "STRINGSET", "integerValue": 0 } ], "runningTasksCount": 0, "versionInfo": { "agentVersion": "1.0.0", "agentHash": "4023248", "dockerVersion": "DockerVersion: 1.5.0" } } ] }For more information, see Amazon ECS Container Instances in the Amazon ECS Developer Guide. - 
                    For API details, see DescribeContainerInstances in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use describe-service-deployments.
- Amazon CLI
- 
             
                    To describe service deployment details The following describe-service-deploymentsexample returns the service deployment details for the service deployment with the ARNarn:aws:ecs:us-east-1:123456789012:service-deployment/example-cluster/example-service/ejGvqq2ilnbKT9qj0vLJe.aws ecs describe-service-deployments \ --service-deployment-arnarn:aws:ecs:us-east-1:123456789012:service-deployment/example-cluster/example-service/ejGvqq2ilnbKT9qj0vLJeOutput: { "serviceDeployments": [ { "serviceDeploymentArn": "arn:aws:ecs:us-east-1:123456789012:service-deployment/example-cluster/example-service/ejGvqq2ilnbKT9qj0vLJe", "serviceArn": "arn:aws:ecs:us-east-1:123456789012:service/example-cluster/example-service", "clusterArn": "arn:aws:ecs:us-east-1:123456789012:cluster/example-cluster", "createdAt": "2024-10-31T08:03:30.917000-04:00", "startedAt": "2024-10-31T08:03:32.510000-04:00", "finishedAt": "2024-10-31T08:05:04.527000-04:00", "updatedAt": "2024-10-31T08:05:04.527000-04:00", "sourceServiceRevisions": [], "targetServiceRevision": { "arn": "arn:aws:ecs:us-east-1:123456789012:service-revision/example-cluster/example-service/1485800978477494678", "requestedTaskCount": 1, "runningTaskCount": 1, "pendingTaskCount": 0 }, "status": "SUCCESSFUL", "deploymentConfiguration": { "deploymentCircuitBreaker": { "enable": true, "rollback": true }, "maximumPercent": 200, "minimumHealthyPercent": 100, "alarms": { "alarmNames": [], "rollback": false, "enable": false } }, "deploymentCircuitBreaker": { "status": "MONITORING_COMPLETE", "failureCount": 0, "threshold": 3 }, "alarms": { "status": "DISABLED" } } ], "failures": [] }For more information, see View service history using Amazon ECS service deployments in the Amazon ECS Developer Guide. - 
                    For API details, see DescribeServiceDeployments in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use describe-service-revisions.
- Amazon CLI
- 
             
                    To describe service revision details The following describe-service-revisionsexample returns the service revision details for the service revision with the ARNarn:aws:ecs:us-east-1:123456789012:service-revision/example-cluster/example-service/1485800978477494678.aws ecs describe-service-revisions \ --service-revision-arnsarn:aws:ecs:us-east-1:123456789012:service-revision/example-cluster/example-service/1485800978477494678Output: { "serviceRevisions": [ { "serviceRevisionArn": "arn:aws:ecs:us-east-1:123456789012:service-revision/example-cluster/example-service/1485800978477494678", "serviceArn": "arn:aws:ecs:us-east-1:123456789012:service/example-cluster/example-service", "clusterArn": "arn:aws:ecs:us-east-1:123456789012:cluster/example-cluster", "taskDefinition": "arn:aws:ecs:us-east-1:123456789012:task-definition/webserver:5", "capacityProviderStrategy": [ { "capacityProvider": "FARGATE", "weight": 1, "base": 0 } ], "platformVersion": "1.4.0", "platformFamily": "Linux", "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-0d0eab1bb38d5ca64", "subnet-0db5010045995c2d5" ], "securityGroups": [ "sg-02556bf85a191f59a" ], "assignPublicIp": "ENABLED" } }, "containerImages": [ { "containerName": "aws-otel-collector", "imageDigest": "sha256:7a1b3560655071bcacd66902c20ebe9a69470d5691fe3bd36baace7c2f3c4640", "image": "public.ecr.aws/aws-observability/aws-otel-collector:v0.32.0" }, { "containerName": "web", "imageDigest": "sha256:28402db69fec7c17e179ea87882667f1e054391138f77ffaf0c3eb388efc3ffb", "image": "nginx" } ], "guardDutyEnabled": false, "serviceConnectConfiguration": { "enabled": false }, "createdAt": "2024-10-31T08:03:29.302000-04:00" } ], "failures": [] }For more information, see Amazon ECS service revisions in the Amazon ECS Developer Guide. - 
                    For API details, see DescribeServiceRevisions in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use describe-services.
- Amazon CLI
- 
             
                    To describe a service The following describe-servicesexample retrieves details for themy-http-serviceservice in the default cluster.aws ecs describe-services --servicesmy-http-serviceOutput: { "services": [ { "status": "ACTIVE", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/amazon-ecs-sample:1", "pendingCount": 0, "loadBalancers": [], "desiredCount": 10, "createdAt": 1466801808.595, "serviceName": "my-http-service", "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/default", "serviceArn": "arn:aws:ecs:us-west-2:123456789012:service/my-http-service", "deployments": [ { "status": "PRIMARY", "pendingCount": 0, "createdAt": 1466801808.595, "desiredCount": 10, "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/amazon-ecs-sample:1", "updatedAt": 1428326312.703, "id": "ecs-svc/1234567890123456789", "runningCount": 10 } ], "events": [ { "message": "(service my-http-service) has reached a steady state.", "id": "a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "createdAt": 1466801812.435 } ], "runningCount": 10 } ], "failures": [] }For more information, see Services in the Amazon ECS Developer Guide. - 
                    For API details, see DescribeServices in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use describe-task-definition.
- Amazon CLI
- 
             
                    To describe a task definition The following describe-task-definitionexample retrieves the details of a task definition.aws ecs describe-task-definition \ --task-definitionhello_world:8Output: { "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": [] }For more information, see Amazon ECS Task Definitions in the Amazon ECS Developer Guide. - 
                    For API details, see DescribeTaskDefinition in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use describe-task-sets.
- Amazon CLI
- 
             
                    To describe a task set The following describe-task-setsexample describes a task set in a service that uses an external deployer.aws ecs describe-task-sets \ --clusterMyCluster\ --serviceMyService\ --task-setsarn:aws:ecs:us-west-2:123456789012:task-set/MyCluster/MyService/ecs-svc/1234567890123456789Output: { "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": [] }- 
                    For API details, see DescribeTaskSets in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use describe-tasks.
- Amazon CLI
- 
             
                    Exampe 1: To describe a single task tasks The following describe-tasksexample retrieves the details of a task in a cluster. You can specify the task by using either the ID or full ARN of the task. This example uses the full ARN of the task.aws ecs describe-tasks \ --clusterMyCluster\ --tasksarn:aws:ecs:us-east-1:123456789012:task/MyCluster/4d590253bb114126b7afa7b58EXAMPLEOutput: { "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": [] }For more information, see Amazon ECS Task Definitions in the Amazon ECS Developer Guide. Exampe 2: To describe multiple tasks The following describe-tasksexample retrieves the details of multiple tasks in a cluster. You can specify the task by using either the ID or full ARN of the task. This example uses the full IDs of the tasks.aws ecs describe-tasks \ --clusterMyCluster\ --tasks"74de0355a10a4f979ac495c14EXAMPLE""d789e94343414c25b9f6bd59eEXAMPLE"Output: { "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": "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": "2021-12-20T12:13:37.875000-05:00", "containers": [ { "containerArn": "arn:aws:ecs:us-east-1:123456789012:container/MyCluster/74de0355a10a4f979ac495c14EXAMPLE/aad3ba00-83b3-4dac-84d4-11f8cEXAMPLE", "taskArn": "arn:aws:ecs:us-east-1:123456789012:task/MyCluster/74de0355a10a4f979ac495c14EXAMPLE", "name": "web", "image": "nginx", "runtimeId": "74de0355a10a4f979ac495c14EXAMPLE-265927825", "lastStatus": "RUNNING", "networkBindings": [], "networkInterfaces": [ { "attachmentId": "d9e7735a-16aa-4128-bc7a-b2d51EXAMPLE", "privateIpv4Address": "10.0.1.184" } ], "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:42.665000-05:00", "pullStoppedAt": "2021-12-20T12:13:46.543000-05:00", "startedAt": "2021-12-20T12:13:48.086000-05:00", "startedBy": "ecs-svc/988401040018EXAMPLE", "tags": [], "taskArn": "arn:aws:ecs:us-east-1:123456789012:task/MyCluster/74de0355a10a4f979ac495c14EXAMPLE", "taskDefinitionArn": "arn:aws:ecs:us-east-1:123456789012:task-definition/webserver:2", "version": 3, "ephemeralStorage": { "sizeInGiB": 20 } }, { "attachments": [ { "id": "214eb5a9-45cd-4bf8-87bc-57fefEXAMPLE", "type": "ElasticNetworkInterface", "status": "ATTACHED", "details": [ { "name": "subnetId", "value": "subnet-0d0eab1bb3EXAMPLE" }, { "name": "networkInterfaceId", "value": "eni-064c7766daEXAMPLE" }, { "name": "macAddress", "value": "0e:76:83:01:17:a9" }, { "name": "privateDnsName", "value": "ip-10-0-1-41.ec2.internal" }, { "name": "privateIPv4Address", "value": "10.0.1.41" } ] } ], "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-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": [] }For more information, see Amazon ECS Task Definitions in the Amazon ECS Developer Guide. - 
                    For API details, see DescribeTasks in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use execute-command.
- Amazon CLI
- 
             
                    To run an interactive /bin/sh command The following execute-commandexample runs an interactive /bin/sh command against a container named MyContainer for a task with an id ofarn:aws:ecs:us-east-1:123456789012:task/MyCluster/d789e94343414c25b9f6bd59eEXAMPLE.aws ecs execute-command \ --clusterMyCluster\ --taskarn:aws:ecs:us-east-1:123456789012:task/MyCluster/d789e94343414c25b9f6bd59eEXAMPLE\ --containerMyContainer\ --interactive \ --command"/bin/sh"This command produces no output. For more information, see Using Amazon ECS Exec for debugging in the Amazon ECS Developer Guide. - 
                    For API details, see ExecuteCommand in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use get-task-protection.
- Amazon CLI
- 
             
                    Retrieve the protection status of task in ECS service The following get-task-protectionprovides the protection status of ECS tasks that belong to Amazon ECS service.aws ecs get-task-protection \ --clusterECS-project-update-cluster\ --tasksc43ed3b1331041f289316f958adb6a24Output: { "protectedTasks": [ { "taskArn": "arn:aws:ecs:us-west-2:123456789012:task/c43ed3b1331041f289316f958adb6a24", "protectionEnabled": false } ], "failures": [] }For more formation on task protection, see Protect your Amazon ECS tasks from being terminated by scale-in events in the Amazon ECS Developer Guide. - 
                    For API details, see GetTaskProtection in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use list-account-settings.
- Amazon CLI
- 
             
                    Example 1: To view the account settings for an account The following list-account-settingsexample displays the effective account settings for an account.aws ecs list-account-settings --effective-settingsOutput: { "settings": [ { "name": "containerInstanceLongArnFormat", "value": "enabled", "principalArn": "arn:aws:iam::123456789012:root" }, { "name": "serviceLongArnFormat", "value": "enabled", "principalArn": "arn:aws:iam::123456789012:root" }, { "name": "taskLongArnFormat", "value": "enabled", "principalArn": "arn:aws:iam::123456789012:root" } ] }Example 2: To view the account settings for a specific IAM user or IAM role The following list-account-settingsexample displays the account settings for the specified IAM user or IAM role.aws ecs list-account-settings --principal-arnarn:aws:iam::123456789012:user/MyUserOutput: { "settings": [ { "name": "serviceLongArnFormat", "value": "enabled", "principalArn": "arn:aws:iam::123456789012:user/MyUser" } ] }For more information, see Amazon Resource Names (ARNs) and IDs in the Amazon ECS Developer Guide. - 
                    For API details, see ListAccountSettings in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use list-attributes.
- Amazon CLI
- 
             
                    To list the container instances that contain a specific attribute The following example lists the attributes for container instances that have the stack=productionattribute in the default cluster.aws ecs list-attributes \ --target-typecontainer-instance\ --attribute-namestack\ --attribute-valueproduction\ --clusterdefaultOutput: { "attributes": [ { "name": "stack", "targetId": "arn:aws:ecs:us-west-2:130757420319:container-instance/1c3be8ed-df30-47b4-8f1e-6e68ebd01f34", "value": "production" } ] }For more information, see Amazon ECS Container Agent Configuration in the Amazon ECS Developer Guide. - 
                    For API details, see ListAttributes in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use list-clusters.
- Amazon CLI
- 
             
                    To list your available clusters The following list-clustersexample lists all of the available clusters.aws ecs list-clustersOutput: { "clusterArns": [ "arn:aws:ecs:us-west-2:123456789012:cluster/MyECSCluster1", "arn:aws:ecs:us-west-2:123456789012:cluster/AnotherECSCluster" ] }For more information, see Amazon ECS Clusters in the Amazon ECS Developer Guide. - 
                    For API details, see ListClusters in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use list-container-instances.
- Amazon CLI
- 
             
                    To list the container instances in a cluster The following list-container-instancesexample lists all of the available container instances in a cluster.aws ecs list-container-instances --clusterMyClusterOutput: { "containerInstanceArns": [ "arn:aws:ecs:us-west-2:123456789012:container-instance/MyCluster/a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "arn:aws:ecs:us-west-2:123456789012:container-instance/MyCluster/a1b2c3d4-5678-90ab-cdef-22222EXAMPLE" ] }For more information, see Amazon ECS Container Instances in the Amazon ECS Developer Guide. - 
                    For API details, see ListContainerInstances in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use list-service-deployments.
- Amazon CLI
- 
             
                    To list service deployments The following list-service-deploymentsexample retrieves the service deployments for the service namedexample-service.aws ecs list-service-deployments \ --servicearn:aws:ecs:us-east-1:123456789012:service/example-cluster/example-serviceOutput: { "serviceDeployments": [ { "serviceDeploymentArn": "arn:aws:ecs:us-east-1:123456789012:service-deployment/example-cluster/example-service/ejGvqq2ilnbKT9qj0vLJe", "serviceArn": "arn:aws:ecs:us-east-1:123456789012:service/example-cluster/example-service", "clusterArn": "arn:aws:ecs:us-east-1:123456789012:cluster/example-cluster", "startedAt": "2024-10-31T08:03:32.510000-04:00", "createdAt": "2024-10-31T08:03:30.917000-04:00", "finishedAt": "2024-10-31T08:05:04.527000-04:00", "targetServiceRevisionArn": "arn:aws:ecs:us-east-1:123456789012:service-revision/example-cluster/example-service/1485800978477494678", "status": "SUCCESSFUL" } ] }For more information, see View service history using Amazon ECS service deployments in the Amazon ECS Developer Guide. - 
                    For API details, see ListServiceDeployments in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use list-services-by-namespace.
- Amazon CLI
- 
             
                    To list the services in a namespace The following list-services-by-namespaceexample lists all of the services configured for the specified namespace in your default Region.aws ecs list-services-by-namespace \ --namespaceservice-connectOutput: { "serviceArns": [ "arn:aws:ecs:us-west-2:123456789012:service/MyCluster/MyService", "arn:aws:ecs:us-west-2:123456789012:service/tutorial/service-connect-nginx-service" ] }For more information, see Service Connect in the Amazon ECS Developer Guide. - 
                    For API details, see ListServicesByNamespace in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use list-services.
- Amazon CLI
- 
             
                    To list the services in a cluster The following list-servicesexample shows how to list the services running in a cluster.aws ecs list-services --clusterMyClusterOutput: { "serviceArns": [ "arn:aws:ecs:us-west-2:123456789012:service/MyCluster/MyService" ] }For more information, see Services in the Amazon ECS Developer Guide. - 
                    For API details, see ListServices in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use list-tags-for-resource.
- Amazon CLI
- 
             
                    To list the tags for a resource The following list-tags-for-resourceexample lists the tags for a specific cluster.aws ecs list-tags-for-resource \ --resource-arnarn:aws:ecs:us-west-2:123456789012:cluster/MyClusterOutput: { "tags": [ { "key": "key1", "value": "value1" }, { "key": "key2", "value": "value2" }, { "key": "key3", "value": "value3" } ] }- 
                    For API details, see ListTagsForResource in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use list-task-definition-families.
- Amazon CLI
- 
             
                    Example 1: To list the registered task definition families The following list-task-definition-familiesexample lists all of the registered task definition families.aws ecs list-task-definition-familiesOutput: { "families": [ "node-js-app", "web-timer", "hpcc", "hpcc-c4-8xlarge" ] }Example 2: To filter the registered task definition families The following list-task-definition-familiesexample lists the task definition revisions that start with "hpcc".aws ecs list-task-definition-families --family-prefixhpccOutput: { "families": [ "hpcc", "hpcc-c4-8xlarge" ] }For more information, see Task Definition Parameters in the Amazon ECS Developer Guide. - 
                    For API details, see ListTaskDefinitionFamilies in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use list-task-definitions.
- Amazon CLI
- 
             
                    Example 1: To list the registered task definitions The following list-task-definitionsexample lists all of the registered task definitions.aws ecs list-task-definitionsOutput: { "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" ] }Example 2: To list the registered task definitions in a family The following list-task-definitions example lists the task definition revisions of a specified family. aws ecs list-task-definitions --family-prefixwordpressOutput: { "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" ] }For more information, see Amazon ECS Task Definitions in the Amazon ECS Developer Guide. - 
                    For API details, see ListTaskDefinitions in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use list-tasks.
- Amazon CLI
- 
             
                    Example 1: To list the tasks in a cluster The following list-tasksexample lists all of the tasks in a cluster.aws ecs list-tasks --clusterdefaultOutput: { "taskArns": [ "arn:aws:ecs:us-west-2:123456789012:task/a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "arn:aws:ecs:us-west-2:123456789012:task/a1b2c3d4-5678-90ab-cdef-22222EXAMPLE" ] }Example 2: To list the tasks on a particular container instance The following list-tasksexample lists the tasks on a container instance, using the container instance UUID as a filter.aws ecs list-tasks --clusterdefault--container-instancea1b2c3d4-5678-90ab-cdef-33333EXAMPLEOutput: { "taskArns": [ "arn:aws:ecs:us-west-2:123456789012:task/a1b2c3d4-5678-90ab-cdef-44444EXAMPLE" ] }For more information, see Amazon ECS Task Definitions in the Amazon ECS Developer Guide. - 
                    For API details, see ListTasks in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use put-account-setting-default.
- Amazon CLI
- 
             
                    To modify the default account settings The following put-account-setting-defaultexample modifies the default account setting for all IAM users or roles on your account. These changes apply to the entire Amazon account unless an IAM user or role explicitly overrides these settings for themselves.aws ecs put-account-setting-default --nameserviceLongArnFormat--valueenabledOutput: { "setting": { "name": "serviceLongArnFormat", "value": "enabled", "principalArn": "arn:aws:iam::123456789012:root" } }For more information, see Amazon Resource Names (ARNs) and IDs in the Amazon ECS Developer Guide. - 
                    For API details, see PutAccountSettingDefault in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use put-account-setting.
- Amazon CLI
- 
             
                    To modify the account setting for your IAM user account The following put-account-settingexample sets thecontainerInsightsaccount setting toenhancedfor your IAM user account. This turns on Container Insights with enhanced observability.aws ecs put-account-setting \ --namecontainerInsights\ --valueenhancedOutput: { "setting": { "name": "containerInsights", "value": "enhanced", "principalArn": "arn:aws:iam::123456789012:user/johndoe", "type": "user" } }For more information, see Modifying Account Settings in the Amazon ECS Developer Guide. - 
                    For API details, see PutAccountSetting in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use put-account-settings.
- Amazon CLI
- 
             
                    To modify the account settings for an IAM user or IAM role The following put-account-settingexample modifies the account settings for the specified IAM user or IAM role.aws ecs put-account-setting \ --nameserviceLongArnFormat\ --valueenabled\ --principal-arnarn:aws:iam::123456789012:user/MyUserOutput: { "setting": { "name": "serviceLongArnFormat", "value": "enabled", "principalArn": "arn:aws:iam::123456789012:user/MyUser" } }- 
                    For API details, see PutAccountSettings in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use put-attributes.
- Amazon CLI
- 
             
                    To create an attribute and associate it with an Amazon ECS resource The following put-attributesapplies an attribute with the name stack and the value production to a container instance.aws ecs put-attributes \ --attributesname=stack,value=production,targetId=arn:aws:ecs:us-west-2:130757420319:container-instance/1c3be8ed-df30-47b4-8f1e-6e68ebd01f34Output: { "attributes": [ { "name": "stack", "targetId": "arn:aws:ecs:us-west-2:130757420319:container-instance/1c3be8ed-df30-47b4-8f1e-6e68ebd01f34", "value": "production" } ] }- 
                    For API details, see PutAttributes in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use put-cluster-capacity-providers.
- Amazon CLI
- 
             
                    Example 1: To add an existing capacity provider to a cluster The following put-cluster-capacity-providersexample adds an existing capacity provider to a cluster. Thecreate-capacity-providercommand is used to create a capacity provider. Thedescribe-clusterscommand is used to describe the current capacity providers and the default capacity provider strategy associated with a cluster. When adding a new capacity provider to a cluster, you must specify all existing capacity providers in addition to the new capacity provider you want to associate with the cluster. You must also specify the default capacity provider strategy to associate with the cluster. In this example, theMyClustercluster has theMyCapacityProvider1capacity provider associated with it and you want to add theMyCapacityProvider2capacity provider and include it in the default capacity provider strategy so tasks are spread evenly across both capacity providers.aws ecs put-cluster-capacity-providers \ --clusterMyCluster\ --capacity-providersMyCapacityProvider1MyCapacityProvider2\ --default-capacity-provider-strategycapacityProvider=MyCapacityProvider1,weight=1capacityProvider=MyCapacityProvider2,weight=1Output: { "cluster": { "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster", "clusterName": "MyCluster", "status": "ACTIVE", "registeredContainerInstancesCount": 0, "runningTasksCount": 0, "pendingTasksCount": 0, "activeServicesCount": 0, "statistics": [], "tags": [], "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": "as_policy", "status": "ACTIVE", "details": [ { "name": "capacityProviderName", "value": "MyCapacityProvider1" }, { "name": "scalingPolicyName", "value": "ECSManagedAutoScalingPolicy-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" } ] }, { "id": "ae592060-2382-4663-9476-b015c685593c", "type": "as_policy", "status": "ACTIVE", "details": [ { "name": "capacityProviderName", "value": "MyCapacityProvider2" }, { "name": "scalingPolicyName", "value": "ECSManagedAutoScalingPolicy-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222" } ] } ], "attachmentsStatus": "UPDATE_IN_PROGRESS" } }For more information, see Cluster capacity providers in the Amazon ECS Developer Guide. Example 2: To remove a capacity provider from a cluster The following put-cluster-capacity-providersexample removes a capacity provider from a cluster. Thedescribe-clusterscommand is used to describe the current capacity providers associated with a cluster. When removing a capacity provider from a cluster, you must specify the capacity providers you want to remain associated with the cluster as well as the default capacity provider strategy to associate with the cluster. In this example, the cluster has theMyCapacityProvider1andMyCapacityProvider2capacity providers associated with it and you want to remove theMyCapacityProvider2capacity provider, so you specify onlyMyCapacityProvider1in the command along with the updated default capacity provider strategy.aws ecs put-cluster-capacity-providers \ --clusterMyCluster\ --capacity-providersMyCapacityProvider1\ --default-capacity-provider-strategycapacityProvider=MyCapacityProvider1,weight=1,base=0Output: { "cluster": { "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster", "clusterName": "MyCluster", "status": "ACTIVE", "registeredContainerInstancesCount": 0, "runningTasksCount": 0, "pendingTasksCount": 0, "activeServicesCount": 0, "statistics": [], "tags": [], "settings": [ { "name": "containerInsights", "value": "enabled" } ], "capacityProviders": [ "MyCapacityProvider1" ], "defaultCapacityProviderStrategy": [ "capacityProvider": "MyCapacityProvider1", "weight": 1, "base": 0 ], "attachments": [ { "id": "0fb0c8f4-6edd-4de1-9b09-17e470ee1918", "type": "as_policy", "status": "ACTIVE", "details": [ { "name": "capacityProviderName", "value": "MyCapacityProvider1" }, { "name": "scalingPolicyName", "value": "ECSManagedAutoScalingPolicy-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" } ] }, { "id": "ae592060-2382-4663-9476-b015c685593c", "type": "as_policy", "status": "DELETING", "details": [ { "name": "capacityProviderName", "value": "MyCapacityProvider2" }, { "name": "scalingPolicyName", "value": "ECSManagedAutoScalingPolicy-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222" } ] } ], "attachmentsStatus": "UPDATE_IN_PROGRESS" } }For more information, see Cluster capacity providers in the Amazon ECS Developer Guide. Example 3: To remove all capacity providers from a cluster The following put-cluster-capacity-providersexample removes all existing capacity providers from the cluster.aws ecs put-cluster-capacity-providers \ --clusterMyCluster\ --capacity-providers[]\ --default-capacity-provider-strategy[]Output: { "cluster": { "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster", "clusterName": "MyCluster", "status": "ACTIVE", "registeredContainerInstancesCount": 0, "runningTasksCount": 0, "pendingTasksCount": 0, "activeServicesCount": 0, "statistics": [], "tags": [], "settings": [ { "name": "containerInsights", "value": "enabled" } ], "capacityProviders": [], "defaultCapacityProviderStrategy": [], "attachments": [ { "id": "0fb0c8f4-6edd-4de1-9b09-17e470ee1918", "type": "as_policy", "status": "DELETING", "details": [ { "name": "capacityProviderName", "value": "MyCapacityProvider1" }, { "name": "scalingPolicyName", "value": "ECSManagedAutoScalingPolicy-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" } ] }, { "id": "ae592060-2382-4663-9476-b015c685593c", "type": "as_policy", "status": "DELETING", "details": [ { "name": "capacityProviderName", "value": "MyCapacityProvider2" }, { "name": "scalingPolicyName", "value": "ECSManagedAutoScalingPolicy-a1b2c3d4-5678-90ab-cdef-EXAMPLE22222" } ] } ], "attachmentsStatus": "UPDATE_IN_PROGRESS" } }For more information, see Cluster capacity providers in the Amazon ECS Developer Guide. - 
                    For API details, see PutClusterCapacityProviders in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use register-task-definition.
- Amazon CLI
- 
             
                    Example 1: To register a task definition with a JSON file The following register-task-definitionexample registers a task definition to the specified family. The container definitions are saved in JSON format at the specified file location.aws ecs register-task-definition \ --cli-input-jsonfile://<path_to_json_file>/sleep360.jsonContents of sleep360.json:{ "containerDefinitions": [ { "name": "sleep", "image": "busybox", "cpu": 10, "command": [ "sleep", "360" ], "memory": 10, "essential": true } ], "family": "sleep360" }Output: { "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 } }For more information, see Example task definitions in the Amazon ECS Developer Guide. Example 2: To register a task definition with a JSON string parameter The following register-task-definitionexample registers a task definition using container definitions provided as a JSON string parameter with escaped double quotes.aws ecs register-task-definition \ --familysleep360\ --container-definitions "[{\"name\":\"sleep\",\"image\":\"busybox\",\"cpu\":10,\"command\":[\"sleep\",\"360\"],\"memory\":10,\"essential\":true}]"The output is identical to the previous example. For more information, see Creating a Task Definition in the Amazon ECS Developer Guide. - 
                    For API details, see RegisterTaskDefinition in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use run-task.
- Amazon CLI
- 
             
                    Example 1: To run a task on your default cluster The following run-taskexample runs a task on the default cluster and uses a client token.aws ecs run-task \ --clusterdefault\ --task-definitionsleep360:1\ --client-token550e8400-e29b-41d4-a716-446655440000Output: { "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": [] }For more information, see Running an application as a standalone task in the Amazon ECS Developer Guide. Example 2: To configure an Amazon EBS volume for a standalone task The following run-taskexample configures an encrypted Amazon EBS volume for a Fargate task on the default cluster. You must have an Amazon ECS infrastructure role configured with theAmazonECSInfrastructureRolePolicyForVolumesmanaged policy attached. You must specify a task definition with the same volume name as in therun-taskrequest. This example uses the--cli-input-jsonoption and a JSON input file calledebs.json.aws ecs run-task \ --cli-input-jsonfile://ebs.jsonContents of ebs.json:{ "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" } } ] }Output: { "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", "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": "FARGATE", "memory": "3072", "overrides": { "containerOverrides": [ { "name": "container-using-ebs" } ], "inferenceAcceleratorOverrides": [] }, "platformVersion": "1.4.0", "platformFamily": "Linux", "tags": [], "taskArn": "arn:aws:ecs:us-west-2:123456789012:task/default/7f1fbd3629434cc4b82d72d2f09b67c9", "taskDefinitionArn": "arn:aws:ecs:us-west-2:123456789012:task-definition/mytaskdef:4", "version": 1, "ephemeralStorage": { "sizeInGiB": 20 }, "fargateEphemeralStorage": { "sizeInGiB": 20 } } ], "failures": [] }For more information, see Use Amazon EBS volumes with Amazon ECS in the Amazon ECS Developer Guide. - 
                    For API details, see RunTask in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use start-task.
- Amazon CLI
- 
             
                    Example 1: To start a new task The following start-taskexample starts a task using the latest revision of thesleep360task definition on the specified container instance in the default cluster.aws ecs start-task \ --task-definitionsleep360\ --container-instances765936fadbdd46b5991a4bd70c2a43d4Output: { "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": [] }For more information, see Schedule your containers on Amazon ECS in the Amazon ECS Developer Guide. Example 2: To configure an Amazon EBS volume at task start The following start-taskexample configures an encrypted Amazon EBS volume for a task on the specified container instance. You must have an Amazon ECS infrastructure role configured with theAmazonECSInfrastructureRolePolicyForVolumesmanaged policy attached. You must specify a task definition with the same volume name as in thestart-taskrequest. This example uses the--cli-input-jsonoption and a JSON input file calledebs.jsonwith the following content.aws ecs start-task \ --cli-input-jsonfile://ebs.json\ --container-instances765936fadbdd46b5991a4bd70c2a43d4Contents of ebs.json:{ "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" } } ] }Output: { "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" } ] } ], "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": [] }For more information, see Use Amazon EBS volumes with Amazon ECS in the Amazon ECS Developer Guide. - 
                    For API details, see StartTask in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use stop-task.
- Amazon CLI
- 
             
                    To stop a task The following stop-taskstops the specified task from running in the default cluster.aws ecs stop-task \ --task666fdccc2e2d4b6894dd422f4eeee8f8Output: { "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": [] } }- 
                    For API details, see StopTask in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use tag-resource.
- Amazon CLI
- 
             
                    To tag a resource The following tag-resourceexample adds a single tag to the specified resource.aws ecs tag-resource \ --resource-arnarn:aws:ecs:us-west-2:123456789012:cluster/MyCluster--tagskey=key1,value=value1This command produces no output. To add multiple tags to a resource The following tag-resourceexample adds multiple tags to the specified resource.aws ecs tag-resource \ --resource-arnarn:aws:ecs:us-west-2:123456789012:cluster/MyCluster\ --tagskey=key1,value=value1key=key2,value=value2key=key3,value=value3This command produces no output. - 
                    For API details, see TagResource in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use untag-resource.
- Amazon CLI
- 
             
                    To remove a tag from a resource The following untag-resourceexample removes the listed tags from the specified resource.aws ecs untag-resource \ --resource-arnarn:aws:ecs:us-west-2:123456789012:cluster/MyCluster\ --tag-keyskey1,key2This command produces no output. - 
                    For API details, see UntagResource in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use update-cluster-settings.
- Amazon CLI
- 
             
                    To modify the settings for your cluster The following update-cluster-settingsexample enables CloudWatch Container Insights with enhanced observability for theMyClustercluster.aws ecs update-cluster-settings \ --clusterMyCluster\ --settingsname=containerInsights,value=enhancedOutput: { "cluster": { "clusterArn": "arn:aws:ecs:us-esat-1:123456789012:cluster/MyCluster", "clusterName": "default", "status": "ACTIVE", "registeredContainerInstancesCount": 0, "runningTasksCount": 0, "pendingTasksCount": 0, "activeServicesCount": 0, "statistics": [], "tags": [], "settings": [ { "name": "containerInsights", "value": "enhanced" } ] } }For more information, see Modifying Account Settings in the Amazon ECS Developer Guide. - 
                    For API details, see UpdateClusterSettings in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use update-cluster.
- Amazon CLI
- 
             
                    Example 1: Update ECS cluster enabling containerInsights The following update-clusterupdates the containerInsights value toenabledin an already created cluster. By default, it is disabled.aws ecs update-cluster \ --clusterECS-project-update-cluster\ --settingsname=containerInsights,value=enabledOutput: "cluster": { "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/ECS-project-update-cluster", "clusterName": "ECS-project-update-cluster", "status": "ACTIVE", "registeredContainerInstancesCount": 0, "runningTasksCount": 0, "pendingTasksCount": 0, "activeServicesCount": 0, "statistics": [], "tags": [], "settings": [ { "name": "containerInsights", "value": "enabled" } ], "capacityProviders": [ "Infra-ECS-Cluster-ECS-project-update-cluster-d6bb6d5b-EC2CapacityProvider-3fIpdkLywwFt" ], "defaultCapacityProviderStrategy": [ { "capacityProvider": "Infra-ECS-Cluster-ECS-project-update-cluster-d6bb6d5b-EC2CapacityProvider-3fIpdkLywwFt", "weight": 1, "base": 0 } ], "attachments": [ { "id": "069d002b-7634-42e4-b1d4-544f4c8f6380", "type": "as_policy", "status": "CREATED", "details": [ { "name": "capacityProviderName", "value": "Infra-ECS-Cluster-ECS-project-update-cluster-d6bb6d5b-EC2CapacityProvider-3fIpdkLywwFt" }, { "name": "scalingPolicyName", "value": "ECSManagedAutoScalingPolicy-152363a6-8c65-484c-b721-42c3e070ae93" } ] }, { "id": "08b5b6ca-45e9-4209-a65d-e962a27c490a", "type": "managed_draining", "status": "CREATED", "details": [ { "name": "capacityProviderName", "value": "Infra-ECS-Cluster-ECS-project-update-cluster-d6bb6d5b-EC2CapacityProvider-3fIpdkLywwFt" }, { "name": "autoScalingLifecycleHookName", "value": "ecs-managed-draining-termination-hook" } ] }, { "id": "45d0b36f-8cff-46b6-9380-1288744802ab", "type": "sc", "status": "ATTACHED", "details": [] } ], "attachmentsStatus": "UPDATE_COMPLETE", "serviceConnectDefaults": { "namespace": "arn:aws:servicediscovery:us-west-2:123456789012:namespace/ns-igwrsylmy3kwvcdx" } }Example 2: Update ECS cluster to set a default Service Connect namspace The following update-clusterupdates ECS cluster by setting a default Service Connect namespace.aws ecs update-cluster \ --clusterECS-project-update-cluster\ --service-connect-defaultsnamespace=testOutput: { "cluster": { "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/ECS-project-update-cluster", "clusterName": "ECS-project-update-cluster", "status": "ACTIVE", "registeredContainerInstancesCount": 0, "runningTasksCount": 0, "pendingTasksCount": 0, "activeServicesCount": 0, "statistics": [], "tags": [], "settings": [ { "name": "containerInsights", "value": "enabled" } ], "capacityProviders": [ "Infra-ECS-Cluster-ECS-project-update-cluster-d6bb6d5b-EC2CapacityProvider-3fIpdkLywwFt" ], "defaultCapacityProviderStrategy": [ { "capacityProvider": "Infra-ECS-Cluster-ECS-project-update-cluster-d6bb6d5b-EC2CapacityProvider-3fIpdkLywwFt", "weight": 1, "base": 0 } ], "attachments": [ { "id": "069d002b-7634-42e4-b1d4-544f4c8f6380", "type": "as_policy", "status": "CREATED", "details": [ { "name": "capacityProviderName", "value": "Infra-ECS-Cluster-ECS-project-update-cluster-d6bb6d5b-EC2CapacityProvider-3fIpdkLywwFt" }, { "name": "scalingPolicyName", "value": "ECSManagedAutoScalingPolicy-152363a6-8c65-484c-b721-42c3e070ae93" } ] }, { "id": "08b5b6ca-45e9-4209-a65d-e962a27c490a", "type": "managed_draining", "status": "CREATED", "details": [ { "name": "capacityProviderName", "value": "Infra-ECS-Cluster-ECS-project-update-cluster-d6bb6d5b-EC2CapacityProvider-3fIpdkLywwFt" }, { "name": "autoScalingLifecycleHookName", "value": "ecs-managed-draining-termination-hook" } ] }, { "id": "45d0b36f-8cff-46b6-9380-1288744802ab", "type": "sc", "status": "DELETED", "details": [] }, { "id": "3e6890c3-609c-4832-91de-d6ca891b3ef1", "type": "sc", "status": "ATTACHED", "details": [] }, { "id": "961b8ec1-c2f1-4070-8495-e669b7668e90", "type": "sc", "status": "DELETED", "details": [] } ], "attachmentsStatus": "UPDATE_COMPLETE", "serviceConnectDefaults": { "namespace": "arn:aws:servicediscovery:us-west-2:123456789012:namespace/ns-dtjmxqpfi46ht7dr" } } }For more information on Service Connect, see Use Service Connect to connect Amazon ECS services with short names in the Amazon ECS Developer Guide. - 
                    For API details, see UpdateCluster in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use update-container-agent.
- Amazon CLI
- 
             
                    To update the container agent on an Amazon ECS container instance The following update-container-agentexample updates the container agent on the specified container instance in the default cluster.aws ecs update-container-agent --clusterdefault--container-instancea1b2c3d4-5678-90ab-cdef-11111EXAMPLEOutput: { "containerInstance": { "status": "ACTIVE", ... "agentUpdateStatus": "PENDING", "versionInfo": { "agentVersion": "1.0.0", "agentHash": "4023248", "dockerVersion": "DockerVersion: 1.5.0" } } }For more information, see Updating the Amazon ECS Container Agent in the Amazon ECS Developer Guide. - 
                    For API details, see UpdateContainerAgent in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use update-container-instances-state.
- Amazon CLI
- 
             
                    To update the state of a container instance The following update-container-instances-stateupdates the state of the specified container instance toDRAININGwhich will remove it from the cluster is it registered to.aws ecs update-container-instances-state \ --container-instances765936fadbdd46b5991a4bd70c2a43d4\ --statusDRAININGOutput: { "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" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.30" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.31" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.32" }, { "name": "ecs.availability-zone", "value": "us-west-2c" }, { "name": "ecs.capability.aws-appmesh" }, { "name": "com.amazonaws.ecs.capability.logging-driver.awslogs" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.24" }, { "name": "ecs.capability.task-eni-trunking" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.25" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.26" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.27" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.28" }, { "name": "com.amazonaws.ecs.capability.privileged-container" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.29" }, { "name": "ecs.cpu-architecture", "value": "x86_64" }, { "name": "com.amazonaws.ecs.capability.ecr-auth" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.20" }, { "name": "ecs.os-type", "value": "linux" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.21" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.22" }, { "name": "ecs.capability.task-eia" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.23" }, { "name": "ecs.capability.private-registry-authentication.secretsmanager" }, { "name": "com.amazonaws.ecs.capability.logging-driver.syslog" }, { "name": "com.amazonaws.ecs.capability.logging-driver.json-file" }, { "name": "ecs.capability.execution-role-awslogs" }, { "name": "ecs.vpc-id", "value": "vpc-1234" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.17" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.18" }, { "name": "com.amazonaws.ecs.capability.docker-remote-api.1.19" }, { "name": "ecs.capability.task-eni" }, { "name": "ecs.capability.execution-role-ecr-pull" }, { "name": "ecs.capability.container-health-check" }, { "name": "ecs.subnet-id", "value": "subnet-1234" }, { "name": "ecs.instance-type", "value": "c5.large" }, { "name": "com.amazonaws.ecs.capability.task-iam-role-network-host" }, { "name": "ecs.capability.container-ordering" }, { "name": "ecs.capability.cni-plugin-version", "value": "91ccefc8-2019.06.0" }, { "name": "ecs.capability.pid-ipc-namespace-sharing" }, { "name": "ecs.capability.secrets.ssm.environment-variables" }, { "name": "com.amazonaws.ecs.capability.task-iam-role" } ], "registeredAt": 1560788724.507, "attachments": [], "tags": [] } ], "failures": [] }- 
                    For API details, see UpdateContainerInstancesState in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use update-service-primary-task-set.
- Amazon CLI
- 
             
                    To update the primary task set for a service The following update-service-primary-task-setexample updates the primary task set for the specified service.aws ecs update-service-primary-task-set \ --clusterMyCluster\ --serviceMyService\ --primary-task-setarn:aws:ecs:us-west-2:123456789012:task-set/MyCluster/MyService/ecs-svc/1234567890123456789Output: { "taskSet": { "id": "ecs-svc/1234567890123456789", "taskSetArn": "arn:aws:ecs:us-west-2:123456789012:task-set/MyCluster/MyService/ecs-svc/1234567890123456789", "status": "PRIMARY", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/sample-fargate:2", "computedDesiredCount": 1, "pendingCount": 0, "runningCount": 0, "createdAt": 1557128360.711, "updatedAt": 1557129412.653, "launchType": "EC2", "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-12344321" ], "securityGroups": [ "sg-12344312" ], "assignPublicIp": "DISABLED" } }, "loadBalancers": [], "serviceRegistries": [], "scale": { "value": 50.0, "unit": "PERCENT" }, "stabilityStatus": "STABILIZING", "stabilityStatusAt": 1557129279.914 } }- 
                    For API details, see UpdateServicePrimaryTaskSet in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use update-service.
- Amazon CLI
- 
             
                    Example 1: To change the task definition used in a service The following update-serviceexample updates themy-http-serviceservice to use theamazon-ecs-sampletask definition.aws ecs update-service \ --clustertest\ --servicemy-http-service\ --task-definitionamazon-ecs-sampleOutput: { "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." } ], "createdAt": "2024-10-30T17:12:43.218000-05:00", "placementConstraints": [], "placementStrategy": [], "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-12344321", ], "securityGroups": [ "sg-12344321" ], "assignPublicIp": "ENABLED" } }, "healthCheckGracePeriodSeconds": 0, "schedulingStrategy": "REPLICA", "deploymentController": { "type": "ECS" }, "createdBy": "arn:aws:iam::123456789012:role/AIDACKCEVSQ6C2EXAMPLE", "enableECSManagedTags": true, "propagateTags": "NONE", "enableExecuteCommand": false, "availabilityZoneRebalancing": "DISABLED" } }For more information, see Update an Amazon ECS service using the console in the Amazon ECS Developer Guide. Example 2: To change the number of tasks in a service The following update-serviceexample updates the desired task count of the servicemy-http-servicefrom to 2.aws ecs update-service \ --clusterMyCluster\ --servicemy-http-service\ --desired-count2Output: { "service": { "serviceArn": "arn:aws:ecs:us-east-1:123456789012:service/MyCluster/my-http-service", "serviceName": "my-http-service", "clusterArn": "arn:aws:ecs:us-east-1:123456789012:cluster/MyCluster", "loadBalancers": [], "serviceRegistries": [], "status": "ACTIVE", "desiredCount": 2, "runningCount": 1, "pendingCount": 0, "capacityProviderStrategy": [ { "capacityProvider": "FARGATE", "weight": 1, "base": 0 } ], "platformVersion": "LATEST", "platformFamily": "Linux", "taskDefinition": "arn:aws:ecs:us-east-1:123456789012:task-definition/MyTaskDefinition", "deploymentConfiguration": { "deploymentCircuitBreaker": { "enable": true, "rollback": true }, "maximumPercent": 200, "minimumHealthyPercent": 100, "alarms": { "alarmNames": [], "rollback": false, "enable": false } }, "deployments": [ { "id": "ecs-svc/1976744184940610707", "status": "PRIMARY", "taskkDefinition": "arn:aws:ecs:us-east-1:123456789012:task-definition/MyTaskDefinition", "desiredCount": 1, "pendingCount": 0, "runningCount": 1, "failedTasks": 0, "createdAt": "2024-12-03T16:24:25.225000-05:00", "updatedAt": "2024-12-03T16:25:15.837000-05:00", "capacityProviderStrategy": [ { "capacityProvider": "FARGATE", "weight": 1, "base": 0 } ], "platformVersion": "1.4.0", "platformFamily": "Linux", "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-0d0eab1bb38d5ca64", "subnet-0db5010045995c2d5" ], "securityGroups": [ "sg-02556bf85a191f59a" ], "assignPublicIp": "ENABLED" } }, "rolloutState": "COMPLETED", "rolloutStateReason": "ECS deployment ecs-svc/1976744184940610707 completed." } ], "roleArn": "arn:aws:iam::123456789012:role/aws-service-role/ecs.amazonaws.com/AWSServiceRoleForECS", "events": [ { "id": "f27350b9-4b2a-4e2e-b72e-a4b68380de45", "createdAt": "2024-12-30T13:24:07.345000-05:00", "message": "(service my-http-service) has reached a steady state." }, { "id": "e764ec63-f53f-45e3-9af2-d99f922d2957", "createdAt": "2024-12-30T12:32:21.600000-05:00", "message": "(service my-http-service) has reached a steady state." }, { "id": "28444756-c2fa-47f8-bd60-93a8e05f3991", "createdAt": "2024-12-08T19:26:10.367000-05:00", "message": "(service my-http-service) has reached a steady state." } ], "createdAt": "2024-12-03T16:24:25.225000-05:00", "placementConstraints": [], "placementStrategy": [], "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-0d0eab1bb38d5ca64", "subnet-0db5010045995c2d5" ], "securityGroups": [ "sg-02556bf85a191f59a" ], "assignPublicIp": "ENABLED" } }, "healthCheckGracePeriodSeconds": 0, "schedulingStrategy": "REPLICA", "deploymentController": { "type": "ECS" }, "createdBy": "arn:aws:iam::123456789012:role/Admin", "enableECSManagedTags": true, "propagateTags": "NONE", "enableExecuteCommand": false, "availabilityZoneRebalancing": "ENABLED" } }For more information, see Updating an Amazon ECS service using the console in the Amazon ECS Developer Guide. Example 3: To configure Amazon EBS volumes for attachment at service update The following update-serviceexample updates the servicemy-http-serviceto use Amazon EBS volumes. You must have an Amazon ECS infrastructure role configured with theAmazonECSInfrastructureRolePolicyForVolumesmanaged policy attached. You must also specify a task definition with the same volume name as in theupdate-servicerequest and withconfiguredAtLaunchset totrue. This example uses the--cli-input-jsonoption and a JSON input file calledebs.json.aws ecs update-service \ --cli-input-jsonfile://ebs.jsonContents of ebs.json:{ "cluster": "mycluster", "taskDefinition": "mytaskdef", "service": "my-http-service", "desiredCount": 2, "volumeConfigurations": [ { "name": "myEbsVolume", "managedEBSVolume": { "roleArn":"arn:aws:iam::123456789012:role/ecsInfrastructureRole", "volumeType": "gp3", "sizeInGiB": 100, "iops": 3000, "throughput": 125, "filesystemType": "ext4" } } ] }Output: { "service": { "serviceArn": "arn:aws:ecs:us-west-2:123456789012:service/mycluster/my-http-service", "serviceName": "my-http-service", "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/mycluster", "loadBalancers": [], "serviceRegistries": [], "status": "ACTIVE", "desiredCount": 2, "runningCount": 2, "pendingCount": 0, "launchType": "FARGATE", "platformVersion": "LATEST", "platformFamily": "Linux", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/mytaskdef:1", "deploymentConfiguration": { "deploymentCircuitBreaker": { "enable": true, "rollback": true }, "maximumPercent": 200, "minimumHealthyPercent": 100, "alarms": { "alarmNames": [], "rollback": false, "enable": false } }, "deployments": [ { "id": "ecs-svc/2420458347226626275", "status": "PRIMARY", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/mytaskdef:1", "desiredCount": 0, "pendingCount": 0, "runningCount": 0, "failedTasks": 0, "createdAt": "2025-02-21T15:07:20.519000-06:00", "updatedAt": "2025-02-21T15:07:20.519000-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/2420458347226626275 in progress.", "volumeConfigurations": [ { "name": "ebs-volume", "managedEBSVolume": { "volumeType": "gp3", "sizeInGiB": 100, "iops": 3000, "throughput": 125, "roleArn": "arn:aws:iam::123456789012:role/ecsInfrastructureRole", "filesystemType": "ext4" } } ] }, { "id": "ecs-svc/5191625155316533644", "status": "ACTIVE", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/mytaskdef:2", "desiredCount": 2, "pendingCount": 0, "runningCount": 2, "failedTasks": 0, "createdAt": "2025-02-21T14:54:48.862000-06:00", "updatedAt": "2025-02-21T14:57:22.502000-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/5191625155316533644 completed." } ], "roleArn": "arn:aws:iam::123456789012:role/aws-service-role/ecs.amazonaws.com/AWSServiceRoleForECS", "events": [ { "id": "b5823113-c2c5-458e-9649-8c2ed38f23a5", "createdAt": "2025-02-21T14:57:22.508000-06:00", "message": "(service my-http-service) has reached a steady state." }, { "id": "b05a48e8-da35-4074-80aa-37ceb3167357", "createdAt": "2025-02-21T14:57:22.507000-06:00", "message": "(service my-http-service) (deployment ecs-svc/5191625155316533644) deployment completed." }, { "id": "a10cd55d-4ba6-4cea-a655-5a5d32ada8a0", "createdAt": "2025-02-21T14:55:32.833000-06:00", "message": "(service my-http-service) has started 1 tasks: (task fb9c8df512684aec92f3c57dc3f22361)." }, ], "createdAt": "2025-02-21T14:54:48.862000-06:00", "placementConstraints": [], "placementStrategy": [], "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-12344321" ], "securityGroups": [ "sg-12344321" ], "assignPublicIp": "ENABLED" } }, "healthCheckGracePeriodSeconds": 0, "schedulingStrategy": "REPLICA", "deploymentController": { "type": "ECS" }, "createdBy": "arn:aws:iam::123456789012:role/AIDACKCEVSQ6C2EXAMPLE", "enableECSManagedTags": true, "propagateTags": "NONE", "enableExecuteCommand": false, "availabilityZoneRebalancing": "ENABLED" } }For more information, see Use Amazon EBS volumes with Amazon ECS in the Amazon ECS Developer Guide. Example 4: To update a service to no longer use Amazon EBS volumes The following update-serviceexample updates the servicemy-http-serviceto no longer use Amazon EBS volumes. You must specify a task definition revision withconfiguredAtLaunchset tofalse.aws ecs update-service \ --clustermycluster\ --task-definitionmytaskdef\ --servicemy-http-service\ --desired-count2\ --volume-configurations"[]"Output: { "service": { "serviceArn": "arn:aws:ecs:us-west-2:123456789012:service/mycluster/my-http-service", "serviceName": "my-http-service", "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/mycluster", "loadBalancers": [], "serviceRegistries": [], "status": "ACTIVE", "desiredCount": 2, "runningCount": 2, "pendingCount": 0, "launchType": "FARGATE", "platformVersion": "LATEST", "platformFamily": "Linux", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/mytaskdef:3", "deploymentConfiguration": { "deploymentCircuitBreaker": { "enable": true, "rollback": true }, "maximumPercent": 200, "minimumHealthyPercent": 100, "alarms": { "alarmNames": [], "rollback": false, "enable": false } }, "deployments": [ { "id": "ecs-svc/7522791612543716777", "status": "PRIMARY", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/mytaskdef:3", "desiredCount": 0, "pendingCount": 0, "runningCount": 0, "failedTasks": 0, "createdAt": "2025-02-21T15:25:38.598000-06:00", "updatedAt": "2025-02-21T15:25:38.598000-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/7522791612543716777 in progress." }, { "id": "ecs-svc/2420458347226626275", "status": "ACTIVE", "taskDefinition": "arn:aws:ecs:us-west-2:123456789012:task-definition/myoldtaskdef:1", "desiredCount": 2, "pendingCount": 0, "runningCount": 2, "failedTasks": 0, "createdAt": "2025-02-21T15:07:20.519000-06:00", "updatedAt": "2025-02-21T15:10:59.955000-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/2420458347226626275 completed.", "volumeConfigurations": [ { "name": "ebs-volume", "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": [ { "id": "4f2c3ca1-7800-4048-ba57-bba210ada2ad", "createdAt": "2025-02-21T15:10:59.959000-06:00", "message": "(service my-http-service) has reached a steady state." }, { "id": "4b36a593-2d40-4ed6-8be8-b9b699eb6198", "createdAt": "2025-02-21T15:10:59.958000-06:00", "message": "(service my-http-service) (deployment ecs-svc/2420458347226626275) deployment completed." }, { "id": "88380089-14e2-4ef0-8dbb-a33991683371", "createdAt": "2025-02-21T15:09:39.055000-06:00", "message": "(service my-http-service) has stopped 1 running tasks: (task fb9c8df512684aec92f3c57dc3f22361)." }, { "id": "97d84243-d52f-4255-89bb-9311391c61f6", "createdAt": "2025-02-21T15:08:57.653000-06:00", "message": "(service my-http-service) has stopped 1 running tasks: (task 33eff090ad2c40539daa837e6503a9bc)." }, { "id": "672ece6c-e2d0-4021-b5da-eefb14001687", "createdAt": "2025-02-21T15:08:15.631000-06:00", "message": "(service my-http-service) has started 1 tasks: (task 996c02a66ff24f3190a4a8e0c841740f)." }, { "id": "a3cf9bea-9be6-4175-ac28-4c68360986eb", "createdAt": "2025-02-21T15:07:36.931000-06:00", "message": "(service my-http-service) has started 1 tasks: (task d5d23c39f89e46cf9a647b9cc6572feb)." }, { "id": "b5823113-c2c5-458e-9649-8c2ed38f23a5", "createdAt": "2025-02-21T14:57:22.508000-06:00", "message": "(service my-http-service) has reached a steady state." }, { "id": "b05a48e8-da35-4074-80aa-37ceb3167357", "createdAt": "2025-02-21T14:57:22.507000-06:00", "message": "(service my-http-service) (deployment ecs-svc/5191625155316533644) deployment completed." }, { "id": "a10cd55d-4ba6-4cea-a655-5a5d32ada8a0", "createdAt": "2025-02-21T14:55:32.833000-06:00", "message": "(service my-http-service) has started 1 tasks: (task fb9c8df512684aec92f3c57dc3f22361)." }, { "id": "42da91fa-e26d-42ef-88c3-bb5965c56b2f", "createdAt": "2025-02-21T14:55:02.703000-06:00", "message": "(service my-http-service) has started 1 tasks: (task 33eff090ad2c40539daa837e6503a9bc)." } ], "createdAt": "2025-02-21T14:54:48.862000-06:00", "placementConstraints": [], "placementStrategy": [], "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-12344321" ], "securityGroups": [ "sg-12344321" ], "assignPublicIp": "ENABLED" } }, "healthCheckGracePeriodSeconds": 0, "schedulingStrategy": "REPLICA", "deploymentController": { "type": "ECS" }, "createdBy": "arn:aws:iam::123456789012:role/AIDACKCEVSQ6C2EXAMPLE", "enableECSManagedTags": true, "propagateTags": "NONE", "enableExecuteCommand": false, "availabilityZoneRebalancing": "ENABLED" } }For more information, see Use Amazon EBS volumes with Amazon ECS in the Amazon ECS Developer Guide. Example 5: To turn on Availability Zone rebalancing for a service The following update-serviceexample turns on Availability Zone rebalancing for the servicemy-http-service.aws ecs update-service \ --clusterMyCluster\ --servicemy-http-service\ --availability-zone-rebalancingENABLEDOutput: { "service": { "serviceArn": "arn:aws:ecs:us-east-1:123456789012:service/MyCluster/my-http-service", "serviceName": "my-http-service", "clusterArn": "arn:aws:ecs:us-east-1:123456789012:cluster/MyCluster", "loadBalancers": [], "serviceRegistries": [], "status": "ACTIVE", "desiredCount": 2, "runningCount": 1, "pendingCount": 0, "capacityProviderStrategy": [ { "capacityProvider": "FARGATE", "weight": 1, "base": 0 } ], "platformVersion": "LATEST", "platformFamily": "Linux", "taskDefinition": "arn:aws:ecs:us-east-1:123456789012:task-definition/MyTaskDefinition", "deploymentConfiguration": { "deploymentCircuitBreaker": { "enable": true, "rollback": true }, "maximumPercent": 200, "minimumHealthyPercent": 100, "alarms": { "alarmNames": [], "rollback": false, "enable": false } }, "deployments": [ { "id": "ecs-svc/1976744184940610707", "status": "PRIMARY", "taskkDefinition": "arn:aws:ecs:us-east-1:123456789012:task-definition/MyTaskDefinition", "desiredCount": 1, "pendingCount": 0, "runningCount": 1, "failedTasks": 0, "createdAt": "2024-12-03T16:24:25.225000-05:00", "updatedAt": "2024-12-03T16:25:15.837000-05:00", "capacityProviderStrategy": [ { "capacityProvider": "FARGATE", "weight": 1, "base": 0 } ], "platformVersion": "1.4.0", "platformFamily": "Linux", "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-0d0eab1bb38d5ca64", "subnet-0db5010045995c2d5" ], "securityGroups": [ "sg-02556bf85a191f59a" ], "assignPublicIp": "ENABLED" } }, "rolloutState": "COMPLETED", "rolloutStateReason": "ECS deployment ecs-svc/1976744184940610707 completed." } ], "roleArn": "arn:aws:iam::123456789012:role/aws-service-role/ecs.amazonaws.com/AWSServiceRoleForECS", "events": [], "createdAt": "2024-12-03T16:24:25.225000-05:00", "placementConstraints": [], "placementStrategy": [], "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-0d0eab1bb38d5ca64", "subnet-0db5010045995c2d5" ], "securityGroups": [ "sg-02556bf85a191f59a" ], "assignPublicIp": "ENABLED" } }, "healthCheckGracePeriodSeconds": 0, "schedulingStrategy": "REPLICA", "deploymentController": { "type": "ECS" }, "createdBy": "arn:aws:iam::123456789012:role/Admin", "enableECSManagedTags": true, "propagateTags": "NONE", "enableExecuteCommand": false, "availabilityZoneRebalancing": "ENABLED" } }For more information, see Updating an Amazon ECS service using the console in the Amazon ECS Developer Guide. - 
                    For API details, see UpdateService in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use update-task-protection.
- Amazon CLI
- 
             
                    Example 1: Enable task protection for ECS tasks The following update-task-protectionprotects your ECS task from termination during scale-in from Deployments or Service AutoScaling. You can specify custom expiration period for task protection from 1 up to 2,880 minutes (48 hours). If you do not specify expiration period, enabling task protection default time is 2 hours.aws ecs update-task-protection \ --clusterECS-project-update-cluster\ --tasksc43ed3b1331041f289316f958adb6a24\ --protection-enabled \ --expires-in-minutes300Output: { "protectedTasks": [ { "taskArn": "arn:aws:ecs:us-west-2:123456789012:task/c43ed3b1331041f289316f958adb6a24", "protectionEnabled": true, "expirationDate": "2024-09-14T19:53:36.687000-05:00" } ], "failures": [] }Example 2: Disable task protection for ECS tasks The following update-task-protectiondisables the tasks protected from scale in from Deployments or Service AutoScaling.aws ecs update-task-protection \ --clusterECS-project-update-cluster\ --tasksc43ed3b1331041f289316f958adb6a24\ --no-protection-enabledOutput: { "protectedTasks": [ { "taskArn": "arn:aws:ecs:us-west-2:123456789012:task/c43ed3b1331041f289316f958adb6a24", "protectionEnabled": false } ], "failures": [] }For more formation on task protection, see Protect your Amazon ECS tasks from being terminated by scale-in events in the Amazon ECS Developer Guide. - 
                    For API details, see UpdateTaskProtection in Amazon CLI Command Reference. 
 
- 
                    
The following code example shows how to use update-task-set.
- Amazon CLI
- 
             
                    To update a task set The following update-task-setexample updates a task set to adjust the scale.aws ecs update-task-set \ --clusterMyCluster\ --serviceMyService\ --task-setarn:aws:ecs:us-west-2:123456789012:task-set/MyCluster/MyService/ecs-svc/1234567890123456789\ --scalevalue=50,unit=PERCENTOutput: { "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/sample-fargate:2", "computedDesiredCount": 0, "pendingCount": 0, "runningCount": 0, "createdAt": 1557128360.711, "updatedAt": 1557129279.914, "launchType": "EC2", "networkConfiguration": { "awsvpcConfiguration": { "subnets": [ "subnet-12344321" ], "securityGroups": [ "sg-12344321" ], "assignPublicIp": "DISABLED" } }, "loadBalancers": [], "serviceRegistries": [], "scale": { "value": 50.0, "unit": "PERCENT" }, "stabilityStatus": "STABILIZING", "stabilityStatusAt": 1557129279.914 } }- 
                    For API details, see UpdateTaskSet in Amazon CLI Command Reference. 
 
-