We have a DynamoDB table with a partition key and sort key. Both the keys are Number type. I am trying to insert items using the PutItem API of the boto3 DynamoDB client. I am getting the below error;
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\satis\Anaconda3\envs\py369\lib\site-packages\botocore\client.py", line 316, in _api_call
return self._make_api_call(operation_name, kwargs)
File "C:\Users\satis\Anaconda3\envs\py369\lib\site-packages\botocore\client.py", line 599, in _make_api_call
api_params, operation_model, context=request_context)
File "C:\Users\satis\Anaconda3\envs\py369\lib\site-packages\botocore\client.py", line 647, in _convert_to_request_dict
api_params, operation_model)
File "C:\Users\satis\Anaconda3\envs\py369\lib\site-packages\botocore\validate.py", line 297, in serialize_to_request
raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid type for parameter Item.doc_id.N, value: 1234, type: <class 'int'>, valid types: <class 'str'>
Invalid type for parameter Item.passage_id.N, value: 1, type: <class 'int'>, valid types: <class 'str'>
The error does not make sense as the value for the sort key I am inserting is an integer and matches with the Number type of the dynamodb. The error clearly states that the value type is an integer but the required type is a string. Not sure what I am missing here.
Following is the data I am trying to insert;
{'doc_id': {'N': 1234}, 'passage_id': {'N': 1}, 'text': {'S': 'some text to insert'}, 'urls': {'S': '[]'}, 'html': {'S': '<p>this is para</p>'}}
Following is the code I am using to insert above dictionary;
import boto3
dynamodb_client=boto3.client('dynamodb',region_name='region_name')
dynamodb_client.put_item(TableName='table_name',Item=data)
To reiterate, both the key viz. doc_id and passage_id are Number type in dynamodb.
Appreciate the help.