forked from scottythered/exlibris-status-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebAPI.py
37 lines (34 loc) · 1009 Bytes
/
webAPI.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
#!/usr/bin/env python
# coding: utf-8
import json
import boto3
import os
def handler(event, context):
headers = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Credentials": True,
}
try:
dynamodb = boto3.resource(
"dynamodb",
region_name=os.environ["region_name"],
aws_access_key_id=os.environ["access_key"],
aws_secret_access_key=os.environ["secret_access"],
)
table = dynamodb.Table(os.environ["table"])
response = table.get_item(Key={"product": "Primo"})
return {
"statusCode": 200,
"headers": headers,
"body": json.dumps(response["Item"]),
}
except:
return {
"statusCode": 500,
"headers": headers,
"body": json.dumps(
{
"result": "An error has occurred, please check with your local library developer."
}
),
}