Reputation: 1240
Through boto3 library, I uploaded and downloaded file from AWS s3 successfully. But after few hours, it shows InvalidAccessKeyId suddenly for the same code.
What I have done:
set ~/.aws/credentials
Set environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
I tried the following solutions, but the error still heppens.
adding quotes on config values
Do I miss anything? Thanks for your help.
Upvotes: 0
Views: 2791
Reputation: 1240
I found this article for the same issue. Amazon suggests to generate new key, and I did. Then it works, but we don't know the root cause. Suggest to do so for saving a lot of time when having the same problem.
Upvotes: 0
Reputation: 109
If you have the credentials in ~/.aws/credentials
there is no need to set environment variables AWS_ACCESS_KEY_ID
& AWS_SECRET_ACCESS_KEY
.
Environment variables are valid only for a session.
If you are using boto3, you can specify the credentials while creating client itself.
The best way to configure AWS credential is to install the AWS Command-Line Interface (CLI) and run aws configure
from the bash console:
~/.aws/credentials format
[default]
aws_access_key_id = ***********
aws_secret_access_key = ************
Upvotes: 1
Reputation: 269370
You do not need to configure both .aws/credentials
AND environment variables.
From Credentials — Boto 3 documentation:
The order in which Boto3 searches for credentials is:
boto.client()
method~/.aws/credentials
)~/.aws/config
)/etc/boto.cfg
and ~/.boto
)The fact that your credentials stopped working after a period of time suggests that they were temporary credentials created via the AWS Security Token Service, with an expiry time.
Upvotes: 1