String Number Table
import boto3
dynamodb = boto3.resource('dynamodb')
TABLE_NAME = 'YourTableName'
PRIMARY_KEY_NAME = 'YourPrimaryKeyName'
RANGE_KEY_NAME = 'YourRangeKeyName'
def query_table(primary_key_value, range_key_value):
"""
Query the DynamoDB table based on primary and range key values.
Args:
- primary_key_value (str): The value of the primary key to query.
- range_key_value (int): The value of the range key to query.
Returns:
- list: A list of items that match the query.
"""
table = dynamodb.Table(TABLE_NAME)
response = table.query(
KeyConditionExpression=boto3.dynamodb.conditions.Key(PRIMARY_KEY_NAME).eq(primary_key_value) &
boto3.dynamodb.conditions.Key(RANGE_KEY_NAME).eq(range_key_value)
)
return response['Items']
if __name__ == "__main__":
primary_key_value = "YourPrimaryKeyValue"
range_key_value = 12345
items = query_table(primary_key_value, range_key_value)
for item in items:
print(item)