How do I use a variable with an AWS query??
There does not seem to documentation on the query syntax, mearly examples.
Im trying to do the following:
API_ID=$(aws apigateway get-rest-apis --query 'items[?name == `${API_NAME}`] | [0].{id: id}' --output text)
The problem is that ${API_NAME} is read literally. Any ideas?
The AWS Command Line Interface (AWS CLI) examples in this guide are formatted using the following conventions: Prompt – The command prompt uses the Linux prompt and is displayed as ( $ ). For commands that are Windows specific, C:\> is used as the prompt. Do not include the prompt when you type commands.
The table format produces human-readable representations of complex AWS CLI output in a tabular form. You can combine the --query option with the table format to display a set of elements preselected from the raw output.
json/array. This option produces raw JSON wrapped in a JSON array. You can select these output formats by starting MySQL Shell with the --result-format= value command line option, or setting the MySQL Shell configuration option resultFormat .
I figured this out after sometime...
AWS uses JMESPath, as the spec for their --query
option.
When passing jmespath filter expression as a string:
You can use double quotes (") instead and wrap the variable in single quotes ('). This will not prevent the variable from being replaced.
So it worked when I changed it to:
API_ID=$(aws apigateway get-rest-apis --query "items[?name == '${API_NAME}'] | [0].{id: id}" --output text)
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