我有一個云形成模板,可以提供不同的資源,例如(EC2、S3、DynamoDB、Lamda、IAM 角色、RDS、EIP、EBS)。想要獲取資源 ARN。因此,我們可以相應地更新資源的標簽。Cloudformation describe_stacks Api 未提供有關資源 ARN 的資訊。在 boto3 中創建標簽需要資源的 ARN。
回應 = client.tag_resources( ResourceARNList=[ 'string', ], Tags={ 'string': 'string' } )
uj5u.com熱心網友回復:
您可以將標簽應用于堆疊本身,而不是單獨標記所有資源。您應用于 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(示例輸出)。您可以將它與client.tag_resources一起使用來標記堆疊。
如果由于某種原因您需要為堆疊創建的每個資源單獨添加不同的標簽,您有兩種選擇:
- 在 CloudFormation 模板本身中定義標簽。
- 在 CloudFormation 模板的輸出部分添加 ARN 值。然后,您可以使用 describe_stacks 讀取這些值。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/439833.html
