I am using an EC2 instance with ubuntu 18.04 and python 3.6. I am running a python script uses aws cli calls for various things. Before running the script, I configured the aws cli with my access keys, default region etc.
When I run the script directly from the command line using:
$ /home/ubuntu/anaconda3/bin/python /home/ubuntu/blahblah/script_name.py
it runs just fine, the aws cli calls work fine, etc. The aws cli commands run the same way they do if I run them from the command line directly.
BUT, I need the script to start up and run automatically when i start the EC2 instance. So I made a service that calls this script and launch it through systemd. When I do this the service starts, the python script starts but it fails partway through when calling the aws cli. It gets an error message that suggests that the aws cli is not configured. The error message says, "You must specify a region. You can also configure your region by running "aws configure"."
I also ran the command
$aws configure list
inside the script. When run from the command line directly, it stated the configuration details I entered. When I run it through the systemd service it tells me (seen through $journalctl -u service_name.service) that the configuration values [access_key, secret_key, region] are 'not set'.
I also tried reconfiguring aws cli using 'sudo' and then calling the aws cli commands with sudo in front but got the same issue.
Any idea what is wrong?