Reputation:
Im trying to copy files from my s3-bucket to my ec2-instance.
When i run this command inside my ec2-instance: aws s3 cp s3://amazing-demobucket-1/file.txt ./file.txt
i get following error: Unable to locate credentials
But the aws configure files is in my ~/.aws
in my local machine. Do i need to configure inside ec2-instance too? Or is there another command i can run outside my ec2-instance to download files from s3-bucket into ec2-instance ?
Thank for help!
Upvotes: 4
Views: 21654
Reputation: 18531
Your AWS credentials on your local machine can't be seen by the awscli
program on your EC2 instance. If you want to run the S3 copy command on the EC2 instance, you have two options:
1) Run aws configure
on the EC2 instance and define the credentials on that machine (not recommended)
or
2) Create an IAM role with the required permissions to copy the files (for example, with the AmazonS3ReadOnlyAccess policy) and attach the role to your EC2 instance
Upvotes: 13
Reputation: 1183
Instead of using AWS credentials inside EC2, you can try with Creating IAM roles and attach it to EC2.
Steps:
i) Create IAM role for EC2 with S3 access ii) Attach the IAM role to EC2 instance
For more reference: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_switch-role-ec2.html
Hope it helps.
Upvotes: 1
Reputation: 144
It might be issue with order of precedence. AWS check Keys first in environment variables and then ~/.aws path
Try running below command to check where its looking for keys
aws configure list
You can find more details about precedence on below link
Upvotes: 2