Created
December 19, 2017 01:11
-
-
Save dzimine/279643fac9f99bf503dea6c802881346 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
# ./record_db/handler.py | |
import json | |
import logging | |
import os | |
import boto3 | |
dynamodb = boto3.resource('dynamodb') | |
logger = logging.getLogger() | |
logger.setLevel(logging.INFO) | |
def endpoint(event, context): | |
logger.info("Event received: {}".format(json.dumps(event))) | |
try: | |
event = event['body'] | |
event['email'] | |
except KeyError: | |
raise Exception("Couldn't create the record: `email` not found.") | |
table = dynamodb.Table(os.environ['DYNAMODB_TABLE']) | |
item = {k: event[k] for k in ['email', 'first_name', 'last_name']} | |
table.put_item(Item=item) | |
return { | |
"statusCode": 200, | |
"item": item | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment