如何在 AWS 查询中使用变量?
似乎没有关于查询语法的文档,只有示例。
我正在尝试执行以下操作:
API_ID=$(aws apigateway get-rest-apis --query 'items[?name == `${API_NAME}`] | [0].{id: id}' --output text)
问题是 ${API_NAME} 是按字面意思读取的。有什么想法吗?
最佳答案
一段时间后我想通了......
AWS 使用 JMESPath ,作为其 --query
选项的规范。
将 jmespath 过滤器表达式作为字符串传递时:
You can use double quotes (") instead and wrap the variable in single quotes ('). This will not prevent the variable from being replaced.
所以当我把它改成:
API_ID=$(aws apigateway get-rest-apis --query "items[?name == '${API_NAME}'] | [0].{id: id}" --output text)
关于bash - 如何在 AWSCLI 查询中使用 cli 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35301545/