Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws command not found #82

Open
Shion093 opened this issue Jul 4, 2018 · 6 comments
Open

aws command not found #82

Shion093 opened this issue Jul 4, 2018 · 6 comments

Comments

@Shion093
Copy link

Shion093 commented Jul 4, 2018

Hi everyone,

I'm having a problem with my scripts, one of the uses the aws command to retrieve variables stored on SSM, something like this

aws ssm get-parameters-by-path \ --path "/keys" \ --with-decryption \ --query "Parameters[*].[Name,Value]" \ --output text

I have aws cli installed on my EC2 Ubuntu instance, and the script works just fine if run from the terminal, but not from codedeploy scripts.

What would be the correct approach to accomplish this?

Thanks

@bedge
Copy link

bedge commented Jul 4, 2018

Check whether you're using bash or the default #!/bin/sh for the script.
That impacts syntax compatibility as well as using a different $PATH.
One solution could be to put this at the top of your script:

#!/bin/bash
PATH="/usr/local/bin:$PATH"

...assuming the aws binary lives in /usr/local/bin.

@Shion093
Copy link
Author

Shion093 commented Jul 4, 2018

Thanks for the fast reply, I've tried your solution, in my case awscli lives here
/home/ubuntu/.local/bin/aws

Added this to the script but didn't work

#!/bin/bash
PATH="/home/ubuntu/.local/bin:$PATH"

It throws these errors

Traceback (most recent call last):
[2018-07-04 22:27:07.602] [d-CK8PAP73U][stderr]  File "/home/ubuntu/.local/bin/aws", line 19, in <module>
[2018-07-04 22:27:07.602] [d-CK8PAP73U][stderr]    import awscli.clidriver
[2018-07-04 22:27:07.602] [d-CK8PAP73U][stderr]ImportError: No module named awscli.clidriver

I installed the awscli with pip.

@bedge
Copy link

bedge commented Jul 4, 2018

np, we've all been there.

I'm guessing you're using some virtual env wrapper for your python installation given the ~/.local/bin PATH.
These usually require that you source some env setup that adds the appropriate PYTHONPATH to your shell's env.
I expect there's probably something in one of the bash init scripts, ~/.bashrc ~/.bash_profile etc. If it's in .bashrc, that would explain it, as IIRC, that's only sourced by interactive login shells, whereas .bash_profile is sourced by all.

Or, from an interactive shell, where the aws command works, loo at the env output and see what you're missing.
One way to sort that out is to add an 'env' command to the top of the codedeploy script so you can see what's set in that context.

@Shion093
Copy link
Author

Shion093 commented Jul 5, 2018

Yeah, you're right. I have this export PATH=~/.local/bin:$PATH in ~/.bashrc

This is the path on the script

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/snap/bin

And this is the path on the terminal

PATH=/home/ubuntu/bin:/home/ubuntu/.local/bin:/home/ubuntu/.local/bin:/home/ubuntu/.nvm/versions/node/v8.9.4/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

But adding the PATH manually doesn't seem to work. Already tried that with
PATH="/home/ubuntu/.local/bin:$PATH"

@bedge
Copy link

bedge commented Jul 5, 2018

It's not PATH, it's the python virtualenv setup.
Try looking at env | grep -i python.

@kkashyap1707
Copy link

Install AWS CLi version 2.

Export the path of aws
export PATH=/usr/local/bin:$PATH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants