我有一个问题,所以你会保护我的生命:-)
当我从 aws-shell 运行以下命令时
cloudformation describe-stacks --query Stacks[*].[StackName,StackId,CreationTime,LastUpdatedTime,Parameters[?ParameterKey==\`PARAM_NAME1\`].ParameterValue,Parameters[?ParameterKey==\`PARAM_NAME2\`].ParameterValue] --output text
结果分为 3 行:
automation-X arn:aws:cloudformation:X X None
PARAM_VALUE1
PARAM_VALUE2
但我的目标是只有一行(像这样)
automation-X arn:aws:cloudformation:X X None PARAM_VALUE1 PARAM_VALUE2
也就是说,PARAM_VALUE1 和 PARAM_VALUE2 位于第一行也是唯一一行。
谁能帮我吗?
我很感激, 预先感谢您
忘了说明,命令的结果很多行(超过1000行),每行由6个参数组成
最佳答案
表达式
Parameters[?ParameterKey==`PARAM_VALUE1`].ParameterValue
返回一个投影,该投影本身返回 ParameterValue
的数组。即使该数组仅包含一项,aws --output text
模式仍将其解释为新行。要解决此问题,您需要使用管道 |
将投影转换为单个值以停止投影,然后选择数组中的第一项:
aws cloudformation describe-stacks --query 'Stacks[*].[StackName,StackId,CreationTime,LastUpdatedTime,Parameters[?ParameterKey==`PARAM_NAME1`].ParameterValue|[0],Parameters[?ParameterKey==`PARAM_NAME2`].ParameterValue|[0]]' --output text
您将看到添加到查询中每个参数的 |[0]
。
关于amazon-web-services - AWS CLI - 使用 jmespath 查询的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54557184/