Skip to content

Instantly share code, notes, and snippets.

@djg07
Created November 22, 2019 18:09
Show Gist options
  • Save djg07/301b24c519fcf537dee5567d477f784c to your computer and use it in GitHub Desktop.
Save djg07/301b24c519fcf537dee5567d477f784c to your computer and use it in GitHub Desktop.
import json
import boto3
from boto3.dynamodb.conditions import Key
def lambda_handler(event, context):
client = boto3.resource('dynamodb')
table = client.Table('Transactions')
#1. Example - Get Item By Id
response = table.get_item(
Key={
'TransactionType_OriginCountry': 'PURCHASE_USA',
'Date': '2019-11-17'
}
)
print(response['Item'])
print('\n\n\n-----\n\n\n')
#2. Example 2 - Query by Partition Key / Sort Key Criteria
response = table.query(
KeyConditionExpression=Key('TransactionType_OriginCountry').eq('PURCHASE_USA') & Key('Date').gt('2019-11-15')
)
items = response['Items']
for item in items:
print(item)
@VinciGit00
Copy link

also me :(

@danocolombo
Copy link

I was getting the same error as above. Found out since I was using index on my table, I had to specify...

response = table.query(
IndexName='clientId-meetingDate-index',
KeyConditionExpression=Key('clientId').eq('abc') & Key('meetingDate').gte('2022-05-05')
)

Of course change to your index, and attribute values, but after adding IndexName, all worked well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment