-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_event_from_dynamodb.py
45 lines (36 loc) · 999 Bytes
/
get_event_from_dynamodb.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
# this is an AWS Lambda function that will query DynamoDB and return
# a single event. it is designed to be called by an API Gateway
# resource in the following format:
#
# GET /event/{id}
#
# see
#
# img/api_gateway.png
#
# for an example setup.
# python 2.7
import json
import boto3
DYNAMODB_TABLE = 'events'
def lambda_handler(event, context):
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table(DYNAMODB_TABLE)
try:
event_id = event['pathParameters']['id']
print("event_id: {}".format(event_id))
response = table.get_item(Key={
'event_id':event_id
})
return {
"statusCode": 200,
"headers": {"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET,OPTIONS"
},
"body": json.dumps(response['Item'])
}
except:
return {
"statusCode": 404
}