-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathhandler.py
More file actions
62 lines (48 loc) · 1.68 KB
/
handler.py
File metadata and controls
62 lines (48 loc) · 1.68 KB
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
58
59
60
61
62
import sys
import os
sys.path.append(f"{os.environ['LAMBDA_TASK_ROOT']}/lib")
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
import cr_response
import logic
import json
def lambda_handler(event, context):
print(f"Received event:{json.dumps(event)}")
lambda_response = cr_response.CustomResourceResponse(event)
cr_params = event['ResourceProperties']
print(f"Resource Properties {cr_params}")
# Validate input
for key in ['Path']:
if key not in cr_params:
lambda_response.respond_error(f"{key} property missing")
return
replace = cr_params.get('Update', True)
try:
parameter = logic.SSMSecureParameterLogic(cr_params['Path'])
length = 16 or cr_params['Length']
if event['RequestType'] == 'Create':
password, version = parameter.create(
length=length,
update=False
)
event['PhysicalResourceId'] = cr_params['Path']
lambda_response.respond(data={
"Password": password,
"Version": version
})
elif event['RequestType'] == 'Update':
password, version = parameter.create(
length=length,
update=replace
)
event['PhysicalResourceId'] = cr_params['Path']
lambda_response.respond(data={
"Password": password,
"Version": version
})
elif event['RequestType'] == 'Delete':
parameter.delete()
lambda_response.respond()
except Exception as e:
message = str(e)
lambda_response.respond_error(message)
return 'OK'