简体   繁体   English

AWS ECS - 使用 Boto3 更新任务定义

[英]AWS ECS - Using Boto3 to update a task definition

Using boto3, we can create a new task definition:使用 boto3,我们可以创建一个新的任务定义:

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.然后,您还必须更新您的 ECS 服务以使用新的任务修订版。 Running register_task_definition again should automatically create new revision for you.再次运行register_task_definition应该会自动为您创建新版本。

As above you have to create a new revision using register_task_definition and passing in everything that did not change.如上所述,您必须使用 register_task_definition 创建一个新修订版并传入所有未更改的内容。 This is super annoying as this is the workflow for a standard ECS deployment.这非常烦人,因为这是标准 ECS 部署的工作流程。 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
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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