LLL
LLL

Reputation: 3771

Windows git bash tries to resolve string as file when calling AWS CLI

I have a string parameter for AWS SSM CLI command that looks like a path to a file due to starting with a /. /path/to/my/param.

When I run the command on git bash it tries to find the file instead, no matter how I try to escape it:

aws ssm get-parameter --name "/path/to/my/param"

aws ssm get-parameter --name '/path/to/my/param'

aws ssm get-parameter --name '\/path\/to\/my\/param'

An error occurred (ValidationException) when calling the GetParameter operation: Invalid label format /Program Files/Git/path/to/my/param. A label name can't be prefixed with numbers, "ssm", or "aws" (case-insensitive). You can specify letters, numbers, and the following symbols: period (.), dash (-), or underscore (_).

Even tried back-ticks, then I get a bash error

aws ssm get-parameter --name `/path/to/my/param`

Error: bash: /path/to/my/param: No such file or directory

If I do echo /asd/asd it actually outputs /asd/asd, so it also might be how the aws cli is treating the input.

Any ideas how to escape it?

Upvotes: 7

Views: 2409

Answers (2)

Edit:

After stumbling upon this issue once more, but this time for: aws logs describe-log-groups --log-group-name-prefix ..., I decided to try 'n' find a more sustainable solution.

I found an SO post that provided an explanation for the underlying problem as well as what I believe to be a better fix, i.e.:

MSYS_NO_PATHCONV=1 aws ...

This goes for any aws cli command suffering from this forward slash problem when being called from Git Bash on Windows.

Kudos of course go to: https://stackoverflow.com/a/56034540

Seems like my first answer happens to work for aws ssm get-parameter because that part of the cli is a bit more forgiving in the sense that it returns the desired value, even when providing the leading space. However, upon further scrutiny of the returned value I noticed in retrospect that the name of the returned parameter also contains the leading space, making the solution of disabling path conversion - by far - the better option.


Original answer:

In case anyone bumps into this issue in the future:

I randomly managed to solve it while grasping at straws.

The trick for me was to put a space before the first forward slash after surrounding the parameter name with double quotes, i.e.:

aws ssm get-parameter --name " /path/to/my/param"

(The GitHub issue that led me to try it out: https://github.com/bmatzelle/gow/issues/196)

Upvotes: 8

zllvm
zllvm

Reputation: 136

It is possible to turn off a path conversion in MSYS2 for selected paths (see Msys2 Porting, Filesystem namespaces section).

You can also disable it temporarily in the following way:

 MSYS2_ARG_CONV_EXCL="/aws" aws ssm get-parameter --name '/aws/path/to/my/param'

Upvotes: 10

Related Questions