繁体   English   中英

使用 Boto3 来自 CF 模板的资源 ARN

[英]Resources ARN from CF template using Boto3

我有一个云形成模板,它提供不同的资源,如(EC2、S3、DynamoDB、Lamda、IAM 角色、RDS、EIP、EBS)。 想要获取资源 ARN。 因此,我们可以相应地更新资源标签。 Cloudformation describe_stacks Api 未提供有关资源 ARN 的信息。 在 boto3 中创建标签需要资源的 ARN。

response = client.tag_resources( ResourceARNList=[ 'string', ], Tags={ 'string': 'string' } )

您可以将标签应用于堆栈本身,而不是单独标记所有资源。 您应用于 AWS CloudFormation 模板的任何标签都将自动应用于堆栈创建的资源。 文档中

All stack-level tags, including automatically created tags, are propagated to resources that CloudFormation supports. Currently, tags aren't propagated to Amazon EBS volumes that are created from block device mappings.

文档没有提到这一点,但 describe_stacks API 中的 StackId 字段实际上是 CloudFormation 堆栈的 ARN( 样本 output )。 您可以将它与client.tag_resources一起使用来标记堆栈。

如果出于某种原因您需要为堆栈创建的每个资源分别添加不同的标签,您有两种选择:

  1. 在 CloudFormation 模板本身中定义标签。
  2. 在 CloudFormation 模板的output 部分添加 ARN 值。 然后,您可以使用 describe_stacks 读取这些值。

暂无
暂无

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

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