-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
54 lines (49 loc) · 1.55 KB
/
app.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import boto3
import json
def handler(event, context):
try:
body = ""
client = boto3.resource('dynamodb')
table = client.Table('python-service-db')
if event['routeKey'] == "GET /items":
res = table.get_item(
Key = {
'id': event['queryStringParameters']['id']
}
)
body = res['Item']
if event['routeKey'] == "POST /items":
table.put_item(
Item = {
'id': event['queryStringParameters']['id'],
'firstName': event['queryStringParameters']['firstName'],
'lastName': event['queryStringParameters']['lastName']
}
)
body = {
'message': 'Successfully added!'
}
if event['routeKey'] == "DELETE /items":
id = event['queryStringParameters']['id']
table.delete_item(
Key = {
'id': id
}
)
body = {
'message': 'Successfully deleted ID: ' + id
}
if body == "":
return json.dumps({
'statusCode': 400,
})
else:
return json.dumps({
'statusCode': 200,
'body': body
})
except Exception as e:
return json.dumps({
'statusCode': 400,
'message': str(e)
})