Git bash will not resolve "sam" command
Asked Answered
L

5

27

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

Lase answered 19/7, 2020 at 22:59 Comment(2)
You can use alias sam="sam.cmd" if it works in normal cmd. Now sam --version should work.Defunct
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 hereTempura
P
41
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.

Phthisis answered 23/7, 2020 at 19:9 Comment(3)
You can make it work without the .cmd extension by adding an alias in your .bashrc: https://mcmap.net/q/505230/-add-aliases-to-bash-terminal-from-inside-of-vscSempiternal
The fact that this is not in docs for installation is annoyingKurtiskurtosis
Thanks @Sempiternal I literally just did alias sam='sam.cmd', and it's working great. :)Bonded
R
26

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

Reckoner answered 5/3, 2021 at 19:22 Comment(3)
While the alias worked when invoking sam straight from the command line it wouldn't work in scripts. After following the above step to make them work in scripts use 'sam.cmd' instead of 'sam'Henrieta
where are you adding the alias? in vs code or somewhere else?Ottinger
Just run this in the cli (i.e. git bash)Stoffel
S
8
$ vi ~/.bashrc  # or favorite editor

Add:

alias sam='sam.cmd'

Then:

$ source ./.bashrc # can use '. ./.bashrc
Sarco answered 7/4, 2022 at 18:0 Comment(0)
B
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
Burkley answered 11/8, 2021 at 13:13 Comment(0)
P
1
  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.
Phosphatize answered 29/3, 2023 at 13:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.