amazon-web-servicesamazon-dynamodbdynamodb-queries

AWS cli - DynamoDb batch-execute-statement return Expected identifier for simple path


I am trying to initially update an item in a table by using the batch-execute-statement as the first try and when that succeeds , add more statements in the file that holds these statements. As of now I have the following

[
  {
    "Statement": "UPDATE 'table_t268468eaf8b64c7b9d3eb2655e98ebd5' SET x=1678976403 WHERE Key='e1c09d48-fdc5-41eb-8ca2-f7b4ff8a01c5' and anotherColumn='e1c09d48-fdc5-41eb-8ca2-f7b4ff8a01c5'"
  }
]

But when running the following

aws dynamodb batch-execute-statement --statements file://batch-execute.json

I am always getting the following error

{
    "Responses": [
        {
            "Error": {
                "Code": "ValidationError",
                "Message": "Statement wasn't well formed, can't be processed: Expected identifier for simple path"
            }
        }
    ]
}

Do you have any idea why ? From what I can see in other examples and documentation I have the right syntax.

Thanks in advance.


Solution

  • The Key attribute name in your query is actually a DynamoDB reserved word so you'll have to escape and quote it, for example:

    SET \"Key\"='fred'
    

    Also, I don't believe that single quotes are allowed with table names (at least they fail for me) so remove the quotes surrounding the table name, for example:

    [
      {
        "Statement": "UPDATE table1 SET x=2 WHERE \"Key\"='3' and anotherColumn='4'"
      }
    ]
    

    Alternatively, use escaped double-quotes around the table name, for example:

    [
      {
        "Statement": "UPDATE \"table1\" SET x=2 WHERE \"Key\"='3' and anotherColumn='4'"
      }
    ]
    

    Finally, ensure that your WHERE clause includes an equality test on all of the primary key attributes (partition key and optional sort key).