7

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?

1
  • 1
    if you are using windows, use powershell for this command Commented Dec 13, 2018 at 15:53

2 Answers 2

10

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'
Sign up to request clarification or add additional context in comments.

2 Comments

The documentation mentioned in this answer has moved to msys2.org/wiki/Porting
According to the documentation : "MSYS2_ARG_CONV_EXCL is a ; delimited string each part of which is compared against the front part of each argument and if a match is found, that conversion is skipped."
8

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)

2 Comments

I ran into the same issue trying to run a command similar to the following: aws cloudfront create-invalidation --distribution-id SOMEID --paths '/some/path/'. The shell tries to be helpful and convert the path to some local computer path but instead it mangles the cloud path. Adding MSYS_NO_PATHCONV=1 to the front of the aws command line worked. Adding the space did not work for me. Using a double slash at the front of the path also worked for me.
Also, without the fix, the aws cloudfront create-invalidation command shows a general message like the following: An error occurred (InvalidArgument) when calling the CreateInvalidation operation: Your request contains one or more invalid invalidation paths. I avoided the warning by adding an asterisk at the end of the original path, which hid the main problem and did not really solve the MinGW root issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.