AWSCli dynamodb 更新项命令语法

Kum*_*nal 4 amazon-web-services amazon-dynamodb aws-cli

我正在使用 AmazonAwsCli 编写一个 shell 脚本来更新 dynamodb 表中项目的属性。我想为多个项目更新表中的属性。我正在从文件中读取属性值,并尝试通过在命令中注入 shell 脚本变量的值来更新表。http://docs.aws.amazon.com/cli/latest/reference/dynamodb/update-item.html 上的文档建议使用单独的 json 文件作为 expression-attribute-names 和 expression-attribute-values。但是,我不想创建单独的 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
Run Code Online (Sandbox Code Playgroud)

我有类似的东西:

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

但是,上面的命令不起作用。有人能指出我正确的语法吗?

Kum*_*nal 8

我的 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'


Arp*_*pan 5

下面是更新命令 --update-expression

 aws --region "us-east-1" dynamodb update-item \
 --table-name "MY_TABLE_NAME" --key \
 '{"Primary_Column_name":{"S":"Primary_Column_value"}}' \
 --update-expression 'SET #H = :h' \
 --expression-attribute-names '{"#H":"Column_name_to_change"}' \
 --expression-attribute-values '{":h":{"S":"Changed_Column_value"}}'
Run Code Online (Sandbox Code Playgroud)