Cli "Unable to locate credentials" on EC2 instance
I'm trying to use the AWS CLI tool on an EC2 instance running Amazon Linux.
I configured it by using the "aws configure" command to set up an access key and secret key. When I run it directly from the linux prompt, it works fine.
However, I need to run it as part of a script that is executed nightly with cron. I put a link to my script in cron.daily. The script runs, but when it reaches the aws command, it fails with the error "Unable to locate credentials".
I suspect that cron must be running the script under some user other than the default ec2-user, but I can't figure out which user, or how to configure the credentials for that user.
I tried typing "sudo su" and then re-issuing the commands to set the credentials, but that did not fix the problem.
I suspect you're on the right path - the credentials are set up for a particular user and the cron job is executing as another user; or in some way cannot locate the file where the credentials are stored.
My recommendation is not to use static credentials. Instead, create a role for the instance - that way you don't have to worry about rotating credentials or even storing them on the instance.
Cli "Unable to locate credentials" on EC2 instanceasked 14 days ago
How does an EC2 instance assume an IAM Role?Accepted Answerasked 3 months ago
Locate Instanceasked 5 months ago
Backing up the EC2asked 3 years ago
Does user need Programmatic Access if using EC2 Instance Connect service?Accepted Answerasked 2 years ago
Botocore not able to use credentials on EC2 instanceasked a year ago
AWS CLI does not pick up credentials file with sudo (EC2, Linux)asked 5 months ago
Unable to connect to EC2 instance via aws websiteAccepted Answerasked 13 days ago
EB-Cli SSH Tunnel to RDS Databaseasked 3 years ago
aws-cli Unable to locate credentials at launchasked 3 years ago