"The provided key element does not match the schema" error when getting an item from DynamoDB
Full error message
This is the table partition key setting
The table content
When I tried to get an item from the table, it prints this error
botocore.exceptions.ClientError: An error occurred
(ValidationException) when calling the GetItem operation: The provided
key element does not match the schema
This is my code
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('testDynamodb')
response = table.get_item(Key={'userId': "user2873"})
item = response['Item']
print(item)
Any ideas? thanks.Solutionsource: stackoverflow \u2197
Your table schema has both hash key and sort key defined. When using DynamoDB GetItem you must provide both of them, here is an excerpt from documentation For the primary key, you must provide all of the attributes. For example, with a simple primary key, you only need to provide a value for the partition key. For a composite primary key, you must provide values for both the partition key and the sort key. So given your example, here is how get_item parameters should look like: response = table.get_item(Key={'userId': "user2873", 'createdAt': "1489376547"})
API access
Get this solution programmatically \u2014 free, no authentication.
curl https://depscope.dev/api/error/3b2080a88cc135bcabdf91dcc37790676cb44914c4fe14e2e8b219e32bd454bchash \u00b7 3b2080a88cc135bcabdf91dcc37790676cb44914c4fe14e2e8b219e32bd454bc