I need to update values in DynamoDB, original value is a string, new value is a number.
The error returned
Parameter validation failed: Invalid type for parameter
ExpressionAttributeValues.:ttl.N, value: 1696989709, type: <class
‘int’>, valid types: <class ‘str’>
Command:
aws dynamodb update-item
--table-name my-datastore
--key '{"Id": {"N": "456"}}'
--update-expression "SET expire_at = :ttl"
--condition-expression "attribute_type(expire_at, :date_str)"
--expression-attribute-values '{":ttl": {"N": 1696989709}, ":date_str": {"S": "S"}}'
The column ‘expire_at’ is specified on DynamoDB as TTL
TimeToLiveSpecification:
AttributeName: expire_at
Enabled: true
Is there a way to update a string value to a number value?
2
Answers
You need to put quotes around your number value, same as you did for the key value. Numbers are passed in as strings.
As Jason stated, change the TTL value in expressionAttributeValues: