【问题标题】:Boto3: when calling the TagResource operation: Long arn format must be used for tagging operationsBoto3:调用TagResource操作时:标记操作必须使用Long arn格式
【发布时间】:2020-06-06 21:58:27
【问题描述】:

我使用 Cloudformation 模板创建了我的 ECS、服务和任务,其中未使用 enableECSManagedTags 或传播标签。

创建堆栈后,我试图在下面运行以添加标签

service_tag_response = self.ecs_client.tag_resource(resourceArn=self.service_arn_name,
                                                                tags=self.service_tag)

然后我得到了错误,when calling the TagResource operation: Long arn format must be used for tagging operations

然后我尝试启用 longresource 选项,我的脚本如下所示

response = self.ecs_client.put_account_setting(name='serviceLongArnFormat', value='enabled')
        if 'ResponseMetadata' in response and \
                response['ResponseMetadata']['HTTPStatusCode'] == 200:
            service_tag_response = self.ecs_client.tag_resource(resourceArn=self.service_arn_name,
                                                                tags=self.service_tag)

然后我也遇到了同样的错误。 有谁知道,如何解决这个错误? 我的服务是:arn:aws:ecs:eu-west-1:12345678901:service/my-service

【问题讨论】:

  • 什么是service_arn_name?似乎是它的唯一名称,而不是完整的 arn。
  • 我的服务 arn 是 arn:aws:ecs:eu-west-1:12345678901:service/my-service,所以您建议只使用 my-service 就足够了。让我试试。同样令人困惑的是,在 boto3 手册中,他们建议服务的 arm 并且在 aws 领域 arn 以 arn 开头
  • 错误信息显示:“Long arn format must 用于标记操作”。这表明您必须使用完整的 arn,而不是服务名称。
  • 根据docs.aws.amazon.com/AmazonECS/latest/userguide/…,我也使用过arn:aws:ecs:eu-west-1:12345678901:service/mycluster/my-service,然后它抱怨when calling the TagResource operation: The specified service does not have the longArn format. Only services created after opting in will have the new format。我在脚本中使用了 arn 名称,那么使用 Long arn format 是什么意思?
  • 标签资源中的 arn 示例为 here。也许这会让你知道出了什么问题。

标签: boto3 amazon-ecs


【解决方案1】:

您似乎没有为创建 ECS 服务的用户/角色启用“serviceLongArnFormat”帐户设置。

要能够向 ECS 服务添加标签,您需要根据 1 选择加入新的 Amazon 资源名称 (ARN) 和资源标识符 (ID) 格式。要选择使用新的 ARN 格式,请参阅 2

您也可以参考这篇博文3 了解更多信息。请注意,现有资源在重新创建之前不会收到新的 ARN 格式。

【讨论】:

  • 我听你的,完全理解。但我的观点是,当我创建 ECS 资源时,我没有选择长格式 arn。这就是为什么当我询问资源 arn 详细信息时,我会得到旧的格式方式。然后在标记旧格式时为什么会强制要求我选择长arn。从出现的错误来看,AWS 正在强制选择 longarn 格式。所以我的问题是在创建资源之前必须选择加入吗?因为我没有这个错误,如果我在创建 ECS 资源之前启用 longarn 格式。
  • “要使用此功能,您需要选择加入新的 Amazon 资源名称 (ARN) 和资源标识符 (ID) 格式。” - docs.aws.amazon.com/AmazonECS/latest/developerguide/…
猜你喜欢
  • 1970-01-01
  • 2021-11-03
  • 1970-01-01
  • 1970-01-01
  • 2015-10-13
  • 2017-10-25
  • 1970-01-01
  • 2017-11-28
  • 1970-01-01
相关资源
最近更新 更多