Open Shion093 opened 6 years ago
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.
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.
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.
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"
It's not PATH, it's the python virtualenv setup.
Try looking at env | grep -i python
.
Install AWS CLi version 2.
Export the path of aws
export PATH=/usr/local/bin:$PATH
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