Skip to content

Commit 1d44935

Browse files
committed
Create main.py
1 parent e8297fa commit 1d44935

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

main.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from __future__ import print_function
2+
3+
import boto3
4+
import json
5+
6+
dynamo_ = boto3.resource('dynamodb')
7+
8+
def lambda_handler(event, context):
9+
'''Provide an event that contains the following keys:
10+
11+
- operation: one of the operations in the operations dict below
12+
- tableName: required for operations that interact with DynamoDB
13+
- payload: a parameter to pass to the operation being performed
14+
'''
15+
#print("Received event: " + json.dumps(event, indent=2))
16+
17+
operation = event['operation']
18+
19+
if 'tableName' in event:
20+
dynamo = dynamo_.Table(event['tableName'])
21+
22+
operations = {
23+
'create': lambda x: dynamo.put_item(**x),
24+
'read': lambda x: dynamo.get_item(**x),
25+
'update': lambda x: dynamo.update_item(**x),
26+
'delete': lambda x: dynamo.delete_item(**x),
27+
'list': lambda x: dynamo.scan(**x),
28+
'echo': lambda x: x,
29+
'ping': lambda x: 'pong'
30+
}
31+
32+
if operation in operations:
33+
operations[operation](event.get('payload'))
34+
else:
35+
raise ValueError('Unrecognized operation "{}"'.format(operation))

0 commit comments

Comments
 (0)