Skip to content

Instantly share code, notes, and snippets.

@coingraham
Created March 21, 2016 14:56
Show Gist options
  • Save coingraham/95b186d59f454eea5968 to your computer and use it in GitHub Desktop.
Save coingraham/95b186d59f454eea5968 to your computer and use it in GitHub Desktop.
Python - get cloudformationtemplate client and it's tags based on name
import boto3
cftname = "Name"
tagname1 = "Key1"
tagname2 = "Key2"
cft_client = boto3.client('cloudformation')
# Here we only get one stack because we know the exact name
stack = cft_client.describe_stacks(StackName=cftname)[u'Stacks'][0]
# Basically for teasing out combination tags like "Owner = Coin Graham:CoinGraham@company.com"
# see a lot of need for this with only 10 tags total.
for tag in stack[u'Tags']:
if tag[u'Key'] == tagname1:
tagpair1, tagpair2 = tag[u'Value'].split(":")
elif tag[u'Key'] == tagname2:
tagvalue2 = tag[u'Value']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment