26

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

Blobafet
  • 419
  • 1
  • 7
  • 13
  • 11
    You can use `alias sam="sam.cmd"` if it works in normal cmd. Now `sam --version` should work. – Nikolai Mar 19 '21 at 12:17
  • it can also be set to create the alias on terminal open, like with `echo 'alias sam="sam.cmd"' >> ~/.bashrc` for e.g. ; some more thoughts on that [here](https://superuser.com/questions/602872/how-do-i-modify-my-git-bash-profile-in-windows?newreg=11a9bb92102040fc83225f509c48b46f) – mud Jul 04 '23 at 12:15

5 Answers5

36
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.

James Pickett
  • 476
  • 4
  • 3
23

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

Clinton White
  • 231
  • 2
  • 2
7
$ vi ~/.bashrc  # or favorite editor

Add:

alias sam='sam.cmd'

Then:

$ source ./.bashrc # can use '. ./.bashrc
Ethan
  • 876
  • 8
  • 18
  • 34
SpiesInOrbit
  • 81
  • 1
  • 1
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
0
  1. Try uninstalling and reinstalling the SAM CLI. You can do this by running the following commands:
pip uninstall aws-sam-cli
pip install aws-sam-cli
  1. Check the version of Python you're using. The SAM CLI requires Python 3.6 or later. You can check your Python version by running the command python --version. If you're using an earlier version of Python, you'll need to upgrade to a later version.
cng.buff
  • 405
  • 4
  • 5