Reputation: 972
When I use the client to get_item from a table using Key it works fine. If I try the same with Resource I get error. Whats going wrong here
>>> ddbr = boto3.resource('dynamodb')
>>> table = ddbr.Table('employees')
>>> table.get_item(Key={'EmpId': {'S': '13456789ABC'}})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/qwert/miniconda2/envs/pyenv36/lib/python3.6/site-packages/boto3/resources/factory.py", line 520, in do_action
response = action(self, *args, **kwargs)
File "/Users/qwert/miniconda2/envs/pyenv36/lib/python3.6/site-packages/boto3/resources/action.py", line 83, in __call__
response = getattr(parent.meta.client, operation_name)(**params)
File "/Users/qwert/miniconda2/envs/pyenv36/lib/python3.6/site-packages/botocore/client.py", line 312, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/Users/qwert/miniconda2/envs/pyenv36/lib/python3.6/site-packages/botocore/client.py", line 601, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the GetItem operation: The provided key element does not match the schema
Upvotes: 0
Views: 1434
Reputation: 78850
Boto3 provides two service abstractions:
And there are two corresponding DynamoDB get_item methods:
If you read the documentation for each method you will see that they expect the item key to be provided in two different ways (in my example I'm assuming it's a string):
There's a good Introduction to Version 3 of the AWS SDK for Python video.
Upvotes: 1
Reputation: 970
No need to declare the type in dynamo Json format; boto does that for you. If your table’s partition key is named ‘EmpId’ and is of type string your get item call should look like
table.get_item(Key={'EmpId':'13456789ABC'})
Upvotes: 2