1

I am able to upload an object from my local to my cloud S3 bucket when reading from the "credentials" located in .aws however there is a file that is the same format as "credentials" called "tester" for the sake of this question and I cannot get it to read from it, even though it's the exact same copy as credentials.

If I do this:

# Upload the file
        s3_client = boto3.client(
            's3',
            aws_access_key_id=ACCESS_KEY,
            aws_secret_access_key=SECRET_KEY,
            aws_session_token=SESSION_TOKEN,
        )

what should I be putting in ACCESS_KEY,SECRET_KEY,SESSION_TOKEN? I do not want to hardcode my credentials but I want it to not read from credentials in .aws but from another file instead called "tester" which has the same credentials.

Note: The "tester" file is in the same location as my python/Boto3 program on my Mac.

IBSurviver
  • 29
  • 3
  • I also noticed that almost all your questions have answers, yet not a single one accepted. Accepting good answers is not only a good practice, but it reduces number of duplicates and increases chances for your questions to be actually answered. – Marcin Sep 20 '21 at 03:27
  • I will accept from now on. No problem. – IBSurviver Sep 20 '21 at 03:38
  • Thanks. You can revisit past questions and answers and accepted those that were helpful retrospectively. – Marcin Sep 20 '21 at 04:04

1 Answers1

6

You can set AWS_SHARED_CREDENTIALS_FILE env variable before you run your code, or in python itself, to specify new configuration file.

Marcin
  • 215,873
  • 14
  • 235
  • 294
  • I have heard that there are parameters you pass into the boto3.client or boto3.resource functions that let you specify the access key and secret key. So how can I read the "tester" file this way? Is setting the env variable the only way? – IBSurviver Sep 20 '21 at 03:38
  • @IBSurviver Yes, I think its the only way. At least I am not aware of other options in boto3 to do that. – Marcin Sep 20 '21 at 04:06
  • technically you can still do this in code. just update the `os.environ` with the new file name in your script. no need to figure out if boto3 supports it :-) – rv.kvetch Sep 20 '21 at 04:24
  • 1
    @rv.kvetch Yes, that's right and that's why I wrote "or in python itself". – Marcin Sep 20 '21 at 06:23