Using python in AWS Lambda, how do I put/get an item from a DynamoDB table?
In Node.js this would be something like:
dynamodb.getItem({
\"Key\": {\"f
full example:
import boto3
def lambda_handler(event, context):
client = boto3.client('dynamodb')
for record in event['Records']:
# your logic here...
try:
client.update_item(TableName='dynamo_table_name', Key={'hash_key':{'N':'value'}}, AttributeUpdates={"some_key":{"Action":"PUT","Value":{"N":'value'}}})
except Exception, e:
print (e)
please note that you need to decide when to use 'update_item' or 'put_item'.
with 'update_item' you ensure to have only one record with the same hash/range. if the record exists it can update this record, else it will create it
http://boto3.readthedocs.org/en/latest/reference/services/dynamodb.html#DynamoDB.Client.update_item