Amazon web services AWS CLI-使用jmespath查询的结果
我有个问题,所以你会保护我的生命:-) 当我从aws shell运行以下命令时Amazon web services AWS CLI-使用jmespath查询的结果,amazon-web-services,aws-cli,jmespath,aws-shell,Amazon Web Services,Aws Cli,Jmespath,Aws Shell,我有个问题,所以你会保护我的生命:-) 当我从aws shell运行以下命令时 cloudformation describe-stacks --query Stacks[*].[StackName,StackId,CreationTime,LastUpdatedTime,Parameters[?ParameterKey==\`PARAM_NAME1\`].ParameterValue,Parameters[?ParameterKey==\`PARAM_NAME2\`].ParameterVal
cloudformation describe-stacks --query Stacks[*].[StackName,StackId,CreationTime,LastUpdatedTime,Parameters[?ParameterKey==\`PARAM_NAME1\`].ParameterValue,Parameters[?ParameterKey==\`PARAM_NAME2\`].ParameterValue] --output text
结果分为3行:
自动化-X arn:aws:cloudformation:X X无参数值1
参数值2 但我的目标是只有一行(像这样) 自动化-X arn:aws:cloudformation:X X无参数值1参数值2 也就是说,在第一行(也是唯一一行)上有PARAM_VALUE1和PARAM_VALUE2 有人能帮我吗 我很感激, 先谢谢你 我忘了指出命令的结果是多行(超过1000行),每行由6个参数组成
Parameters[?ParameterKey==`PARAM_VALUE1`].ParameterValue
返回一个投影,该投影本身返回一个ParameterValue
s的数组。即使该数组只包含一个项,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]
添加到查询中的每个参数。为什么不试试“|tr-d'\n'”谢谢@sashok\u bg不幸的是,它不起作用。。。。它将所有内容都写在一行上:-(