Created
October 1, 2019 01:16
-
-
Save garystafford/8654781a4657d156dd5529ea90618ccf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def lambda_handler(event, context): | |
operations = { | |
'DELETE': lambda dynamo, x: dynamo.delete_item(**x), | |
'POST': lambda dynamo, x: dynamo.put_item(**x), | |
'PUT': lambda dynamo, x: dynamo.update_item(**x), | |
'GET': lambda dynamo, x: dynamo.get_item(**x), | |
'GET_ALL': lambda dynamo, x: dynamo.scan(**x), | |
} | |
for record in event['Records']: | |
payload = loads(record['body'], parse_float=str) | |
operation = record['messageAttributes']['Method']['stringValue'] | |
if operation in operations: | |
try: | |
operations[operation](dynamo_client, payload) | |
except Exception as e: | |
logger.error(e) | |
else: | |
logger.error('Unsupported method \'{}\''.format(operation)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment