Kum*_*nal 1 amazon-web-services amazon-dynamodb aws-cli
我正在编写一个 shell 脚本来从 dynamoDB 表中查询一个属性。我正在使用 AWS CLI 编写脚本。
我想从 MY_TABLE_NAME 中为 ReferenceId gfsdgrhfsh 找到 AccountId。当我在 AttributeValueList 中提供属性的确切值时,查询操作成功并获得正确的属性值。
aws dynamodb query --table-name MY_TABLE_NAME \
--select SPECIFIC_ATTRIBUTES --attributes-to-get "AccountId" \
--key-conditions '{"ReferenceId": {"AttributeValueList": [ {"S": "gfsdgrhfsh" } ], "ComparisonOperator": "EQ"} }' \
--limit 1 | jq '.Items[0].AccountId.S'
Run Code Online (Sandbox Code Playgroud)
上面的命令给了我正确的帐户 ID。
但是,当我将 ReferenceId gfsdgrhfsh 分配给一个变量,然后将该变量放入命令中时,我没有得到响应。
referenceId=gfsdgrhfsh
aws dynamodb query --table-name MY_TABLE_NAME \
--select SPECIFIC_ATTRIBUTES --attributes-to-get "AccountId" \
--key-conditions '{"ReferenceId": {"AttributeValueList": [ {"S": "$referenceId" } ], "ComparisonOperator": "EQ"} }' \
--limit 1 | jq '.Items[0].AccountId.S'
Run Code Online (Sandbox Code Playgroud)
有人可以建议如何在命令中注入变量的值。我必须通过从文件中读取它们来对大量 referenceId 执行查询操作,因此我需要在命令中注入变量值。
任何帮助,将不胜感激。
想通了,我们需要传递用双引号括起来的值。以下命令有效:
aws dynamodb query --table-name MY_TABLE_NAME \
--select SPECIFIC_ATTRIBUTES --attributes-to-get "AccountId" \
--key-conditions '{"ReferenceId": {"AttributeValueList": [ {"S": '\"$referenceId\"' } ], "ComparisonOperator": "EQ"} }' \
--limit 1 | jq '.Items[0].AccountId.S'
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1336 次 |
最近记录: |