-
Notifications
You must be signed in to change notification settings - Fork 0
/
devopsstackinfoapi.py
57 lines (46 loc) · 1.61 KB
/
devopsstackinfoapi.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import boto3
import json
cf = boto3.client('cloudformation')
### RETURN BODY FOR API ###
def return_body(status_code, message):
body = {
'statusCode': str(status_code),
'body': json.dumps(message),
'headers': {
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
}
}
return body
def lambda_handler(event, context):
body = json.loads(event['body'])
print body
try:
devopsstack = body['devopsstackName']
if devopsstack == "":
status_code = 400
message = {"errorMessage": "devopsstackName cannot be empty"}
return_message = return_body(status_code, message)
return return_message
except KeyError:
status_code = 400
message = {"errorMessage": "devopsstackName needs to be mentioned"}
return_message = return_body(status_code, message)
return return_message
try:
resp = cf.describe_stacks(StackName=devopsstack)
tags = resp['Stacks'][0]['Tags']
print tags
for eachtag in tags:
if eachtag['Key'] == 'version':
version = eachtag['Value']
print version
status_code = 200
message = {"version": version}
return_message = return_body(status_code, message)
return return_message
except Exception as e:
status_code = 404
message = {"errorMessage": "Error Fetching the version of the DevOps Stack"}
return_message = return_body(status_code, message)
return return_message