Home > OS >  Resources ARN from CF template using Boto3
Resources ARN from CF template using Boto3

Time:03-09

I have a cloud formation template that provisions different resources like(EC2, S3, DynamoDB, Lamda, IAM Role, RDS, EIP, EBS). Want to get the resources ARN. so, we can update the tags of resources accordingly. Cloudformation describe_stacks Api not providing the information regarding resources ARN. In boto3 to create a tag needs an ARN of resources.

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

CodePudding user response:

Instead of individually tagging all the resource, you can apply the tags to the stack itself. Any tag you apply to the AWS CloudFormation template will automatically be applied to the resources created by the stack. From the documentation:

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.

The documentation does not mention this, but the StackId field in the describe_stacks API is actually the ARN of the CloudFormation stack (Sample output). You can use it along with client.tag_resources to tag the stack.

If for some reason you need to individually add different tags to each resource created by the stack, you have two options:

  1. Define the tags in the CloudFormation template itself.
  2. Add the ARN values in the output section of the CloudFormation template. You can then read the values using describe_stacks.
  • Related