我正在使用 AmazonAwsCli 编写一个 shell 脚本来更新 dynamodb 表中项目的属性。我想为多个项目更新表中的属性。我正在从文件中读取属性值,并尝试通过在命令中注入(inject) shell 脚本变量的值来更新表。 http://docs.aws.amazon.com/cli/latest/reference/dynamodb/update-item.html 上提供的文档建议对表达式属性名称和表达式属性值使用单独的 json 文件。但是,我不想创建单独的 json 文件。相反,我想编写一个命令来更新给定属性值的项目。
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
我有类似的东西:
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
但是,上面的命令不起作用。有人可以指出正确的语法。
最佳答案
我的 AwsCli 版本不支持 --update-expression 选项。我改用了属性更新选项。
这是我的命令:
更新版本= 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'
关于amazon-web-services - AWSCli dynamodb update-item 命令语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32835299/