-
Notifications
You must be signed in to change notification settings - Fork 1
/
custom-resource-handler.py
35 lines (28 loc) · 1.16 KB
/
custom-resource-handler.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
# used python cause i pulled in some hello world example that used it
import boto3
def main(event, context):
import logging as log
import cfnresponse
log.getLogger().setLevel(log.INFO)
# This needs to change if there are to be multiple resources in the same stack
physical_id = 'TheOnlyCustomResource'
# shows we can interact with the dynamo api
client = boto3.client('dynamodb')
result = client.describe_table(
TableName='prodEventsTable'
)
try:
log.info(f'Input event: {event}')
log.info(f'result: {result}')
# Check if this is a Create and we're failing Creates
if event['RequestType'] == 'Create' and event['ResourceProperties'].get('FailCreate', False):
raise RuntimeError('Create failure requested')
# Do the thin
attributes = {
'Response': 'You said foooo'
}
cfnresponse.send(event, context, cfnresponse.SUCCESS, attributes, physical_id)
except Exception as e:
log.exception(e)
# cfnresponse's error message is always "see CloudWatch"
cfnresponse.send(event, context, cfnresponse.FAILED, {}, physical_id)