skip to Main Content

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


  1. You need to put quotes around your number value, same as you did for the key value. Numbers are passed in as strings.

    Login or Signup to reply.
  2. As Jason stated, change the TTL value in expressionAttributeValues:

    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"}}'
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search