bash - 如何在 AWSCLI 查询中使用 cli 变量

标签 bash aws-cli

如何在 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/

相关文章:

bash - shell 脚本可以设置调用 shell 的环境变量吗?

amazon-web-services - 为什么使用 CLI 启动的 Amazon EMR 集群没有显示在 Web 控制台中?

amazon-web-services - AWS CLI 和 JMESPath 过滤并选择嵌套属性

powershell - aws-cli (powershell) import-image 缺少必需参数 disk-images

node.js - 解释 'DEBUG=myapp:* npm start' 实际上在做什么

linux - 为什么会在这里得到模糊重定向的错误?

Bash:在执行 bash 之前等待产生的子进程

amazon-web-services - 使用 AWS CloudFormation 更新 SNS 订阅的替代方案

amazon-web-services - 如何将 ELB 指向由服务发现定义的域

linux - 如果找到关键字,则在行尾附加文件名的一部分