am using AmazonAwsCli to write a shell script to update an attribute in an item in a dynamodb table. I want to update an attribute in a table for multiple items. I am reading the attribute value from a file and am trying to update the table by injecting the value of the shell script variable in the command. The documentation available at http://docs.aws.amazon.com/cli/latest/reference/dynamodb/update-item.html suggests using separate json files for expression-attribute-names and expression-attribute-values. However, I do not want to create separate json files. Rather, I want to write one command to update an item for a given attribute value.
My table name = MY_TABLE_NAME
hashkey = AccountId
shell script variable holding the value of AccountId = accountId
attribute name that needs to be updated = Version
shell script variable holding the value of Version = ver
I have got something like :
aws dynamodb update-item --table-name MY_TABLE_NAME --key '{"AccountId": {"S": '$accountId'}}' --update-expression "SET Version = '{"Version": {"S": '$ver'}}'" --condition-expression "attribute_exists(Version)" --return-values UPDATED_NEW
But, the above command does not work. Can someone point me to the correct syntax.
My AwsCli version did not support --update-expression option. I used the attribute-updates option instead.
Here is my command :
updatedVersion=aws dynamodb update-item --table-name MY_TABLE_NAME --key '{"AccountId": {"S": '$accountId'}}' --attribute-updates '{"Version": {"Value": {"S": '$desiredVersion'},"Action": "PUT"}}' --return-values UPDATED_NEW | jq '.Attributes.RuleSetVersion.S'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With