Error: dynamodb number_value cannot be converted to string

Answered by Rafal Wilinski
What's Causing This Error
This error message indicates an issue with the data type of an attribute in the item being stored or retrieved in DynamoDB. Specifically, it suggests that a number data type (such as an int or float) is being passed as an attribute value, but the attribute expects a string data type.
Solution: Here's How To Resolve It
To solve this error, check the data types of the item's attributes to ensure that they match the table's schema. For example, ensure that the attribute expecting a string data type is passed a string value.
You can convert the number value to a string before putting the item in the table.
import boto3 # Instantiate a client dynamodb = boto3.client('dynamodb', region_name='us-west-2') # Define the parameters table_name = "my_table" item = { 'primary_key': {'S': '12345'}, 'number_value': {'S': str(number_value)} } # Perform the operation dynamodb.put_item(TableName=table_name, Item=item)
Finally, check that the IAM user or role used to call the function has the necessary permissions to operate on the DynamoDB service.
Other Common DynamoDB Errors (with Solutions)
- DynamoDB local error unable to access JAR file dynamodblocal.jar
- DynamoDB ConditionalCheckFailedException
- name key is not defined dynamodb
- DynamoDB Not Supported Requires @DynamoDBTyped Or @DynamoDBTypeConverted
- failed to list tables not authorized dynamodb
- DynamoDB Key element does not match the schema
- DynamoDB Item Does Not Exist
- dynamodb mapper save not persisting
- boto3 dynamodb unable to locate credentials
- DynamoDB FilterExpression Not Working
- One or more parameter values were invalid: some AttributeDefinitions are not used
- dynamodb can not resolve withkeyconditionexpression
- DynamoDB Mapper Could Not Instantiate Class
- dynamodb botocore.exceptions.nocredentialserror unable to locate credentials
Login to the AWS Console less. Use Dynobase.
First 7 days are on us. No strings attached.
Product Features
DynamoDB Tools
DynamoDB Info
© 2025 Dynobase