Created
May 24, 2018 11:34
-
-
Save adhorn/f2b6a36c84dc2e2e0077788966e32e96 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import unicode_literals | |
import sys | |
import logging | |
import boto3 | |
import os | |
log = logging.getLogger() | |
log.setLevel(logging.DEBUG) | |
sys.path.insert(0, './vendored') | |
import simplejson as json | |
# simplejson can handle Decimal object while the \ | |
# standard json package can't. | |
region = os.environ["AWS_REGION"] | |
dynamodb = boto3.resource('dynamodb', region_name=region) | |
table = dynamodb.Table('global2') | |
def get_from_dynamo(event): | |
log.debug("Received in get_from_dynamo: {}".format(json.dumps(event))) | |
item_id = event['pathParameters']['item_id'] | |
log.debug("item_id: {}".format(item_id)) | |
item = table.get_item( | |
Key={ | |
'item_id': item_id, | |
} | |
) | |
return item['Item'] | |
def get_item(event, context): | |
log.debug("Received event in get_item: {}".format(json.dumps(event))) | |
body = { | |
"item_id": get_from_dynamo(event), | |
} | |
response = { | |
"statusCode": 200, | |
"body": json.dumps(body) | |
} | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment