admin管理员组文章数量:1123011
With the following query:
aws fsx describe-file-systems \
--no-paginate --no-cli-pager --output yaml \
--query 'FileSystems[].{id:FileSystemId,netid:NetworkInterfaceIds[0],name:Tags[?Key==`Name`].Value}'
the output lists the result of the search in the tags in an extra level of hierarchy:
- id: fs-1234abcd
name:
- home
netid: eni-1234abcde
I would like to have a flat structure like this:
- id: fs-1234abcd
name: home
netid: eni-1234abcde
This would make it easier to display a table of objects or do further queries. I tried the usual flatten operator []
but that wouldn't remove that extra level.
With the following query:
aws fsx describe-file-systems \
--no-paginate --no-cli-pager --output yaml \
--query 'FileSystems[].{id:FileSystemId,netid:NetworkInterfaceIds[0],name:Tags[?Key==`Name`].Value}'
the output lists the result of the search in the tags in an extra level of hierarchy:
- id: fs-1234abcd
name:
- home
netid: eni-1234abcde
I would like to have a flat structure like this:
- id: fs-1234abcd
name: home
netid: eni-1234abcde
This would make it easier to display a table of objects or do further queries. I tried the usual flatten operator []
but that wouldn't remove that extra level.
1 Answer
Reset to default 0Inspired by this answer, I now got it:
aws fsx describe-file-systems \
--no-paginate --no-cli-pager --output yaml \
--query 'FileSystems[].{id:FileSystemId,netid:NetworkInterfaceIds[0],name:Tags[?Key==`Name`].Value|[0]}'
I tried adding the [0]
to dereference the first element of the resulting list of one tag, but then the query returned (null)
. Adding the pipe |
does the trick.
The manual states that
A pipe-expression stops projections on the left hand side for propagating to the right hand side. If the left expression creates a projection, it does not apply to the right hand side.
If I understand this correctly, because I did a query of the Tags[?...]
I created a projection. To get the first element of it, I've got to stop the projection from propagating with the |
, and then refer to the first element with [0]
.
本文标签:
版权声明:本文标题:aws cli - How can I perform a hierarchical query with the AWS CLI for specific tags and output the result in a flat structure? - 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736538694a1944356.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论