-
Notifications
You must be signed in to change notification settings - Fork 0
/
biosteamGetter.py
49 lines (43 loc) · 1.28 KB
/
biosteamGetter.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
# import json
# def lambda_handler(event, context):
# # TODO implement
# return {
# 'statusCode': 200,
# 'body': json.dumps('Hello from Lambda!')
# }
import json
import boto3
dynamodb = boto3.client('dynamodb')
# =============================================================================
#biosteamGetter function gets data stored in dynamoDB table "biosteamResults" by
#jobId lookup
# =============================================================================
def lambda_handler(event, context):
#Read postId from event
print(event)
jobId = event['jobId']
print('jobId', jobId)
#check if item exists and get corresponting item or throw error
try:
response = dynamodb.get_item(
TableName='biosteam-results',
Key={
'jobId': {'S': jobId}
}
)
item = response['Item']
except:
item = "no data"
print('item ', item)
return {
'statusCode': 200,
"headers": {
'Access-Control-Allow-Headers': 'Content-Type',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'OPTIONS,POST,GET'
},
'body': json.dumps({
'item': item,
'jobId': jobId,
})
}