I'm running Amazon Linux 2018.03 (which I suppose is basically CentOS) with Python 2.7. I have a python script my_script.py that uses the boto3 library to use AWS services. I want to run the script on a schedule, so I have a cron entry in /etc/crontab.

The cron entry looks like this:

*  *  *  *  * ec2-user cd /home/ec2-user/scripts && ./my_script.py >> log/run.log 2>&1

Permission for my python script:

-rwxrwxrwx 1 ec2-user ec2-user 9863 Dec 10 10:50 my_script.py

If I run the cron command manually, exactly as it is above, to launch the script, then everything works correctly. If that same command is run by cron, as above, then my python script fails with the following error:

botocore.exceptions.ProfileNotFound: The config profile (dev) could not be found

The boto3 config and credentials are in /home/ec2-user/.aws/:

-rwxr-xr-x 1 ec2-user ec2-user 49 Dec 15 16:11 config
-rwxr-xr-x 1 ec2-user ec2-user 114 Dec 15 16:11 credentials

This is the content of config:

[profile dev]
output = json
region = eu-west-1

...and this is the content of credentials:

aws_access_key_id = xxxxxxxxxxxxxxxx
aws_secret_access_key = xxxxxxxxxxxxxxxxx

As I said before, everything works fine if I run manually, it's just running through cron that has the problem. Why is this happening?

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.