简体   繁体   中英

AWS ECS - Using Boto3 to update a task definition

Using boto3, we can create a new task definition:

client = boto3.client('ecs')
client.register_task_definition(...)

How do we update an existing task definition? Is it just another call with changes and the same family name?

update an existing task definition

You can't do this. You have to create a new revision of an existing task definition. Then you will also have to update your ECS service to use the new task revision. Running register_task_definition again should automatically create new revision for you.

As above you have to create a new revision using register_task_definition and passing in everything that did not change. This is super annoying as this is the workflow for a standard ECS deployment. ie create a new task definition revision with updated tag for image. Why would there not be some built in functionality for this... This is what i have done:

existing_task_def_response = ecs_client.describe_task_definition(
    taskDefinition=ecs_task_definition_name,
)
new_task_definition = existing_task_def_response['taskDefinition']
#edit the image tag here
new_task_definition['containerDefinitions'][0]['image'] = yournewimagetagforexample

#drop all the keys from the dict that you can't use as kwargs in the next call. could be explicit here and map things
remove_args=['compatibilities', 'registeredAt', 'registeredBy', 'status', 'revision', 'taskDefinitionArn', 'requiresAttributes' ]
for arg in remove_args:
    new_task_definition.pop(arg)

reg_task_def_response = ecs_client.register_task_definition(
**new_task_definition
)

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