Skip to content

Instantly share code, notes, and snippets.

@mholmes-hs
Created May 28, 2020 19:08
Show Gist options
  • Save mholmes-hs/3cd9f75141a2eb619af0f7492d87afcc to your computer and use it in GitHub Desktop.
Save mholmes-hs/3cd9f75141a2eb619af0f7492d87afcc to your computer and use it in GitHub Desktop.
Query example using GSI
import boto3
from boto3.dynamodb.conditions import Key
def query_data_with_gsi():
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('Employees')
response = table.query(
IndexName='email',
KeyConditionExpression=Key('email').eq('jdoe@test.com')
)
print(response['Items'][0])
#{'last_name': 'Doe', 'email': 'jdoe@test.com', 'first_name': 'Jon', 'emp_id': Decimal('1')}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment