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.

Share Improve this question edited Nov 21, 2024 at 9:39 jonrsharpe 122k30 gold badges264 silver badges472 bronze badges asked Nov 21, 2024 at 8:32 cficfi 11.3k9 gold badges59 silver badges105 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 0

Inspired 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].

本文标签: