I have this script:
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
SHELL=/bin/bash
# Create EBS Data snapshot
/usr/local/bin/aws ec2 create-snapshot --volume-id "vol-XXXXX" --description "test"
It works perfectly if I run it from the shell, but does nothing with Cron. Why? I am using IAM roles, is it important?
Running aws configure
as the root user didn't help me, as I had already configured the credentials, and the script ran quite happily for the root user directly from the command line, but would still not run through cron.
The error message I was receiving was;
Unable to locate credentials. You can configure credentials by running "aws configure".
What helped me was adding the following lines to the top of my crontab file, so that the environment was in place for all scripts that ran through cron.
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Hope that helps someone!
Ok, after several hours I found the solution:
The user root was running the script but AWS was not configured for this user. I only needed to configure AWS for the user root:
# aws configure
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With