繁体   English   中英

如何在已创建的 ECS 服务上更新选项“propagateTags”?

[英]How can I update the option "propagateTags" on an already created ECS service?

我需要为给定的 ECS 服务标记所有现有和即将到来的任务定义。 问题是我意识到服务的“PropagateTags”属性设置为“NONE”并且任务定义没有所需的标签。 我试图先在控制台中更新该属性,但这是不可能的。 然后,我使用了下一个命令:

aws ecs update-service --cluster my-cluster --service my-service --propagateTags  SERVICE --profile "my-profile"

但这也不起作用,因为参数“propagateTags”没有被识别。

我最后一次尝试使用 boto3 (API) 使用下一个脚本:

import boto3

session = boto3.Session(profile_name = 'my-profile', region_name = 'us-east-1')
    
ecs_cluster= 'my-cluster'
ecs_service= 'my-service'

ecs_client=boto3.client('ecs')

response = ecs_client.update_service(
    cluster=ecs_cluster,
    service=ecs_service,
    propagateTags='SERVICE'
)

但猜猜怎么了? 这不起作用,因为 API 调用无法识别 tags 参数。

Traceback (most recent call last):
  File "./ecs_propagatetags.py", line 16, in <module>
    propagateTags='SERVICE'
  File "C:\Python37\lib\site-packages\botocore\client.py", line 388, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "C:\Python37\lib\site-packages\botocore\client.py", line 681, in _make_api_call
    api_params, operation_model, context=request_context)
  File "C:\Python37\lib\site-packages\botocore\client.py", line 729, in _convert_to_request_dict
    api_params, operation_model)
  File "C:\Python37\lib\site-packages\botocore\validate.py", line 360, in serialize_to_request
    raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Unknown parameter in input: "propagateTags", must be one of: cluster, service, desiredCount, taskDefinition, capacityProviderStrategy, deploymentConfiguration, networkConfiguration, placementConstraints, placementStrategy, platformVersion, forceNewDeployment, healthCheckGracePeriodSeconds, enableExecuteCommand

关于如何解决问题的任何想法? 重新创建服务是最后的选择。

该文档propagateTags显示为ECS update_service() 方法的有效参数,因此如果您的 boto3 版本表明它无效,您可能需要升级您的 boto3 版本。

AWS CLI相同,因此您可能也没有运行最新版本。

一旦你在你的服务上设置了propagateTags配置,它仍然只适用于它创建的任何新任务,现有的运行任务不会被添加标签。 因此,您可以触发新的服务部署以使服务用分配有标签的新任务替换这些任务,或者您可以使用ECS tag_resource()方法将标签添加到现有任务。

不幸的是,这似乎是唯一记录在案的选项: propagateTags(字符串)——指定是否将标签从任务定义传播到任务。 如果未指定值,则不会传播标签。 标签只能在任务创建期间传播到任务。 要在创建任务后向任务添加标签,请使用 TagResource API 操作。 参考: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ecs.html

正如它在那里提到的那样,您可以使用 tag_resource 客户端方法: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ecs.html#ECS.Client.tag_resource

暂无
暂无

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

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