Search code examples
amazon-s3amazon-ec2

Get "fatal error: Unable to locate credentials" when I'm copying file from S3 to EC2 using aws cli


When login EC2 as ec2-user and run the following command:

aws s3 cp s3://mybucket/test/test.txt /home/ec2-user/

I got the following error:

fatal error: Unable to locate credentials

My bucket and my EC2 are created by the same account and in the same region. Why my EC2 can't access my S3 object?


Solution

  • I find that it is caused by missing role. In order to access S3 objects from EC2, I need to assign a role during the EC2 creation, and the role should has the access rights to S3.