Aws-cli 1.2.10 cron script does not work

I have a crontab that runs a PHP script that runs the AWS CLI command "aws ec2 create-snapshot".

When I run the script through the command line, the PHP script successfully completes with the aws command, which returns the JSON string in PHP. But when I configure crontab to run a PHP script, the aws command returns nothing.

crontab works as the same user as when running a php script on the command line, so am I a little dead end?

+4
source share
2 answers

I had the same problem running ruby ​​script (ruby script.rb). I replaced ruby ​​with the full path (/sources/ruby-2.0.0-p195/ruby) and it worked. in your case, replace "aws" with the full path. find it: find / -name "aws"

+6
source

The reason you need to specify the full path to the aws command is because cron works by default with a very limited environment. I ran into this problem and debugged it by adding it to the cron script:

set | sort > /tmp/environment.txt

Then I ran the script through cron and through the command line (renamed the environment file between starts) and compared them. This led me to need to set the PATH and AWS_DEFAULT_REGION environment variables. After that, the script worked fine.

+1
source

Source: https://habr.com/ru/post/1523320/


All Articles