'Git bash will not resolve "sam" command

I am using Win10 latest. After installing AWS-SAM-CLI and testing the installation with:

sam --version

I get the message

bash: sam: command not found

however, when I use Powershell, cmd or ConEmu they can all resolve "sam".

the path is "e/Program Files/Amazon/AWSSAMCLI/bin" but other commands like "yarn" work fine which is also installed at "e/Program Files/..."

Any ideas? Thanks



Solution 1:[1]

sam.cmd --version

The windows version of the SAM CLI does not have a direct executable binary. It is instead a .cmd script that echos your options to the python executable.

@rem
@echo off

setlocal

"%~dp0/../runtime/python.exe" -m samcli %*

I haven't figured out how to make it work with

sam --version

My assumption is that powershell and command prompt see .cmd as an executable not requiring an extension where git bash does not.

Solution 2:[2]

Here is how I got it work with an alias. alias sam="/c/Program\ Files/Amazon/AWSSAMCLI/bin/sam.cmd"

Solution 3:[3]

While the alias worked when invoking sam straight from the command line it wouldn't work in scripts that I was using.

To fix this for both instances I found that I needed to add a shell script equivalent of the installed .cmd script, named sam, in the same folder as it, typically C:\Program Files\Amazon\AWSSAMCLI\bin:

#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
    *CYGWIN*|*MINGW*|*MSYS*) basedir=`cygpath -w "$basedir"`;;
esac

"$basedir/../runtime/python.exe" -m samcli "$@"
ret=$?
exit $ret

Solution 4:[4]

$ vi ~/.bashrc  # or favorite editor

Add:

alias sam='sam.cmd'

Then:

$ source ./.bashrc # can use '. ./.bashrc

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 James Pickett
Solution 2 Clinton White
Solution 3 Andrew Willis
Solution 4 Ethan