简体   繁体   中英

AWS CLI - Create New Revision of Task Definition

In AWS ECS with the UI, I can create a new revision of a task definition. I go to Task Definitions -> Select my Task Definition -> Select my Revision -> Click Create new revision.

With AWS UI, the container definition properties are copied across from the old revision to the new revision .

With AWS CLI, how do I copy across the container definition from the old revision to the new revision? Is there a simple CLI command I can use without having to manually extract properties from the old definition to then create the new definition?

This is my AWS CLI solution so far:

I'm getting the image with:

aws ecr describe-images ...

And the container definition with:

aws ecs describe-task-definition ...

I'm then extracting the container definition properties, placing them in a json string $CONTAINER_DEFINITION and then creating a new revision with:

aws ecs register-task-definition --family $TASK_DEFINITION --container-definitions $CONTAINER_DEFINITION

When I check the UI, the old revision's container definition properties are not copied across to the new revision's container definition. I expected the container definition properties to be copied across from the old revision to the new revision, as that would be the same behaviour as AWS UI.

I am trying to do exactly the same - create a new revision of an existing task definition using an updated container version. I suspect your approach is registering an entirely new task definition, rather than creating an incremental version of an existing one.

Update... managed to get this working using Powershell and the AWS CLI. The PS commands below read the task definition, edit the container version in the container definitions, then get the container defs as JSON and pass them back into the register command.

$taskDef = aws ecs describe-task-definition --task-definition <task definition name> --region=eu-west-1 | ConvertFrom-Json
$taskDef.taskDefinition.containerDefinitions[0].image = "<container>:<version>"
$containerDefinitions = $taskDef.taskDefinition.containerDefinitions | ConvertTo-Json -Depth 10
aws ecs register-task-definition --family "<task definition name>" --container-definitions $containerDefinitions --memory 8192

The trick to generate a revision (rather than a new task def) appeared to be the family parameter which is set to the existing task definition name. Not sure why it required the memory parameter, but it worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM