Seleziona le tue preferenze relative ai cookie

Utilizziamo cookie essenziali e strumenti simili necessari per fornire il nostro sito e i nostri servizi. Utilizziamo i cookie prestazionali per raccogliere statistiche anonime in modo da poter capire come i clienti utilizzano il nostro sito e apportare miglioramenti. I cookie essenziali non possono essere disattivati, ma puoi fare clic su \"Personalizza\" o \"Rifiuta\" per rifiutare i cookie prestazionali.

Se sei d'accordo, AWS e le terze parti approvate utilizzeranno i cookie anche per fornire utili funzionalità del sito, ricordare le tue preferenze e visualizzare contenuti pertinenti, inclusa la pubblicità pertinente. Per continuare senza accettare questi cookie, fai clic su \"Continua\" o \"Rifiuta\". Per effettuare scelte più dettagliate o saperne di più, fai clic su \"Personalizza\".

Esempi di utilizzo di Amazon ECS AWS CLI

Modalità Focus
Esempi di utilizzo di Amazon ECS AWS CLI - AWS Command Line Interface

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

I seguenti esempi di codice mostrano come eseguire azioni e implementare scenari comuni utilizzando Amazon ECS. AWS Command Line Interface

Le operazioni sono estratti di codice da programmi più grandi e devono essere eseguite nel contesto. Sebbene le operazioni mostrino come richiamare le singole funzioni del servizio, è possibile visualizzarle contestualizzate negli scenari correlati.

Ogni esempio include un collegamento al codice sorgente completo, dove puoi trovare istruzioni su come configurare ed eseguire il codice nel contesto.

Argomenti

Operazioni

Il seguente esempio di codice mostra come utilizzarecapacity-provider-update.

AWS CLI

Aggiornare il provider di capacità in un cluster ECS

L'update-capacity-provideresempio seguente mostra come modificare i parametri del fornitore di capacità in un cluster ECS.

aws ecs update-capacity-provider \ --name Infra-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": [] } }

Per ulteriori informazioni su Capacity Provider, consulta i provider di capacità di Amazon ECS per il tipo di EC2 lancio nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarecapacity-provider-update.

AWS CLI

Aggiornare il provider di capacità in un cluster ECS

L'update-capacity-provideresempio seguente mostra come modificare i parametri del fornitore di capacità in un cluster ECS.

aws ecs update-capacity-provider \ --name Infra-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": [] } }

Per ulteriori informazioni su Capacity Provider, consulta i provider di capacità di Amazon ECS per il tipo di EC2 lancio nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarecreate-capacity-provider.

AWS CLI

Per creare un provider di capacità

L' create-capacity-provideresempio seguente crea un provider di capacità che utilizza un gruppo Auto Scaling denominato MyASG, ha la scalabilità gestita e la protezione gestita delle terminazioni abilitate. Questa configurazione viene utilizzata per il ridimensionamento automatico del cluster Amazon ECS.

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

Per ulteriori informazioni, consulta Amazon ECS cluster auto scaling nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarecreate-capacity-provider.

AWS CLI

Per creare un provider di capacità

L' create-capacity-provideresempio seguente crea un provider di capacità che utilizza un gruppo Auto Scaling denominato MyASG, ha la scalabilità gestita e la protezione gestita delle terminazioni abilitate. Questa configurazione viene utilizzata per il ridimensionamento automatico del cluster Amazon ECS.

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

Per ulteriori informazioni, consulta Amazon ECS cluster auto scaling nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarecreate-cluster.

AWS CLI

Esempio 1: per creare un nuovo cluster

L'create-clusteresempio seguente crea un cluster denominato MyCluster e abilita CloudWatch Container Insights con una migliore osservabilità.

aws ecs create-cluster \ --cluster-name MyCluster \ --settings name=containerInsights,value=enhanced

Output:

{ "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": [] } }

Per ulteriori informazioni, consulta Creating a Cluster nella Amazon ECS Developer Guide.

Esempio 2: creare un nuovo cluster utilizzando fornitori di capacità

L'create-clusteresempio seguente crea un cluster e vi associa due fornitori di capacità esistenti. Il create-capacity-provider comando viene utilizzato per creare un provider di capacità. La specificazione di una strategia predefinita per un provider di capacità è facoltativa, ma consigliata. In questo esempio, creiamo un cluster denominato MyCluster e ad esso associamo i MyCapacityProvider1 fornitori di MyCapacityProvider2 capacità. Viene specificata una strategia predefinita per i fornitori di capacità che distribuisce le attività in modo uniforme tra entrambi i fornitori di capacità.

aws ecs create-cluster \ --cluster-name MyCluster \ --capacity-providers MyCapacityProvider1 MyCapacityProvider2 \ --default-capacity-provider-strategy capacityProvider=MyCapacityProvider1,weight=1 capacityProvider=MyCapacityProvider2,weight=1

Output:

{ "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" } }

Per ulteriori informazioni, consulta Cluster Capacity Provider nella Amazon ECS Developer Guide.

Esempio 3: creare un nuovo cluster con più tag

L'create-clusteresempio seguente crea un cluster con più tag. Per ulteriori informazioni sull'aggiunta di tag utilizzando la sintassi abbreviata, consulta Uso della sintassi abbreviata con l'interfaccia a AWS riga di comando nella Guida per l'utente della CLI.AWS

aws ecs create-cluster \ --cluster-name MyCluster \ --tags key=key1,value=value1 key=key2,value=value2

Output:

{ "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" } ] } }

Per ulteriori informazioni, consulta Creating a Cluster nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarecreate-cluster.

AWS CLI

Esempio 1: per creare un nuovo cluster

L'create-clusteresempio seguente crea un cluster denominato MyCluster e abilita CloudWatch Container Insights con una migliore osservabilità.

aws ecs create-cluster \ --cluster-name MyCluster \ --settings name=containerInsights,value=enhanced

Output:

{ "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": [] } }

Per ulteriori informazioni, consulta Creating a Cluster nella Amazon ECS Developer Guide.

Esempio 2: creare un nuovo cluster utilizzando fornitori di capacità

L'create-clusteresempio seguente crea un cluster e vi associa due fornitori di capacità esistenti. Il create-capacity-provider comando viene utilizzato per creare un provider di capacità. La specificazione di una strategia predefinita per un provider di capacità è facoltativa, ma consigliata. In questo esempio, creiamo un cluster denominato MyCluster e ad esso associamo i MyCapacityProvider1 fornitori di MyCapacityProvider2 capacità. Viene specificata una strategia predefinita per i fornitori di capacità che distribuisce le attività in modo uniforme tra entrambi i fornitori di capacità.

aws ecs create-cluster \ --cluster-name MyCluster \ --capacity-providers MyCapacityProvider1 MyCapacityProvider2 \ --default-capacity-provider-strategy capacityProvider=MyCapacityProvider1,weight=1 capacityProvider=MyCapacityProvider2,weight=1

Output:

{ "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" } }

Per ulteriori informazioni, consulta Cluster Capacity Provider nella Amazon ECS Developer Guide.

Esempio 3: creare un nuovo cluster con più tag

L'create-clusteresempio seguente crea un cluster con più tag. Per ulteriori informazioni sull'aggiunta di tag utilizzando la sintassi abbreviata, consulta Uso della sintassi abbreviata con l'interfaccia a AWS riga di comando nella Guida per l'utente della CLI.AWS

aws ecs create-cluster \ --cluster-name MyCluster \ --tags key=key1,value=value1 key=key2,value=value2

Output:

{ "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" } ] } }

Per ulteriori informazioni, consulta Creating a Cluster nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarecreate-service.

AWS CLI

Esempio 1: creare un servizio con un'attività Fargate

L'create-serviceesempio seguente mostra come creare un servizio utilizzando un'attività Fargate.

aws ecs create-service \ --cluster MyCluster \ --service-name MyService \ --task-definition sample-fargate:1 \ --desired-count 2 \ --launch-type FARGATE \ --platform-version LATEST \ --network-configuration "awsvpcConfiguration={subnets=[subnet-12344321],securityGroups=[sg-12344321],assignPublicIp=ENABLED}" \ --tags key=key1,value=value1 key=key2,value=value2 key=key3,value=value3

Output:

{ "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" } }

Esempio 2: creare un servizio utilizzando il tipo di EC2 avvio

L'create-serviceesempio seguente mostra come creare un servizio chiamato ecs-simple-service con un'attività che utilizza il tipo di EC2 avvio. Il servizio utilizza la definizione dell'sleep360attività e mantiene 1 istanza dell'attività.

aws ecs create-service \ --cluster MyCluster \ --service-name ecs-simple-service \ --task-definition sleep360:2 \ --desired-count 1

Output:

{ "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" } }

Esempio 3: creare un servizio che utilizza un controller di distribuzione esterno

L'create-serviceesempio seguente crea un servizio che utilizza un controller di distribuzione esterno.

aws ecs create-service \ --cluster MyCluster \ --service-name MyService \ --deployment-controller type=EXTERNAL \ --desired-count 1

Output:

{ "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" } }

Esempio 4: creare un nuovo servizio basato su un sistema di bilanciamento del carico

L'create-serviceesempio seguente mostra come creare un servizio basato su un sistema di bilanciamento del carico. È necessario disporre di un sistema di bilanciamento del carico configurato nella stessa regione dell'istanza del contenitore. Questo esempio utilizza l'--cli-input-jsonopzione e un file di input JSON chiamato ecs-simple-service-elb.json con il seguente contenuto:

{ "serviceName": "ecs-simple-service-elb", "taskDefinition": "ecs-demo", "loadBalancers": [ { "loadBalancerName": "EC2Contai-EcsElast-123456789012", "containerName": "simple-demo", "containerPort": 80 } ], "desiredCount": 10, "role": "ecsServiceRole" }

Comando:

aws ecs create-service \ --cluster MyCluster \ --service-name ecs-simple-service-elb \ --cli-input-json file://ecs-simple-service-elb.json

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 } }

Per ulteriori informazioni, consulta Creating a Service nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarecreate-service.

AWS CLI

Esempio 1: creare un servizio con un'attività Fargate

L'create-serviceesempio seguente mostra come creare un servizio utilizzando un'attività Fargate.

aws ecs create-service \ --cluster MyCluster \ --service-name MyService \ --task-definition sample-fargate:1 \ --desired-count 2 \ --launch-type FARGATE \ --platform-version LATEST \ --network-configuration "awsvpcConfiguration={subnets=[subnet-12344321],securityGroups=[sg-12344321],assignPublicIp=ENABLED}" \ --tags key=key1,value=value1 key=key2,value=value2 key=key3,value=value3

Output:

{ "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" } }

Esempio 2: creare un servizio utilizzando il tipo di EC2 avvio

L'create-serviceesempio seguente mostra come creare un servizio chiamato ecs-simple-service con un'attività che utilizza il tipo di EC2 avvio. Il servizio utilizza la definizione dell'sleep360attività e mantiene 1 istanza dell'attività.

aws ecs create-service \ --cluster MyCluster \ --service-name ecs-simple-service \ --task-definition sleep360:2 \ --desired-count 1

Output:

{ "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" } }

Esempio 3: creare un servizio che utilizza un controller di distribuzione esterno

L'create-serviceesempio seguente crea un servizio che utilizza un controller di distribuzione esterno.

aws ecs create-service \ --cluster MyCluster \ --service-name MyService \ --deployment-controller type=EXTERNAL \ --desired-count 1

Output:

{ "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" } }

Esempio 4: creare un nuovo servizio basato su un sistema di bilanciamento del carico

L'create-serviceesempio seguente mostra come creare un servizio basato su un sistema di bilanciamento del carico. È necessario disporre di un sistema di bilanciamento del carico configurato nella stessa regione dell'istanza del contenitore. Questo esempio utilizza l'--cli-input-jsonopzione e un file di input JSON chiamato ecs-simple-service-elb.json con il seguente contenuto:

{ "serviceName": "ecs-simple-service-elb", "taskDefinition": "ecs-demo", "loadBalancers": [ { "loadBalancerName": "EC2Contai-EcsElast-123456789012", "containerName": "simple-demo", "containerPort": 80 } ], "desiredCount": 10, "role": "ecsServiceRole" }

Comando:

aws ecs create-service \ --cluster MyCluster \ --service-name ecs-simple-service-elb \ --cli-input-json file://ecs-simple-service-elb.json

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 } }

Per ulteriori informazioni, consulta Creating a Service nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarecreate-task-set.

AWS CLI

Per creare un set di attività

L'create-task-setesempio seguente crea un set di attività in un servizio che utilizza un controller di distribuzione esterno.

aws ecs create-task-set \ --cluster MyCluster \ --service MyService \ --task-definition MyTaskDefinition: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 } }
  • Per i dettagli sull'API, vedere CreateTaskSetin AWS CLI Command Reference.

Il seguente esempio di codice mostra come utilizzarecreate-task-set.

AWS CLI

Per creare un set di attività

L'create-task-setesempio seguente crea un set di attività in un servizio che utilizza un controller di distribuzione esterno.

aws ecs create-task-set \ --cluster MyCluster \ --service MyService \ --task-definition MyTaskDefinition: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 } }
  • Per i dettagli sull'API, vedere CreateTaskSetin AWS CLI Command Reference.

Il seguente esempio di codice mostra come utilizzaredelete-account-setting.

AWS CLI

Per eliminare le impostazioni dell'account per uno specifico utente o ruolo IAM

L'esempio seguente delete-account-setting elimina le impostazioni dell'account per lo specifico utente IAM o ruolo IAM.

aws ecs delete-account-setting \ --name serviceLongArnFormat \ --principal-arn arn:aws:iam::123456789012:user/MyUser

Output:

{ "setting": { "name": "serviceLongArnFormat", "value": "enabled", "principalArn": "arn:aws:iam::123456789012:user/MyUser" } }

Per ulteriori informazioni, consulta Amazon Resource Names (ARNs) e IDs la Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzaredelete-account-setting.

AWS CLI

Per eliminare le impostazioni dell'account per uno specifico utente o ruolo IAM

L'esempio seguente delete-account-setting elimina le impostazioni dell'account per lo specifico utente IAM o ruolo IAM.

aws ecs delete-account-setting \ --name serviceLongArnFormat \ --principal-arn arn:aws:iam::123456789012:user/MyUser

Output:

{ "setting": { "name": "serviceLongArnFormat", "value": "enabled", "principalArn": "arn:aws:iam::123456789012:user/MyUser" } }

Per ulteriori informazioni, consulta Amazon Resource Names (ARNs) e IDs la Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzaredelete-attributes.

AWS CLI

Per eliminare uno o più attributi personalizzati da una risorsa Amazon ECS

Quanto segue delete-attributes elimina un attributo con lo stesso nome stack da un'istanza del contenitore.

aws ecs delete-attributes \ --attributes name=stack,targetId=arn:aws:ecs:us-west-2:130757420319:container-instance/1c3be8ed-df30-47b4-8f1e-6e68ebd01f34

Output:

{ "attributes": [ { "name": "stack", "targetId": "arn:aws:ecs:us-west-2:130757420319:container-instance/1c3be8ed-df30-47b4-8f1e-6e68ebd01f34", "value": "production" } ] }

Il seguente esempio di codice mostra come utilizzaredelete-attributes.

AWS CLI

Per eliminare uno o più attributi personalizzati da una risorsa Amazon ECS

Quanto segue delete-attributes elimina un attributo con lo stesso nome stack da un'istanza del contenitore.

aws ecs delete-attributes \ --attributes name=stack,targetId=arn:aws:ecs:us-west-2:130757420319:container-instance/1c3be8ed-df30-47b4-8f1e-6e68ebd01f34

Output:

{ "attributes": [ { "name": "stack", "targetId": "arn:aws:ecs:us-west-2:130757420319:container-instance/1c3be8ed-df30-47b4-8f1e-6e68ebd01f34", "value": "production" } ] }

Il seguente esempio di codice mostra come utilizzaredelete-capacity-provider.

AWS CLI

Esempio 1: eliminare un provider di capacità utilizzando Amazon Resource Name (ARN)

L'delete-capacity-provideresempio seguente elimina un provider di capacità specificando l'Amazon Resource Name (ARN) del fornitore di capacità. L'ARN e lo stato dell'eliminazione del provider di capacità possono essere recuperati utilizzando il comando. describe-capacity-providers

aws ecs delete-capacity-provider \ --capacity-provider arn:aws:ecs:us-west-2:123456789012:capacity-provider/ExampleCapacityProvider

Output:

{ "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": [] } }

Per ulteriori informazioni, consulta Cluster Capacity Provider nella Amazon ECS Developer Guide.

Esempio 2: eliminare un provider di capacità utilizzando il nome

L'delete-capacity-provideresempio seguente elimina un fornitore di capacità specificando il nome breve del fornitore di capacità. Il nome breve e lo stato dell'eliminazione del provider di capacità possono essere recuperati utilizzando il comando. describe-capacity-providers

aws ecs delete-capacity-provider \ --capacity-provider ExampleCapacityProvider

Output:

{ "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": [] } }

Per ulteriori informazioni, consulta Cluster Capacity Provider nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzaredelete-capacity-provider.

AWS CLI

Esempio 1: eliminare un provider di capacità utilizzando Amazon Resource Name (ARN)

L'delete-capacity-provideresempio seguente elimina un provider di capacità specificando l'Amazon Resource Name (ARN) del fornitore di capacità. L'ARN e lo stato dell'eliminazione del provider di capacità possono essere recuperati utilizzando il comando. describe-capacity-providers

aws ecs delete-capacity-provider \ --capacity-provider arn:aws:ecs:us-west-2:123456789012:capacity-provider/ExampleCapacityProvider

Output:

{ "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": [] } }

Per ulteriori informazioni, consulta Cluster Capacity Provider nella Amazon ECS Developer Guide.

Esempio 2: eliminare un provider di capacità utilizzando il nome

L'delete-capacity-provideresempio seguente elimina un fornitore di capacità specificando il nome breve del fornitore di capacità. Il nome breve e lo stato dell'eliminazione del provider di capacità possono essere recuperati utilizzando il comando. describe-capacity-providers

aws ecs delete-capacity-provider \ --capacity-provider ExampleCapacityProvider

Output:

{ "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": [] } }

Per ulteriori informazioni, consulta Cluster Capacity Provider nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzaredelete-cluster.

AWS CLI

Per eliminare un cluster vuoto

L'delete-clusteresempio seguente elimina il cluster vuoto specificato.

aws ecs delete-cluster --cluster MyCluster

Output:

{ "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": [] } }

Per ulteriori informazioni, consulta Eliminazione di un cluster nella Amazon ECS Developer Guide.

  • Per i dettagli sull'API, consulta AWS CLI Command DeleteClusterReference.

Il seguente esempio di codice mostra come utilizzaredelete-cluster.

AWS CLI

Per eliminare un cluster vuoto

L'delete-clusteresempio seguente elimina il cluster vuoto specificato.

aws ecs delete-cluster --cluster MyCluster

Output:

{ "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": [] } }

Per ulteriori informazioni, consulta Eliminazione di un cluster nella Amazon ECS Developer Guide.

  • Per i dettagli sull'API, consulta AWS CLI Command DeleteClusterReference.

Il seguente esempio di codice mostra come utilizzaredelete-service.

AWS CLI

Per eliminare un servizio

L'ecs delete-serviceesempio seguente elimina il servizio specificato da un cluster. È possibile includere il --force parametro per eliminare un servizio anche se non è stato ridimensionato a zero attività.

aws ecs delete-service --cluster MyCluster --service MyService1 --force

Per ulteriori informazioni, consulta Eliminazione di un servizio nella Amazon ECS Developer Guide.

  • Per i dettagli sull'API, consulta AWS CLI Command DeleteServiceReference.

Il seguente esempio di codice mostra come utilizzaredelete-service.

AWS CLI

Per eliminare un servizio

L'ecs delete-serviceesempio seguente elimina il servizio specificato da un cluster. È possibile includere il --force parametro per eliminare un servizio anche se non è stato ridimensionato a zero attività.

aws ecs delete-service --cluster MyCluster --service MyService1 --force

Per ulteriori informazioni, consulta Eliminazione di un servizio nella Amazon ECS Developer Guide.

  • Per i dettagli sull'API, consulta AWS CLI Command DeleteServiceReference.

Il seguente esempio di codice mostra come utilizzaredelete-task-definitions.

AWS CLI

Per eliminare una definizione di attività

L'delete-task-definitionsesempio seguente elimina una definizione di attività INACTIVE.

aws ecs delete-task-definitions \ --task-definition curltest:1

Output:

{ "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": [] }

Per ulteriori informazioni, consulta Amazon ECS Task Definitions nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzaredelete-task-definitions.

AWS CLI

Per eliminare una definizione di attività

L'delete-task-definitionsesempio seguente elimina una definizione di attività INACTIVE.

aws ecs delete-task-definitions \ --task-definition curltest:1

Output:

{ "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": [] }

Per ulteriori informazioni, consulta Amazon ECS Task Definitions nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzaredelete-task-set.

AWS CLI

Per eliminare un set di attività

L'delete-task-setesempio seguente mostra come eliminare un set di attività. È possibile includere il --force parametro per eliminare un set di attività anche se non è stato ridimensionato a zero.

aws ecs delete-task-set \ --cluster MyCluster \ --service MyService \ --task-set arn:aws:ecs:us-west-2:123456789012:task-set/MyCluster/MyService/ecs-svc/1234567890123456789 \ --force

Output:

{ "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 } }

Il seguente esempio di codice mostra come utilizzaredelete-task-set.

AWS CLI

Per eliminare un set di attività

L'delete-task-setesempio seguente mostra come eliminare un set di attività. È possibile includere il --force parametro per eliminare un set di attività anche se non è stato ridimensionato a zero.

aws ecs delete-task-set \ --cluster MyCluster \ --service MyService \ --task-set arn:aws:ecs:us-west-2:123456789012:task-set/MyCluster/MyService/ecs-svc/1234567890123456789 \ --force

Output:

{ "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 } }

Il seguente esempio di codice mostra come utilizzarederegister-container-instance.

AWS CLI

Per annullare la registrazione di un'istanza di contenitore da un cluster

L'deregister-container-instanceesempio seguente annulla la registrazione di un'istanza di contenitore dal cluster specificato. Se ci sono ancora attività in esecuzione nell'istanza del contenitore, è necessario interromperle prima di annullare la registrazione oppure utilizzare l'opzione. --force

aws ecs deregister-container-instance \ --cluster arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster \ --container-instance arn:aws:ecs:us-west-2:123456789012:container-instance/a1b2c3d4-5678-90ab-cdef-11111EXAMPLE \ --force

Output:

{ "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" } }

Per ulteriori informazioni, consulta Annullare la registrazione di un'istanza di container nella ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarederegister-container-instance.

AWS CLI

Per annullare la registrazione di un'istanza di contenitore da un cluster

L'deregister-container-instanceesempio seguente annulla la registrazione di un'istanza di contenitore dal cluster specificato. Se ci sono ancora attività in esecuzione nell'istanza del contenitore, è necessario interromperle prima di annullare la registrazione oppure utilizzare l'opzione. --force

aws ecs deregister-container-instance \ --cluster arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster \ --container-instance arn:aws:ecs:us-west-2:123456789012:container-instance/a1b2c3d4-5678-90ab-cdef-11111EXAMPLE \ --force

Output:

{ "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" } }

Per ulteriori informazioni, consulta Annullare la registrazione di un'istanza di container nella ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarederegister-task-definition.

AWS CLI

Per annullare la registrazione di una definizione di attività

L'deregister-task-definitionesempio seguente annulla la registrazione della prima revisione della definizione dell'curlerattività nell'area predefinita.

aws ecs deregister-task-definition --task-definition curler:1

Si noti che nell'output risultante, lo stato della definizione dell'attività mostra: 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 } }

Per ulteriori informazioni, consulta Amazon ECS Task Definitions nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarederegister-task-definition.

AWS CLI

Per annullare la registrazione di una definizione di attività

L'deregister-task-definitionesempio seguente annulla la registrazione della prima revisione della definizione dell'curlerattività nell'area predefinita.

aws ecs deregister-task-definition --task-definition curler:1

Si noti che nell'output risultante, lo stato della definizione dell'attività mostra: 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 } }

Per ulteriori informazioni, consulta Amazon ECS Task Definitions nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzaredescribe-capacity-providers.

AWS CLI

Esempio 1: Per descrivere tutti i fornitori di capacità

L'describe-capacity-providersesempio seguente recupera i dettagli su tutti i fornitori di capacità.

aws ecs describe-capacity-providers

Output:

{ "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": [] } ] }

Per ulteriori informazioni, consulta Cluster Capacity Provider nella Amazon ECS Developer Guide.

Esempio 2: Per descrivere uno specifico fornitore di capacità

L'describe-capacity-providersesempio seguente recupera i dettagli su un fornitore di capacità specifico. L'utilizzo del --include TAGS parametro aggiungerà all'output i tag associati al fornitore di capacità.

aws ecs describe-capacity-providers \ --capacity-providers MyCapacityProvider \ --include TAGS

Output:

{ "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" } ] } ] }

Per ulteriori informazioni, consulta Cluster Capacity Provider nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzaredescribe-capacity-providers.

AWS CLI

Esempio 1: Per descrivere tutti i fornitori di capacità

L'describe-capacity-providersesempio seguente recupera i dettagli su tutti i fornitori di capacità.

aws ecs describe-capacity-providers

Output:

{ "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": [] } ] }

Per ulteriori informazioni, consulta Cluster Capacity Provider nella Amazon ECS Developer Guide.

Esempio 2: Per descrivere uno specifico fornitore di capacità

L'describe-capacity-providersesempio seguente recupera i dettagli su un fornitore di capacità specifico. L'utilizzo del --include TAGS parametro aggiungerà all'output i tag associati al fornitore di capacità.

aws ecs describe-capacity-providers \ --capacity-providers MyCapacityProvider \ --include TAGS

Output:

{ "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" } ] } ] }

Per ulteriori informazioni, consulta Cluster Capacity Provider nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzaredescribe-clusters.

AWS CLI

Esempio 1: Per descrivere un cluster

L'describe-clustersesempio seguente recupera i dettagli sul cluster specificato.

aws ecs describe-clusters \ --cluster default

Output:

{ "clusters": [ { "status": "ACTIVE", "clusterName": "default", "registeredContainerInstancesCount": 0, "pendingTasksCount": 0, "runningTasksCount": 0, "activeServicesCount": 1, "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/default" } ], "failures": [] }

Per ulteriori informazioni, consulta Amazon ECS Clusters nella Amazon ECS Developer Guide.

Esempio 2: descrivere un cluster con l'opzione attachment

L'describe-clustersesempio seguente specifica l'opzione ATTACHMENTS. Recupera i dettagli sul cluster specificato e un elenco di risorse collegate al cluster sotto forma di allegati. Quando si utilizza un provider di capacità con un cluster, le risorse, sia che si tratti di AutoScaling piani o politiche di scalabilità, saranno rappresentate come asp o as_policy ATTACHMENTS.

aws ecs describe-clusters \ --include ATTACHMENTS \ --clusters sampleCluster

Output:

{ "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": [] }

Per ulteriori informazioni, consulta Amazon ECS Clusters nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzaredescribe-clusters.

AWS CLI

Esempio 1: Per descrivere un cluster

L'describe-clustersesempio seguente recupera i dettagli sul cluster specificato.

aws ecs describe-clusters \ --cluster default

Output:

{ "clusters": [ { "status": "ACTIVE", "clusterName": "default", "registeredContainerInstancesCount": 0, "pendingTasksCount": 0, "runningTasksCount": 0, "activeServicesCount": 1, "clusterArn": "arn:aws:ecs:us-west-2:123456789012:cluster/default" } ], "failures": [] }

Per ulteriori informazioni, consulta Amazon ECS Clusters nella Amazon ECS Developer Guide.

Esempio 2: descrivere un cluster con l'opzione attachment

L'describe-clustersesempio seguente specifica l'opzione ATTACHMENTS. Recupera i dettagli sul cluster specificato e un elenco di risorse collegate al cluster sotto forma di allegati. Quando si utilizza un provider di capacità con un cluster, le risorse, sia che si tratti di AutoScaling piani o politiche di scalabilità, saranno rappresentate come asp o as_policy ATTACHMENTS.

aws ecs describe-clusters \ --include ATTACHMENTS \ --clusters sampleCluster

Output:

{ "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": [] }

Per ulteriori informazioni, consulta Amazon ECS Clusters nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzaredescribe-container-instances.

AWS CLI

Per descrivere l'istanza del contenitore

L'describe-container-instancesesempio seguente recupera i dettagli di un'istanza di contenitore nel update cluster, utilizzando l'UUID dell'istanza del contenitore come identificatore.

aws ecs describe-container-instances \ --cluster update \ --container-instances a1b2c3d4-5678-90ab-cdef-11111EXAMPLE

Output:

{ "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" } } ] }

Per ulteriori informazioni, consulta Amazon ECS Container Instances nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzaredescribe-container-instances.

AWS CLI

Per descrivere l'istanza del contenitore

L'describe-container-instancesesempio seguente recupera i dettagli di un'istanza di contenitore nel update cluster, utilizzando l'UUID dell'istanza del contenitore come identificatore.

aws ecs describe-container-instances \ --cluster update \ --container-instances a1b2c3d4-5678-90ab-cdef-11111EXAMPLE

Output:

{ "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" } } ] }

Per ulteriori informazioni, consulta Amazon ECS Container Instances nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzaredescribe-service-deployments.

AWS CLI

Per descrivere i dettagli della distribuzione del servizio

L'describe-service-deploymentsesempio seguente restituisce i dettagli di distribuzione del servizio per la distribuzione del servizio con l'ARNarn:aws:ecs:us-east-1:123456789012:service-deployment/example-cluster/example-service/ejGvqq2ilnbKT9qj0vLJe.

aws ecs describe-service-deployments \ --service-deployment-arn arn:aws:ecs:us-east-1:123456789012:service-deployment/example-cluster/example-service/ejGvqq2ilnbKT9qj0vLJe

Output:

{ "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": [] }

Per ulteriori informazioni, consulta Visualizza la cronologia dei servizi utilizzando le distribuzioni di servizi Amazon ECS nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzaredescribe-service-deployments.

AWS CLI

Per descrivere i dettagli della distribuzione del servizio

L'describe-service-deploymentsesempio seguente restituisce i dettagli di distribuzione del servizio per la distribuzione del servizio con l'ARNarn:aws:ecs:us-east-1:123456789012:service-deployment/example-cluster/example-service/ejGvqq2ilnbKT9qj0vLJe.

aws ecs describe-service-deployments \ --service-deployment-arn arn:aws:ecs:us-east-1:123456789012:service-deployment/example-cluster/example-service/ejGvqq2ilnbKT9qj0vLJe

Output:

{ "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": [] }

Per ulteriori informazioni, consulta Visualizza la cronologia dei servizi utilizzando le distribuzioni di servizi Amazon ECS nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzaredescribe-service-revisions.

AWS CLI

Per descrivere i dettagli della revisione del servizio

L'describe-service-revisionsesempio seguente restituisce i dettagli di revisione del servizio per la revisione del servizio con l'ARN. arn:aws:ecs:us-east-1:123456789012:service-revision/example-cluster/example-service/1485800978477494678

aws ecs describe-service-revisions \ --service-revision-arns arn:aws:ecs:us-east-1:123456789012:service-revision/example-cluster/example-service/1485800978477494678

Output:

{ "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": [] }

Per ulteriori informazioni, consulta le revisioni dei servizi Amazon ECS nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzaredescribe-service-revisions.

AWS CLI

Per descrivere i dettagli della revisione del servizio

L'describe-service-revisionsesempio seguente restituisce i dettagli di revisione del servizio per la revisione del servizio con l'ARN. arn:aws:ecs:us-east-1:123456789012:service-revision/example-cluster/example-service/1485800978477494678

aws ecs describe-service-revisions \ --service-revision-arns arn:aws:ecs:us-east-1:123456789012:service-revision/example-cluster/example-service/1485800978477494678

Output:

{ "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": [] }

Per ulteriori informazioni, consulta le revisioni dei servizi Amazon ECS nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzaredescribe-services.

AWS CLI

Per descrivere un servizio

L'describe-servicesesempio seguente recupera i dettagli del my-http-service servizio nel cluster predefinito.

aws ecs describe-services --services my-http-service

Output:

{ "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": [] }

Per ulteriori informazioni, consulta la sezione Servizi nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzaredescribe-services.

AWS CLI

Per descrivere un servizio

L'describe-servicesesempio seguente recupera i dettagli del my-http-service servizio nel cluster predefinito.

aws ecs describe-services --services my-http-service

Output:

{ "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": [] }

Per ulteriori informazioni, consulta la sezione Servizi nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzaredescribe-task-definition.

AWS CLI

Per descrivere una definizione di attività

L'describe-task-definitionesempio seguente recupera i dettagli di una definizione di attività.

aws ecs describe-task-definition \ --task-definition hello_world:8

Output:

{ "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": [] }

Per ulteriori informazioni, consulta Amazon ECS Task Definitions nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzaredescribe-task-definition.

AWS CLI

Per descrivere una definizione di attività

L'describe-task-definitionesempio seguente recupera i dettagli di una definizione di attività.

aws ecs describe-task-definition \ --task-definition hello_world:8

Output:

{ "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": [] }

Per ulteriori informazioni, consulta Amazon ECS Task Definitions nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzaredescribe-task-sets.

AWS CLI

Per descrivere un set di attività

L'describe-task-setsesempio seguente descrive un set di attività in un servizio che utilizza un deployer esterno.

aws ecs describe-task-sets \ --cluster MyCluster \ --service MyService \ --task-sets arn:aws:ecs:us-west-2:123456789012:task-set/MyCluster/MyService/ecs-svc/1234567890123456789

Output:

{ "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": [] }

Il seguente esempio di codice mostra come utilizzaredescribe-task-sets.

AWS CLI

Per descrivere un set di attività

L'describe-task-setsesempio seguente descrive un set di attività in un servizio che utilizza un deployer esterno.

aws ecs describe-task-sets \ --cluster MyCluster \ --service MyService \ --task-sets arn:aws:ecs:us-west-2:123456789012:task-set/MyCluster/MyService/ecs-svc/1234567890123456789

Output:

{ "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": [] }

Il seguente esempio di codice mostra come utilizzaredescribe-tasks.

AWS CLI

Esempio 1: per descrivere una singola attività

L'describe-tasksesempio seguente recupera i dettagli di un'attività in un cluster. È possibile specificare l'attività utilizzando l'ID o l'ARN completo dell'attività. Questo esempio utilizza l'ARN completo dell'attività.

aws ecs describe-tasks \ --cluster MyCluster \ --tasks arn:aws:ecs:us-east-1:123456789012:task/MyCluster/4d590253bb114126b7afa7b58EXAMPLE

Output:

{ "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": [] }

Per ulteriori informazioni, consulta Amazon ECS Task Definitions nella Amazon ECS Developer Guide.

Esempio 2: descrivere più attività

L'describe-tasksesempio seguente recupera i dettagli di più attività in un cluster. È possibile specificare l'attività utilizzando l'ID o l'ARN completo dell'attività. In questo esempio viene utilizzata la IDs totalità delle attività.

aws ecs describe-tasks \ --cluster MyCluster \ --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": [] }

Per ulteriori informazioni, consulta Amazon ECS Task Definitions nella Amazon ECS Developer Guide.

  • Per i dettagli sull'API, consulta AWS CLI Command DescribeTasksReference.

Il seguente esempio di codice mostra come utilizzaredescribe-tasks.

AWS CLI

Esempio 1: per descrivere una singola attività

L'describe-tasksesempio seguente recupera i dettagli di un'attività in un cluster. È possibile specificare l'attività utilizzando l'ID o l'ARN completo dell'attività. Questo esempio utilizza l'ARN completo dell'attività.

aws ecs describe-tasks \ --cluster MyCluster \ --tasks arn:aws:ecs:us-east-1:123456789012:task/MyCluster/4d590253bb114126b7afa7b58EXAMPLE

Output:

{ "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": [] }

Per ulteriori informazioni, consulta Amazon ECS Task Definitions nella Amazon ECS Developer Guide.

Esempio 2: descrivere più attività

L'describe-tasksesempio seguente recupera i dettagli di più attività in un cluster. È possibile specificare l'attività utilizzando l'ID o l'ARN completo dell'attività. In questo esempio viene utilizzata la IDs totalità delle attività.

aws ecs describe-tasks \ --cluster MyCluster \ --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": [] }

Per ulteriori informazioni, consulta Amazon ECS Task Definitions nella Amazon ECS Developer Guide.

  • Per i dettagli sull'API, consulta AWS CLI Command DescribeTasksReference.

Il seguente esempio di codice mostra come utilizzareexecute-command.

AWS CLI

Per eseguire un interactive /bin/sh comando

L'execute-commandesempio seguente esegue un interactive /bin/sh comando su un contenitore denominato in MyContainer base a un'attività con un id diarn:aws:ecs:us-east-1:123456789012:task/MyCluster/d789e94343414c25b9f6bd59eEXAMPLE.

aws ecs execute-command \ --cluster MyCluster \ --task arn:aws:ecs:us-east-1:123456789012:task/MyCluster/d789e94343414c25b9f6bd59eEXAMPLE \ --container MyContainer \ --interactive \ --command "/bin/sh"

Questo comando non produce alcun output.

Per ulteriori informazioni, consulta Using Amazon ECS Exec for debugging nella Amazon ECS Developer Guide.

  • Per i dettagli sull'API, consulta Command Reference. ExecuteCommandAWS CLI

Il seguente esempio di codice mostra come utilizzareexecute-command.

AWS CLI

Per eseguire un interactive /bin/sh comando

L'execute-commandesempio seguente esegue un interactive /bin/sh comando su un contenitore denominato in MyContainer base a un'attività con un id diarn:aws:ecs:us-east-1:123456789012:task/MyCluster/d789e94343414c25b9f6bd59eEXAMPLE.

aws ecs execute-command \ --cluster MyCluster \ --task arn:aws:ecs:us-east-1:123456789012:task/MyCluster/d789e94343414c25b9f6bd59eEXAMPLE \ --container MyContainer \ --interactive \ --command "/bin/sh"

Questo comando non produce alcun output.

Per ulteriori informazioni, consulta Using Amazon ECS Exec for debugging nella Amazon ECS Developer Guide.

  • Per i dettagli sull'API, consulta Command Reference. ExecuteCommandAWS CLI

Il seguente esempio di codice mostra come utilizzareget-task-protection.

AWS CLI

Recupera lo stato di protezione dell'attività nel servizio ECS

Quanto segue get-task-protection fornisce lo stato di protezione delle attività ECS che appartengono al servizio Amazon ECS.

aws ecs get-task-protection \ --cluster ECS-project-update-cluster \ --tasks c43ed3b1331041f289316f958adb6a24

Output:

{ "protectedTasks": [ { "taskArn": "arn:aws:ecs:us-west-2:123456789012:task/c43ed3b1331041f289316f958adb6a24", "protectionEnabled": false } ], "failures": [] }

Per ulteriori informazioni sulla protezione delle attività, consulta Proteggi le tue attività Amazon ECS dall'interruzione a causa di eventi di scalabilità nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzareget-task-protection.

AWS CLI

Recupera lo stato di protezione dell'attività nel servizio ECS

Quanto segue get-task-protection fornisce lo stato di protezione delle attività ECS che appartengono al servizio Amazon ECS.

aws ecs get-task-protection \ --cluster ECS-project-update-cluster \ --tasks c43ed3b1331041f289316f958adb6a24

Output:

{ "protectedTasks": [ { "taskArn": "arn:aws:ecs:us-west-2:123456789012:task/c43ed3b1331041f289316f958adb6a24", "protectionEnabled": false } ], "failures": [] }

Per ulteriori informazioni sulla protezione delle attività, consulta Proteggi le tue attività Amazon ECS dall'interruzione a causa di eventi di scalabilità nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarelist-account-settings.

AWS CLI

Esempio 1: Per visualizzare le impostazioni di un account

L'list-account-settingsesempio seguente mostra le impostazioni effettive dell'account per un account.

aws ecs list-account-settings --effective-settings

Output:

{ "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" } ] }

Esempio 2: per visualizzare le impostazioni dell'account per uno specifico utente IAM o ruolo IAM

L'list-account-settingsesempio seguente mostra le impostazioni dell'account per l'utente IAM o il ruolo IAM specificato.

aws ecs list-account-settings --principal-arn arn:aws:iam::123456789012:user/MyUser

Output:

{ "settings": [ { "name": "serviceLongArnFormat", "value": "enabled", "principalArn": "arn:aws:iam::123456789012:user/MyUser" } ] }

Per ulteriori informazioni, consulta Amazon Resource Names (ARNs) e IDs la Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarelist-account-settings.

AWS CLI

Esempio 1: Per visualizzare le impostazioni di un account

L'list-account-settingsesempio seguente mostra le impostazioni effettive dell'account per un account.

aws ecs list-account-settings --effective-settings

Output:

{ "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" } ] }

Esempio 2: per visualizzare le impostazioni dell'account per uno specifico utente IAM o ruolo IAM

L'list-account-settingsesempio seguente mostra le impostazioni dell'account per l'utente IAM o il ruolo IAM specificato.

aws ecs list-account-settings --principal-arn arn:aws:iam::123456789012:user/MyUser

Output:

{ "settings": [ { "name": "serviceLongArnFormat", "value": "enabled", "principalArn": "arn:aws:iam::123456789012:user/MyUser" } ] }

Per ulteriori informazioni, consulta Amazon Resource Names (ARNs) e IDs la Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarelist-attributes.

AWS CLI

Per elencare le istanze del contenitore che contengono un attributo specifico

L'esempio seguente elenca gli attributi per le istanze di contenitore che hanno l'stack=productionattributo nel cluster predefinito.

aws ecs list-attributes \ --target-type container-instance \ --attribute-name stack \ --attribute-value production \ --cluster default

Output:

{ "attributes": [ { "name": "stack", "targetId": "arn:aws:ecs:us-west-2:130757420319:container-instance/1c3be8ed-df30-47b4-8f1e-6e68ebd01f34", "value": "production" } ] }

Per ulteriori informazioni, consulta Amazon ECS Container Agent Configuration nella Amazon ECS Developer Guide.

  • Per i dettagli sull'API, consulta AWS CLI Command ListAttributesReference.

Il seguente esempio di codice mostra come utilizzarelist-attributes.

AWS CLI

Per elencare le istanze del contenitore che contengono un attributo specifico

L'esempio seguente elenca gli attributi per le istanze di contenitore che hanno l'stack=productionattributo nel cluster predefinito.

aws ecs list-attributes \ --target-type container-instance \ --attribute-name stack \ --attribute-value production \ --cluster default

Output:

{ "attributes": [ { "name": "stack", "targetId": "arn:aws:ecs:us-west-2:130757420319:container-instance/1c3be8ed-df30-47b4-8f1e-6e68ebd01f34", "value": "production" } ] }

Per ulteriori informazioni, consulta Amazon ECS Container Agent Configuration nella Amazon ECS Developer Guide.

  • Per i dettagli sull'API, consulta AWS CLI Command ListAttributesReference.

Il seguente esempio di codice mostra come utilizzarelist-clusters.

AWS CLI

Per elencare i cluster disponibili

L'list-clustersesempio seguente elenca tutti i cluster disponibili.

aws ecs list-clusters

Output:

{ "clusterArns": [ "arn:aws:ecs:us-west-2:123456789012:cluster/MyECSCluster1", "arn:aws:ecs:us-west-2:123456789012:cluster/AnotherECSCluster" ] }

Per ulteriori informazioni, consulta Amazon ECS Clusters nella Amazon ECS Developer Guide.

  • Per i dettagli sull'API, consulta Command ListClustersReference AWS CLI .

Il seguente esempio di codice mostra come utilizzarelist-clusters.

AWS CLI

Per elencare i cluster disponibili

L'list-clustersesempio seguente elenca tutti i cluster disponibili.

aws ecs list-clusters

Output:

{ "clusterArns": [ "arn:aws:ecs:us-west-2:123456789012:cluster/MyECSCluster1", "arn:aws:ecs:us-west-2:123456789012:cluster/AnotherECSCluster" ] }

Per ulteriori informazioni, consulta Amazon ECS Clusters nella Amazon ECS Developer Guide.

  • Per i dettagli sull'API, consulta Command ListClustersReference AWS CLI .

Il seguente esempio di codice mostra come utilizzarelist-container-instances.

AWS CLI

Per elencare le istanze del contenitore in un cluster

L'list-container-instancesesempio seguente elenca tutte le istanze di container disponibili in un cluster.

aws ecs list-container-instances --cluster MyCluster

Output:

{ "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" ] }

Per ulteriori informazioni, consulta Amazon ECS Container Instances nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarelist-container-instances.

AWS CLI

Per elencare le istanze del contenitore in un cluster

L'list-container-instancesesempio seguente elenca tutte le istanze di container disponibili in un cluster.

aws ecs list-container-instances --cluster MyCluster

Output:

{ "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" ] }

Per ulteriori informazioni, consulta Amazon ECS Container Instances nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarelist-service-deployments.

AWS CLI

Per elencare le distribuzioni dei servizi

L'list-service-deploymentsesempio seguente recupera le distribuzioni dei servizi per il servizio denominato. example-service

aws ecs list-service-deployments \ --service arn:aws:ecs:us-east-1:123456789012:service/example-cluster/example-service

Output:

{ "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" } ] }

Per ulteriori informazioni, consulta Visualizza la cronologia dei servizi utilizzando le distribuzioni di servizi Amazon ECS nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarelist-service-deployments.

AWS CLI

Per elencare le distribuzioni dei servizi

L'list-service-deploymentsesempio seguente recupera le distribuzioni dei servizi per il servizio denominato. example-service

aws ecs list-service-deployments \ --service arn:aws:ecs:us-east-1:123456789012:service/example-cluster/example-service

Output:

{ "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" } ] }

Per ulteriori informazioni, consulta Visualizza la cronologia dei servizi utilizzando le distribuzioni di servizi Amazon ECS nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarelist-services-by-namespace.

AWS CLI

Per elencare i servizi in un namespace

L'list-services-by-namespaceesempio seguente elenca tutti i servizi configurati per lo spazio dei nomi specificato nella regione predefinita.

aws ecs list-services-by-namespace \ --namespace service-connect

Output:

{ "serviceArns": [ "arn:aws:ecs:us-west-2:123456789012:service/MyCluster/MyService", "arn:aws:ecs:us-west-2:123456789012:service/tutorial/service-connect-nginx-service" ] }

Per ulteriori informazioni, consulta Service Connect nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarelist-services-by-namespace.

AWS CLI

Per elencare i servizi in un namespace

L'list-services-by-namespaceesempio seguente elenca tutti i servizi configurati per lo spazio dei nomi specificato nella regione predefinita.

aws ecs list-services-by-namespace \ --namespace service-connect

Output:

{ "serviceArns": [ "arn:aws:ecs:us-west-2:123456789012:service/MyCluster/MyService", "arn:aws:ecs:us-west-2:123456789012:service/tutorial/service-connect-nginx-service" ] }

Per ulteriori informazioni, consulta Service Connect nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarelist-services.

AWS CLI

Per elencare i servizi in un cluster

L'list-servicesesempio seguente mostra come elencare i servizi in esecuzione in un cluster.

aws ecs list-services --cluster MyCluster

Output:

{ "serviceArns": [ "arn:aws:ecs:us-west-2:123456789012:service/MyCluster/MyService" ] }

Per ulteriori informazioni, consulta la sezione Servizi nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarelist-services.

AWS CLI

Per elencare i servizi in un cluster

L'list-servicesesempio seguente mostra come elencare i servizi in esecuzione in un cluster.

aws ecs list-services --cluster MyCluster

Output:

{ "serviceArns": [ "arn:aws:ecs:us-west-2:123456789012:service/MyCluster/MyService" ] }

Per ulteriori informazioni, consulta la sezione Servizi nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarelist-tags-for-resource.

AWS CLI

Per elencare i tag di una risorsa

L'list-tags-for-resourceesempio seguente elenca i tag per un cluster specifico.

aws ecs list-tags-for-resource \ --resource-arn arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster

Output:

{ "tags": [ { "key": "key1", "value": "value1" }, { "key": "key2", "value": "value2" }, { "key": "key3", "value": "value3" } ] }

Il seguente esempio di codice mostra come utilizzarelist-tags-for-resource.

AWS CLI

Per elencare i tag di una risorsa

L'list-tags-for-resourceesempio seguente elenca i tag per un cluster specifico.

aws ecs list-tags-for-resource \ --resource-arn arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster

Output:

{ "tags": [ { "key": "key1", "value": "value1" }, { "key": "key2", "value": "value2" }, { "key": "key3", "value": "value3" } ] }

Il seguente esempio di codice mostra come utilizzarelist-task-definition-families.

AWS CLI

Esempio 1: per elencare le famiglie di definizioni delle attività registrate

L'list-task-definition-familiesesempio seguente elenca tutte le famiglie di definizioni di attività registrate.

aws ecs list-task-definition-families

Output:

{ "families": [ "node-js-app", "web-timer", "hpcc", "hpcc-c4-8xlarge" ] }

Esempio 2: per filtrare le famiglie di definizioni delle attività registrate

L'list-task-definition-familiesesempio seguente elenca le revisioni delle definizioni delle attività che iniziano con «hpcc».

aws ecs list-task-definition-families --family-prefix hpcc

Output:

{ "families": [ "hpcc", "hpcc-c4-8xlarge" ] }

Per ulteriori informazioni, consulta Task Definition Parameters nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarelist-task-definition-families.

AWS CLI

Esempio 1: per elencare le famiglie di definizioni delle attività registrate

L'list-task-definition-familiesesempio seguente elenca tutte le famiglie di definizioni di attività registrate.

aws ecs list-task-definition-families

Output:

{ "families": [ "node-js-app", "web-timer", "hpcc", "hpcc-c4-8xlarge" ] }

Esempio 2: per filtrare le famiglie di definizioni delle attività registrate

L'list-task-definition-familiesesempio seguente elenca le revisioni delle definizioni delle attività che iniziano con «hpcc».

aws ecs list-task-definition-families --family-prefix hpcc

Output:

{ "families": [ "hpcc", "hpcc-c4-8xlarge" ] }

Per ulteriori informazioni, consulta Task Definition Parameters nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarelist-task-definitions.

AWS CLI

Esempio 1: per elencare le definizioni delle attività registrate

L'list-task-definitionsesempio seguente elenca tutte le definizioni delle attività registrate.

aws ecs list-task-definitions

Output:

{ "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" ] }

Esempio 2: Elencare le definizioni delle attività registrate in una famiglia

L' list-task-definitionsesempio seguente elenca le revisioni delle definizioni delle attività di una famiglia specificata.

aws ecs list-task-definitions --family-prefix wordpress

Output:

{ "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" ] }

Per ulteriori informazioni, consulta Amazon ECS Task Definitions nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarelist-task-definitions.

AWS CLI

Esempio 1: per elencare le definizioni delle attività registrate

L'list-task-definitionsesempio seguente elenca tutte le definizioni delle attività registrate.

aws ecs list-task-definitions

Output:

{ "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" ] }

Esempio 2: Elencare le definizioni delle attività registrate in una famiglia

L' list-task-definitionsesempio seguente elenca le revisioni delle definizioni delle attività di una famiglia specificata.

aws ecs list-task-definitions --family-prefix wordpress

Output:

{ "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" ] }

Per ulteriori informazioni, consulta Amazon ECS Task Definitions nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarelist-tasks.

AWS CLI

Esempio 1: per elencare le attività in un cluster

L'list-tasksesempio seguente elenca tutte le attività di un cluster.

aws ecs list-tasks --cluster default

Output:

{ "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" ] }

Esempio 2: per elencare le attività su una particolare istanza del contenitore

L'list-tasksesempio seguente elenca le attività su un'istanza del contenitore, utilizzando l'UUID dell'istanza del contenitore come filtro.

aws ecs list-tasks --cluster default --container-instance a1b2c3d4-5678-90ab-cdef-33333EXAMPLE

Output:

{ "taskArns": [ "arn:aws:ecs:us-west-2:123456789012:task/a1b2c3d4-5678-90ab-cdef-44444EXAMPLE" ] }

Per ulteriori informazioni, consulta Amazon ECS Task Definitions nella Amazon ECS Developer Guide.

  • Per i dettagli sull'API, consulta AWS CLI Command ListTasksReference.

Il seguente esempio di codice mostra come utilizzarelist-tasks.

AWS CLI

Esempio 1: per elencare le attività in un cluster

L'list-tasksesempio seguente elenca tutte le attività di un cluster.

aws ecs list-tasks --cluster default

Output:

{ "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" ] }

Esempio 2: per elencare le attività su una particolare istanza del contenitore

L'list-tasksesempio seguente elenca le attività su un'istanza del contenitore, utilizzando l'UUID dell'istanza del contenitore come filtro.

aws ecs list-tasks --cluster default --container-instance a1b2c3d4-5678-90ab-cdef-33333EXAMPLE

Output:

{ "taskArns": [ "arn:aws:ecs:us-west-2:123456789012:task/a1b2c3d4-5678-90ab-cdef-44444EXAMPLE" ] }

Per ulteriori informazioni, consulta Amazon ECS Task Definitions nella Amazon ECS Developer Guide.

  • Per i dettagli sull'API, consulta AWS CLI Command ListTasksReference.

Il seguente esempio di codice mostra come utilizzareput-account-setting-default.

AWS CLI

Per modificare le impostazioni predefinite dell'account

L'put-account-setting-defaultesempio seguente modifica l'impostazione predefinita dell'account per tutti gli utenti o i ruoli IAM sul tuo account. Queste modifiche si applicano all'intero AWS account a meno che un utente o un ruolo IAM non sovrascriva esplicitamente queste impostazioni.

aws ecs put-account-setting-default --name serviceLongArnFormat --value enabled

Output:

{ "setting": { "name": "serviceLongArnFormat", "value": "enabled", "principalArn": "arn:aws:iam::123456789012:root" } }

Per ulteriori informazioni, consulta Amazon Resource Names (ARNs) e IDs la Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzareput-account-setting-default.

AWS CLI

Per modificare le impostazioni predefinite dell'account

L'put-account-setting-defaultesempio seguente modifica l'impostazione predefinita dell'account per tutti gli utenti o i ruoli IAM sul tuo account. Queste modifiche si applicano all'intero AWS account a meno che un utente o un ruolo IAM non sovrascriva esplicitamente queste impostazioni.

aws ecs put-account-setting-default --name serviceLongArnFormat --value enabled

Output:

{ "setting": { "name": "serviceLongArnFormat", "value": "enabled", "principalArn": "arn:aws:iam::123456789012:root" } }

Per ulteriori informazioni, consulta Amazon Resource Names (ARNs) e IDs la Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzareput-account-setting.

AWS CLI

Per modificare l'impostazione dell'account per il tuo account utente IAM

L'put-account-settingesempio seguente imposta l'impostazione dell'containerInsightsaccount su enhanced per il tuo account utente IAM. Questo attiva Container Insights con una migliore osservabilità.

aws ecs put-account-setting \ --name containerInsights \ --value enhanced

Output:

{ "setting": { "name": "containerInsights", "value": "enhanced", "principalArn": "arn:aws:iam::123456789012:user/johndoe", "type": "user" } }

Per ulteriori informazioni, consulta Modifica delle impostazioni dell'account nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzareput-account-setting.

AWS CLI

Per modificare l'impostazione dell'account per il tuo account utente IAM

L'put-account-settingesempio seguente imposta l'impostazione dell'containerInsightsaccount su enhanced per il tuo account utente IAM. Questo attiva Container Insights con una migliore osservabilità.

aws ecs put-account-setting \ --name containerInsights \ --value enhanced

Output:

{ "setting": { "name": "containerInsights", "value": "enhanced", "principalArn": "arn:aws:iam::123456789012:user/johndoe", "type": "user" } }

Per ulteriori informazioni, consulta Modifica delle impostazioni dell'account nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzareput-account-settings.

AWS CLI

Per modificare le impostazioni dell'account per un utente o un ruolo IAM

L'put-account-settingesempio seguente modifica le impostazioni dell'account per l'utente IAM o il ruolo IAM specificato.

aws ecs put-account-setting \ --name serviceLongArnFormat \ --value enabled \ --principal-arn arn:aws:iam::123456789012:user/MyUser

Output:

{ "setting": { "name": "serviceLongArnFormat", "value": "enabled", "principalArn": "arn:aws:iam::123456789012:user/MyUser" } }

Il seguente esempio di codice mostra come utilizzareput-account-settings.

AWS CLI

Per modificare le impostazioni dell'account per un utente o un ruolo IAM

L'put-account-settingesempio seguente modifica le impostazioni dell'account per l'utente IAM o il ruolo IAM specificato.

aws ecs put-account-setting \ --name serviceLongArnFormat \ --value enabled \ --principal-arn arn:aws:iam::123456789012:user/MyUser

Output:

{ "setting": { "name": "serviceLongArnFormat", "value": "enabled", "principalArn": "arn:aws:iam::123456789012:user/MyUser" } }

Il seguente esempio di codice mostra come utilizzareput-attributes.

AWS CLI

Per creare un attributo e associarlo a una risorsa Amazon ECS

Quanto segue put-attributes applica un attributo con il nome stack e la produzione di valore a un'istanza del contenitore.

aws ecs put-attributes \ --attributes name=stack,value=production,targetId=arn:aws:ecs:us-west-2:130757420319:container-instance/1c3be8ed-df30-47b4-8f1e-6e68ebd01f34

Output:

{ "attributes": [ { "name": "stack", "targetId": "arn:aws:ecs:us-west-2:130757420319:container-instance/1c3be8ed-df30-47b4-8f1e-6e68ebd01f34", "value": "production" } ] }

Il seguente esempio di codice mostra come utilizzareput-attributes.

AWS CLI

Per creare un attributo e associarlo a una risorsa Amazon ECS

Quanto segue put-attributes applica un attributo con il nome stack e la produzione di valore a un'istanza del contenitore.

aws ecs put-attributes \ --attributes name=stack,value=production,targetId=arn:aws:ecs:us-west-2:130757420319:container-instance/1c3be8ed-df30-47b4-8f1e-6e68ebd01f34

Output:

{ "attributes": [ { "name": "stack", "targetId": "arn:aws:ecs:us-west-2:130757420319:container-instance/1c3be8ed-df30-47b4-8f1e-6e68ebd01f34", "value": "production" } ] }

Il seguente esempio di codice mostra come utilizzareput-cluster-capacity-providers.

AWS CLI

Esempio 1: aggiungere un provider di capacità esistente a un cluster

L'put-cluster-capacity-providersesempio seguente aggiunge un provider di capacità esistente a un cluster. Il create-capacity-provider comando viene utilizzato per creare un provider di capacità. Il describe-clusters comando viene utilizzato per descrivere gli attuali fornitori di capacità e la strategia predefinita dei fornitori di capacità associata a un cluster. Quando si aggiunge un nuovo fornitore di capacità a un cluster, è necessario specificare tutti i fornitori di capacità esistenti oltre al nuovo fornitore di capacità che si desidera associare al cluster. È inoltre necessario specificare la strategia predefinita del provider di capacità da associare al cluster. In questo esempio, al MyCluster cluster è associato il provider di MyCapacityProvider1 capacità e si desidera aggiungere il fornitore di MyCapacityProvider2 capacità e includerlo nella strategia predefinita del fornitore di capacità in modo che le attività siano distribuite uniformemente tra entrambi i fornitori di capacità.

aws ecs put-cluster-capacity-providers \ --cluster MyCluster \ --capacity-providers MyCapacityProvider1 MyCapacityProvider2 \ --default-capacity-provider-strategy capacityProvider=MyCapacityProvider1,weight=1 capacityProvider=MyCapacityProvider2,weight=1

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

Per ulteriori informazioni, consulta Cluster Capacity Provider nella Amazon ECS Developer Guide.

Esempio 2: rimuovere un fornitore di capacità da un cluster

L'put-cluster-capacity-providersesempio seguente rimuove un fornitore di capacità da un cluster. Il describe-clusters comando viene utilizzato per descrivere gli attuali provider di capacità associati a un cluster. Quando si rimuove un fornitore di capacità da un cluster, è necessario specificare i fornitori di capacità che si desidera che rimangano associati al cluster, nonché la strategia predefinita del provider di capacità da associare al cluster. In questo esempio, al cluster sono associati i provider di MyCapacityProvider2 capacità MyCapacityProvider1 e si desidera rimuovere il provider di MyCapacityProvider2 capacità, quindi lo si specifica solo MyCapacityProvider1 nel comando insieme alla strategia predefinita aggiornata del provider di capacità.

aws ecs put-cluster-capacity-providers \ --cluster MyCluster \ --capacity-providers MyCapacityProvider1 \ --default-capacity-provider-strategy capacityProvider=MyCapacityProvider1,weight=1,base=0

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

Per ulteriori informazioni, consulta Cluster Capacity Provider nella Amazon ECS Developer Guide.

Esempio 3: rimuovere tutti i fornitori di capacità da un cluster

L'put-cluster-capacity-providersesempio seguente rimuove tutti i provider di capacità esistenti dal cluster.

aws ecs put-cluster-capacity-providers \ --cluster MyCluster \ --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" } }

Per ulteriori informazioni, consulta Cluster Capacity Provider nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzareput-cluster-capacity-providers.

AWS CLI

Esempio 1: aggiungere un provider di capacità esistente a un cluster

L'put-cluster-capacity-providersesempio seguente aggiunge un provider di capacità esistente a un cluster. Il create-capacity-provider comando viene utilizzato per creare un provider di capacità. Il describe-clusters comando viene utilizzato per descrivere gli attuali fornitori di capacità e la strategia predefinita dei fornitori di capacità associata a un cluster. Quando si aggiunge un nuovo fornitore di capacità a un cluster, è necessario specificare tutti i fornitori di capacità esistenti oltre al nuovo fornitore di capacità che si desidera associare al cluster. È inoltre necessario specificare la strategia predefinita del provider di capacità da associare al cluster. In questo esempio, al MyCluster cluster è associato il provider di MyCapacityProvider1 capacità e si desidera aggiungere il fornitore di MyCapacityProvider2 capacità e includerlo nella strategia predefinita del fornitore di capacità in modo che le attività siano distribuite uniformemente tra entrambi i fornitori di capacità.

aws ecs put-cluster-capacity-providers \ --cluster MyCluster \ --capacity-providers MyCapacityProvider1 MyCapacityProvider2 \ --default-capacity-provider-strategy capacityProvider=MyCapacityProvider1,weight=1 capacityProvider=MyCapacityProvider2,weight=1

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

Per ulteriori informazioni, consulta Cluster Capacity Provider nella Amazon ECS Developer Guide.

Esempio 2: rimuovere un fornitore di capacità da un cluster

L'put-cluster-capacity-providersesempio seguente rimuove un fornitore di capacità da un cluster. Il describe-clusters comando viene utilizzato per descrivere gli attuali provider di capacità associati a un cluster. Quando si rimuove un fornitore di capacità da un cluster, è necessario specificare i fornitori di capacità che si desidera che rimangano associati al cluster, nonché la strategia predefinita del provider di capacità da associare al cluster. In questo esempio, al cluster sono associati i provider di MyCapacityProvider2 capacità MyCapacityProvider1 e si desidera rimuovere il provider di MyCapacityProvider2 capacità, quindi lo si specifica solo MyCapacityProvider1 nel comando insieme alla strategia predefinita aggiornata del provider di capacità.

aws ecs put-cluster-capacity-providers \ --cluster MyCluster \ --capacity-providers MyCapacityProvider1 \ --default-capacity-provider-strategy capacityProvider=MyCapacityProvider1,weight=1,base=0

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

Per ulteriori informazioni, consulta Cluster Capacity Provider nella Amazon ECS Developer Guide.

Esempio 3: rimuovere tutti i fornitori di capacità da un cluster

L'put-cluster-capacity-providersesempio seguente rimuove tutti i provider di capacità esistenti dal cluster.

aws ecs put-cluster-capacity-providers \ --cluster MyCluster \ --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" } }

Per ulteriori informazioni, consulta Cluster Capacity Provider nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzareregister-task-definition.

AWS CLI

Esempio 1: registrare una definizione di attività con un file JSON

L'register-task-definitionesempio seguente registra una definizione di attività nella famiglia specificata. Le definizioni dei contenitori vengono salvate in formato JSON nella posizione del file specificata.

aws ecs register-task-definition \ --cli-input-json file://<path_to_json_file>/sleep360.json

Contenuto di 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 } }

Per ulteriori informazioni, consulta Definizioni di attività di esempio nella Amazon ECS Developer Guide.

Esempio 2: registrare una definizione di attività con un parametro di stringa JSON

L'register-task-definitionesempio seguente registra una definizione di attività utilizzando le definizioni dei contenitori fornite come parametro di stringa JSON con virgolette doppie con escape.

aws ecs register-task-definition \ --family sleep360 \ --container-definitions "[{\"name\":\"sleep\",\"image\":\"busybox\",\"cpu\":10,\"command\":[\"sleep\",\"360\"],\"memory\":10,\"essential\":true}]"

L'output è identico all'esempio precedente.

Per ulteriori informazioni, consulta Creating a Task Definition nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzareregister-task-definition.

AWS CLI

Esempio 1: registrare una definizione di attività con un file JSON

L'register-task-definitionesempio seguente registra una definizione di attività nella famiglia specificata. Le definizioni dei contenitori vengono salvate in formato JSON nella posizione del file specificata.

aws ecs register-task-definition \ --cli-input-json file://<path_to_json_file>/sleep360.json

Contenuto di 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 } }

Per ulteriori informazioni, consulta Definizioni di attività di esempio nella Amazon ECS Developer Guide.

Esempio 2: registrare una definizione di attività con un parametro di stringa JSON

L'register-task-definitionesempio seguente registra una definizione di attività utilizzando le definizioni dei contenitori fornite come parametro di stringa JSON con virgolette doppie con escape.

aws ecs register-task-definition \ --family sleep360 \ --container-definitions "[{\"name\":\"sleep\",\"image\":\"busybox\",\"cpu\":10,\"command\":[\"sleep\",\"360\"],\"memory\":10,\"essential\":true}]"

L'output è identico all'esempio precedente.

Per ulteriori informazioni, consulta Creating a Task Definition nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarerun-task.

AWS CLI

Per eseguire un'attività nel cluster predefinito

L'run-taskesempio seguente esegue un'attività nel cluster predefinito e utilizza un token client.

aws ecs run-task \ --cluster default \ --task-definition sleep360:1 \ --client-token 550e8400-e29b-41d4-a716-446655440000

Output:

{ "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": [] }

Per ulteriori informazioni, consulta Running Tasks nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarerun-task.

AWS CLI

Per eseguire un'attività nel cluster predefinito

L'run-taskesempio seguente esegue un'attività nel cluster predefinito e utilizza un token client.

aws ecs run-task \ --cluster default \ --task-definition sleep360:1 \ --client-token 550e8400-e29b-41d4-a716-446655440000

Output:

{ "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": [] }

Per ulteriori informazioni, consulta Running Tasks nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzarestart-task.

AWS CLI

Per iniziare una nuova attività

Quanto segue start-task avvia un'attività utilizzando la revisione più recente della definizione dell'sleep360attività sull'istanza del contenitore specificata nel cluster predefinito.

aws ecs start-task \ --task-definition sleep360 \ --container-instances 765936fadbdd46b5991a4bd70c2a43d4

Output:

{ "tasks": [ { "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": [ { "name": "sleep" } ] }, "lastStatus": "PENDING", "desiredStatus": "RUNNING", "cpu": "128", "memory": "128", "containers": [ { "containerArn": "arn:aws:ecs:us-west-2:130757420319:container/75f11ed4-8a3d-4f26-a33b-ad1db9e02d41", "taskArn": "arn:aws:ecs:us-west-2:130757420319: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": [] }

Il seguente esempio di codice mostra come utilizzarestart-task.

AWS CLI

Per iniziare una nuova attività

Quanto segue start-task avvia un'attività utilizzando la revisione più recente della definizione dell'sleep360attività sull'istanza del contenitore specificata nel cluster predefinito.

aws ecs start-task \ --task-definition sleep360 \ --container-instances 765936fadbdd46b5991a4bd70c2a43d4

Output:

{ "tasks": [ { "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": [ { "name": "sleep" } ] }, "lastStatus": "PENDING", "desiredStatus": "RUNNING", "cpu": "128", "memory": "128", "containers": [ { "containerArn": "arn:aws:ecs:us-west-2:130757420319:container/75f11ed4-8a3d-4f26-a33b-ad1db9e02d41", "taskArn": "arn:aws:ecs:us-west-2:130757420319: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": [] }

Il seguente esempio di codice mostra come utilizzarestop-task.

AWS CLI

Per interrompere un'operazione

Quanto segue stop-task interrompe l'esecuzione dell'attività specificata nel cluster predefinito.

aws ecs stop-task \ --task 666fdccc2e2d4b6894dd422f4eeee8f8

Output:

{ "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": [] } }
  • Per i dettagli sull'API, vedere StopTaskin AWS CLI Command Reference.

Il seguente esempio di codice mostra come utilizzarestop-task.

AWS CLI

Per interrompere un'operazione

Quanto segue stop-task interrompe l'esecuzione dell'attività specificata nel cluster predefinito.

aws ecs stop-task \ --task 666fdccc2e2d4b6894dd422f4eeee8f8

Output:

{ "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": [] } }
  • Per i dettagli sull'API, vedere StopTaskin AWS CLI Command Reference.

Il seguente esempio di codice mostra come utilizzaretag-resource.

AWS CLI

Per etichettare una risorsa

L'tag-resourceesempio seguente aggiunge un singolo tag alla risorsa specificata.

aws ecs tag-resource \ --resource-arn arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster --tags key=key1,value=value1

Questo comando non produce alcun output.

Per aggiungere più tag a una risorsa

L'tag-resourceesempio seguente aggiunge più tag alla risorsa specificata.

aws ecs tag-resource \ --resource-arn arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster \ --tags key=key1,value=value1 key=key2,value=value2 key=key3,value=value3

Questo comando non produce alcun output.

  • Per i dettagli sull'API, vedere TagResourcein AWS CLI Command Reference.

Il seguente esempio di codice mostra come utilizzaretag-resource.

AWS CLI

Per etichettare una risorsa

L'tag-resourceesempio seguente aggiunge un singolo tag alla risorsa specificata.

aws ecs tag-resource \ --resource-arn arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster --tags key=key1,value=value1

Questo comando non produce alcun output.

Per aggiungere più tag a una risorsa

L'tag-resourceesempio seguente aggiunge più tag alla risorsa specificata.

aws ecs tag-resource \ --resource-arn arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster \ --tags key=key1,value=value1 key=key2,value=value2 key=key3,value=value3

Questo comando non produce alcun output.

  • Per i dettagli sull'API, vedere TagResourcein AWS CLI Command Reference.

Il seguente esempio di codice mostra come utilizzareuntag-resource.

AWS CLI

Per rimuovere un tag da una risorsa

L'untag-resourceesempio seguente rimuove i tag elencati dalla risorsa specificata.

aws ecs untag-resource \ --resource-arn arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster \ --tag-keys key1,key2

Questo comando non produce alcun output.

  • Per i dettagli sull'API, vedere UntagResourcein AWS CLI Command Reference.

Il seguente esempio di codice mostra come utilizzareuntag-resource.

AWS CLI

Per rimuovere un tag da una risorsa

L'untag-resourceesempio seguente rimuove i tag elencati dalla risorsa specificata.

aws ecs untag-resource \ --resource-arn arn:aws:ecs:us-west-2:123456789012:cluster/MyCluster \ --tag-keys key1,key2

Questo comando non produce alcun output.

  • Per i dettagli sull'API, vedere UntagResourcein AWS CLI Command Reference.

Il seguente esempio di codice mostra come utilizzareupdate-cluster-settings.

AWS CLI

Per modificare le impostazioni del cluster

L'update-cluster-settingsesempio seguente abilita CloudWatch Container Insights con una migliore osservabilità per il MyCluster cluster.

aws ecs update-cluster-settings \ --cluster MyCluster \ --settings name=containerInsights,value=enhanced

Output:

{ "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" } ] } }

Per ulteriori informazioni, consulta Modifica delle impostazioni dell'account nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzareupdate-cluster-settings.

AWS CLI

Per modificare le impostazioni del cluster

L'update-cluster-settingsesempio seguente abilita CloudWatch Container Insights con una migliore osservabilità per il MyCluster cluster.

aws ecs update-cluster-settings \ --cluster MyCluster \ --settings name=containerInsights,value=enhanced

Output:

{ "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" } ] } }

Per ulteriori informazioni, consulta Modifica delle impostazioni dell'account nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzareupdate-cluster.

AWS CLI

Esempio 1: aggiornamento del cluster ECS abilitando ContainerInsights

Quanto segue update-cluster aggiorna il valore di ContainerInsights enabled in un cluster già creato. Per impostazione predefinita, è disabilitato.

aws ecs update-cluster \ --cluster ECS-project-update-cluster \ --settings name=containerInsights,value=enabled

Output:

"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" } }

Esempio 2: aggiorna il cluster ECS per impostare uno spazio dei nomi Service Connect predefinito

Quanto segue update-cluster aggiorna il cluster ECS impostando uno spazio dei nomi Service Connect predefinito.

aws ecs update-cluster \ --cluster ECS-project-update-cluster \ --service-connect-defaults namespace=test

Output:

{ "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" } } }

Per ulteriori informazioni su Service Connect, consulta Use Service Connect per connettere i servizi Amazon ECS con nomi brevi nella Amazon ECS Developer Guide.

  • Per i dettagli sull'API, consulta AWS CLI Command UpdateClusterReference.

Il seguente esempio di codice mostra come utilizzareupdate-cluster.

AWS CLI

Esempio 1: aggiornamento del cluster ECS abilitando ContainerInsights

Quanto segue update-cluster aggiorna il valore di ContainerInsights enabled in un cluster già creato. Per impostazione predefinita, è disabilitato.

aws ecs update-cluster \ --cluster ECS-project-update-cluster \ --settings name=containerInsights,value=enabled

Output:

"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" } }

Esempio 2: aggiorna il cluster ECS per impostare uno spazio dei nomi Service Connect predefinito

Quanto segue update-cluster aggiorna il cluster ECS impostando uno spazio dei nomi Service Connect predefinito.

aws ecs update-cluster \ --cluster ECS-project-update-cluster \ --service-connect-defaults namespace=test

Output:

{ "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" } } }

Per ulteriori informazioni su Service Connect, consulta Use Service Connect per connettere i servizi Amazon ECS con nomi brevi nella Amazon ECS Developer Guide.

  • Per i dettagli sull'API, consulta AWS CLI Command UpdateClusterReference.

Il seguente esempio di codice mostra come utilizzareupdate-container-agent.

AWS CLI

Per aggiornare l'agente container su un'istanza di container Amazon ECS

L'update-container-agentesempio seguente aggiorna l'agente del contenitore sull'istanza di contenitore specificata nel cluster predefinito.

aws ecs update-container-agent --cluster default --container-instance a1b2c3d4-5678-90ab-cdef-11111EXAMPLE

Output:

{ "containerInstance": { "status": "ACTIVE", ... "agentUpdateStatus": "PENDING", "versionInfo": { "agentVersion": "1.0.0", "agentHash": "4023248", "dockerVersion": "DockerVersion: 1.5.0" } } }

Per ulteriori informazioni, consulta Updating the Amazon ECS Container Agent nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzareupdate-container-agent.

AWS CLI

Per aggiornare l'agente container su un'istanza di container Amazon ECS

L'update-container-agentesempio seguente aggiorna l'agente del contenitore sull'istanza di contenitore specificata nel cluster predefinito.

aws ecs update-container-agent --cluster default --container-instance a1b2c3d4-5678-90ab-cdef-11111EXAMPLE

Output:

{ "containerInstance": { "status": "ACTIVE", ... "agentUpdateStatus": "PENDING", "versionInfo": { "agentVersion": "1.0.0", "agentHash": "4023248", "dockerVersion": "DockerVersion: 1.5.0" } } }

Per ulteriori informazioni, consulta Updating the Amazon ECS Container Agent nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzareupdate-container-instances-state.

AWS CLI

Per aggiornare lo stato di un'istanza del contenitore

Quanto segue update-container-instances-state aggiorna lo stato dell'istanza del contenitore specificata in DRAINING cui verrà rimossa dal cluster in cui è registrata.

aws ecs update-container-instances-state \ --container-instances 765936fadbdd46b5991a4bd70c2a43d4 \ --status DRAINING

Output:

{ "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": [] }

Il seguente esempio di codice mostra come utilizzareupdate-container-instances-state.

AWS CLI

Per aggiornare lo stato di un'istanza del contenitore

Quanto segue update-container-instances-state aggiorna lo stato dell'istanza del contenitore specificata in DRAINING cui verrà rimossa dal cluster in cui è registrata.

aws ecs update-container-instances-state \ --container-instances 765936fadbdd46b5991a4bd70c2a43d4 \ --status DRAINING

Output:

{ "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": [] }

Il seguente esempio di codice mostra come utilizzareupdate-service-primary-task-set.

AWS CLI

Per aggiornare il set di attività principale per un servizio

L'update-service-primary-task-setesempio seguente aggiorna il set di attività principale per il servizio specificato.

aws ecs update-service-primary-task-set \ --cluster MyCluster \ --service MyService \ --primary-task-set arn:aws:ecs:us-west-2:123456789012:task-set/MyCluster/MyService/ecs-svc/1234567890123456789

Output:

{ "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 } }

Il seguente esempio di codice mostra come utilizzareupdate-service-primary-task-set.

AWS CLI

Per aggiornare il set di attività principale per un servizio

L'update-service-primary-task-setesempio seguente aggiorna il set di attività principale per il servizio specificato.

aws ecs update-service-primary-task-set \ --cluster MyCluster \ --service MyService \ --primary-task-set arn:aws:ecs:us-west-2:123456789012:task-set/MyCluster/MyService/ecs-svc/1234567890123456789

Output:

{ "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 } }

Il seguente esempio di codice mostra come utilizzareupdate-service.

AWS CLI

Esempio 1: per modificare il numero di istanze in un servizio

L'update-serviceesempio seguente aggiorna il numero di attività desiderato del servizio my-http-service a 2.

aws ecs update-service \ --cluster MyCluster --service my-http-service \ --desired-count 2

Output:

{ "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" } }

Per ulteriori informazioni, consulta Aggiornamento di un servizio Amazon ECS utilizzando la console nella Amazon ECS Developer Guide.

Esempio 2: attivare il ribilanciamento della zona di disponibilità per un servizio

L'update-serviceesempio seguente attiva il ribilanciamento della zona di disponibilità per il servizio. my-http-service

aws ecs update-service \ --cluster MyCluster \ --service my-http-service \ --availability-zone-rebalancing ENABLED

Output:

{ "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" } }

Per ulteriori informazioni, consulta Aggiornamento di un servizio Amazon ECS utilizzando la console nella Amazon ECS Developer Guide.

  • Per i dettagli sull'API, consulta AWS CLI Command UpdateServiceReference.

Il seguente esempio di codice mostra come utilizzareupdate-service.

AWS CLI

Esempio 1: per modificare il numero di istanze in un servizio

L'update-serviceesempio seguente aggiorna il numero di attività desiderato del servizio my-http-service a 2.

aws ecs update-service \ --cluster MyCluster --service my-http-service \ --desired-count 2

Output:

{ "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" } }

Per ulteriori informazioni, consulta Aggiornamento di un servizio Amazon ECS utilizzando la console nella Amazon ECS Developer Guide.

Esempio 2: attivare il ribilanciamento della zona di disponibilità per un servizio

L'update-serviceesempio seguente attiva il ribilanciamento della zona di disponibilità per il servizio. my-http-service

aws ecs update-service \ --cluster MyCluster \ --service my-http-service \ --availability-zone-rebalancing ENABLED

Output:

{ "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" } }

Per ulteriori informazioni, consulta Aggiornamento di un servizio Amazon ECS utilizzando la console nella Amazon ECS Developer Guide.

  • Per i dettagli sull'API, consulta AWS CLI Command UpdateServiceReference.

Il seguente esempio di codice mostra come utilizzareupdate-task-protection.

AWS CLI

Esempio 1: abilitare la protezione delle attività per le attività ECS

Quanto segue update-task-protection protegge l'attività ECS dall'interruzione durante lo scale-in from Deployments o Service. AutoScaling È possibile specificare un periodo di scadenza personalizzato per la protezione delle attività da 1 a 2.880 minuti (48 ore). Se non si specifica il periodo di scadenza, il tempo predefinito di attivazione della protezione delle attività è di 2 ore.

aws ecs update-task-protection \ --cluster ECS-project-update-cluster \ --tasks c43ed3b1331041f289316f958adb6a24 \ --protection-enabled \ --expires-in-minutes 300

Output:

{ "protectedTasks": [ { "taskArn": "arn:aws:ecs:us-west-2:123456789012:task/c43ed3b1331041f289316f958adb6a24", "protectionEnabled": true, "expirationDate": "2024-09-14T19:53:36.687000-05:00" } ], "failures": [] }

Esempio 2: disabilita la protezione delle attività per le attività ECS

Quanto segue update-task-protection disabilita le attività protette dalla scalabilità di Deployments o Service. AutoScaling

aws ecs update-task-protection \ --cluster ECS-project-update-cluster \ --tasks c43ed3b1331041f289316f958adb6a24 \ --no-protection-enabled

Output:

{ "protectedTasks": [ { "taskArn": "arn:aws:ecs:us-west-2:123456789012:task/c43ed3b1331041f289316f958adb6a24", "protectionEnabled": false } ], "failures": [] }

Per ulteriori informazioni sulla protezione delle attività, consulta Proteggi le tue attività Amazon ECS dall'interruzione a causa di eventi di scalabilità nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzareupdate-task-protection.

AWS CLI

Esempio 1: abilitare la protezione delle attività per le attività ECS

Quanto segue update-task-protection protegge l'attività ECS dall'interruzione durante lo scale-in from Deployments o Service. AutoScaling È possibile specificare un periodo di scadenza personalizzato per la protezione delle attività da 1 a 2.880 minuti (48 ore). Se non si specifica il periodo di scadenza, il tempo predefinito di attivazione della protezione delle attività è di 2 ore.

aws ecs update-task-protection \ --cluster ECS-project-update-cluster \ --tasks c43ed3b1331041f289316f958adb6a24 \ --protection-enabled \ --expires-in-minutes 300

Output:

{ "protectedTasks": [ { "taskArn": "arn:aws:ecs:us-west-2:123456789012:task/c43ed3b1331041f289316f958adb6a24", "protectionEnabled": true, "expirationDate": "2024-09-14T19:53:36.687000-05:00" } ], "failures": [] }

Esempio 2: disabilita la protezione delle attività per le attività ECS

Quanto segue update-task-protection disabilita le attività protette dalla scalabilità di Deployments o Service. AutoScaling

aws ecs update-task-protection \ --cluster ECS-project-update-cluster \ --tasks c43ed3b1331041f289316f958adb6a24 \ --no-protection-enabled

Output:

{ "protectedTasks": [ { "taskArn": "arn:aws:ecs:us-west-2:123456789012:task/c43ed3b1331041f289316f958adb6a24", "protectionEnabled": false } ], "failures": [] }

Per ulteriori informazioni sulla protezione delle attività, consulta Proteggi le tue attività Amazon ECS dall'interruzione a causa di eventi di scalabilità nella Amazon ECS Developer Guide.

Il seguente esempio di codice mostra come utilizzareupdate-task-set.

AWS CLI

Per aggiornare un set di attività

L'update-task-setesempio seguente aggiorna un set di attività per regolare la scala.

aws ecs update-task-set \ --cluster MyCluster \ --service MyService \ --task-set arn:aws:ecs:us-west-2:123456789012:task-set/MyCluster/MyService/ecs-svc/1234567890123456789 \ --scale value=50,unit=PERCENT

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/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 } }
  • Per i dettagli sull'API, vedere UpdateTaskSetin AWS CLI Command Reference.

Il seguente esempio di codice mostra come utilizzareupdate-task-set.

AWS CLI

Per aggiornare un set di attività

L'update-task-setesempio seguente aggiorna un set di attività per regolare la scala.

aws ecs update-task-set \ --cluster MyCluster \ --service MyService \ --task-set arn:aws:ecs:us-west-2:123456789012:task-set/MyCluster/MyService/ecs-svc/1234567890123456789 \ --scale value=50,unit=PERCENT

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/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 } }
  • Per i dettagli sull'API, vedere UpdateTaskSetin AWS CLI Command Reference.

In questa pagina

Argomento successivo:

Amazon EFS

Argomento precedente:

Amazon ECR
PrivacyCondizioni del sitoPreferenze cookie
© 2025, Amazon Web Services, Inc. o società affiliate. Tutti i diritti riservati.