I'm totally new to AWS. I want to download an s3 bukcet into my EC2 instance but I am geeting this error
raise NoCredentialsError()
botocore.exceptions.NoCredentialsError: Unable to locate credentials
in order for that to work I need to specify aws_access_key_id
and aws_secret_access_key
but I don't know from where I can get them
CodePudding user response:
If you run your code on an EC2 instance, you should setup IAM role for Amazon EC2 with arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess
policy. Hardcoding credentials into an EC2 instance is a bad security practice.
Once you setup the role, boto3 on the instance will be able to automatically get the AWS credentials from the role to access the S3.