dynamodb queries

diary of a codelovingyogi
1 min readMay 9, 2020

connect to dynamodb via boto3 and make queries

import boto3
from boto3.dynamodb.conditions import Key, Attr
dynamo = boto3.resource('dynamodb')
table = dynamo.Table(table)

add item

item = {"table_key_name": "table_key_id", "attribute": "attribute value"}response = table.put_item(Item=item)
print('finished writing to table')
return response

query by multiple keys

key_condition_exp_query = Key("table_key_name").eq(table_key_id) & Key ("another_table_key_name").eq("another_table_key_id")response = table.query(KeyConditionExpression=key_condition_exp_query)

print(response['Items'])

--

--