Created
March 18, 2016 14:34
-
-
Save kszarek/a7a7ed1acb33cc975cd3 to your computer and use it in GitHub Desktop.
Lambda-API-DynamoDB
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 print_function | |
import logging | |
import boto3 | |
import json | |
logger = logging.getLogger() | |
logger.setLevel(logging.INFO) | |
logger.info('Loading function') | |
def lambda_handler(event, context): | |
logger.info('got event{}'.format(event)) | |
logger.info('got context{}'.format(context)) | |
dynamo = boto3.resource('dynamodb').Table('weather') | |
dynamo.put_item( | |
Item={ | |
'Timestamp': 1400288400, | |
'AirportCode': 'AAL', | |
'temperature': 11, | |
'conditions': 'Scattered Clouds' | |
} | |
) | |
response = dynamo.get_item( | |
Key={ | |
'Timestamp': 1400288400, | |
'AirportCode': 'AAL' | |
} | |
) | |
item = response['Item'] | |
logger.info('Response from DynamoDB {}'.format(item)) | |
return item |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment