Skip to content

Instantly share code, notes, and snippets.

@ankona
Created May 4, 2016 17:33
Show Gist options
  • Save ankona/e64e5508258cd31d2644ff9084ca5fcb to your computer and use it in GitHub Desktop.
Save ankona/e64e5508258cd31d2644ff9084ca5fcb to your computer and use it in GitHub Desktop.
query a cloudformation stack for it's resources and find the first RestAPI id in it
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
.. module:: get_api_id_from_stack
:synopsis:
"""
import boto3
import sys
try:
stack_name = sys.argv[1]
cloudformation = boto3.client('cloudformation')
resp = cloudformation.describe_stack_resources(StackName=stack_name)
for r in resp['StackResources']:
if r['ResourceType'] == "AWS::ApiGateway::RestApi":
print r['PhysicalResourceId']
break
except:
print 'missing api name'
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment