I am writing a shell script to query an attribute from dynamoDB table. I am using AWS CLI to write the script.
I want to find AccountId from MY_TABLE_NAME for ReferenceId gfsdgrhfsh. When I supply the exact value of the attribute in the AttributeValueList, the query operation succeeds and I get the correct attribute value.
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'
The above command gives me the correct account id.
However, when I am assigning the ReferenceId gfsdgrhfsh to a variable and then putting this variable in the command, I am not getting a response.
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'
Can someone please advise on how to inject the value of the variable in the command. I have to perform query operation for lots of referenceIds by reading them from a file, so I need to inject the variable value in the command.
Any help would be appreciated.
Aucun commentaire:
Enregistrer un commentaire