File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 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 ))
You can’t perform that action at this time.
0 commit comments