Search code examples
jsonamazon-web-servicesaws-clijmespathamazon-efs

What is the best way to query the following file systems for a specific file system ID?


On my AWS account I have four file systems. In creating each of these file systems, I have given each on a tag Name. I would like to use the AWS CLI to filter out the one with a specific name, and retrieve its file system id.

I have already tried looking in JMESPath in order to filter out the one specific file system, but it seems the structure of my query as well as the structure of the output is a bit difficult for me to work with.

Here is my query so far:

aws efs describe-file-systems --query FileSystems[?Name=='dev-four'].FileSystemId --region us-east-1 --output text

Ideally, I would get the file system id as a single string, but I keep getting the error:

Bad value for --query FileSystems[?Name==dev-sg].FileSystemId: Bad jmespath expression: Unknown token '-':
FileSystems[?Name==dev-four].FileSystemId

I am not sure how to do the JMES a different way.


Solution

  • I think you should escape the query. Instead of using single-quotes around dev-four, try using escaped back-ticks. jmespath can be quirky about escape sequence.

    --query FileSystems[?Name == \`dev-spring\`].FileSystemId
    

    On my mac, I need the back slashes. Try the query with and without them, it may affect the result. More detail here