-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstack_outputs.py
38 lines (33 loc) · 1.25 KB
/
stack_outputs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import json
import boto3
import datetime
from botocore.exceptions import BotoCoreError, ClientError
def main():
try:
query = json.loads(sys.stdin.read())
client = boto3.client('cloudformation', region_name=query['region'])
except (BotoCoreError, ClientError, Exception) as e:
msg = '{}: {}'.format(type(e).__name__, e)
sys.stdout.write("{\"Error:\" : \"" + msg + "\"}")
sys.exit(0)
try:
outputs = client.describe_stacks(StackName=query['stack_name'])["Stacks"]
d = {}
for o in outputs:
if 'StackName' in o:
d['StackName'] = o['StackName']
if 'Outputs' in o:
for op in o['Outputs']:
d[op['OutputKey']] = op['OutputValue']
sys.stdout.write(json.dumps(d))
except (BotoCoreError, ClientError, Exception) as e:
msg = '{}: {}'.format(type(e).__name__, e)
sys.stdout.write("{\"Error:\" : \"" + msg + "\"}")
if __name__ == '__main__':
main()
sys.exit(0)
## Details on what else could be pulled out of the CF json.
## https://boto3.readthedocs.io/en/latest/reference/services/cloudformation.html#CloudFormation.Client.describe_stacks