pythonamazon-web-servicesamazon-s3boto3aws-credentials

How do I read S3 credentials from a different file name (not called credentials in .aws)?


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.


Solution

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