[英]AWS ECS - Using Boto3 to update a task definition
使用 boto3,我們可以創建一個新的任務定義:
client = boto3.client('ecs')
client.register_task_definition(...)
我們如何更新現有的任務定義? 這只是另一個有變化和相同姓氏的電話嗎?
更新現有的任務定義
你不能這樣做。 您必須創建現有任務定義的新版本。 然后,您還必須更新您的 ECS 服務以使用新的任務修訂版。 再次運行register_task_definition
應該會自動為您創建新版本。
如上所述,您必須使用 register_task_definition 創建一個新修訂版並傳入所有未更改的內容。 這非常煩人,因為這是標准 ECS 部署的工作流程。 即使用更新的圖像標簽創建一個新的任務定義修訂。 為什么沒有一些內置功能...這就是我所做的:
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.