TJB
TJB

Reputation: 3836

Where to put AWS credentials for Boto3 S3 instance

I am trying to run a simple python script that goes through all of my AWS buckets and print outs the buckets name. I am trying to figure out where to put my AWS credentials for authorization. In the documentation it says to put them in a specific aws config file

Alternatively, you can create the credential file yourself. By default, its location is at ~/.aws/credentials:

When running a standalone python script, lets call it s3_test.py, where do I put the credentials ? On my local machine, do I create a file called credentials at ~/.aws/ , or can I just put my credentials in the script itself ?

import boto3

s3 = boto3.resource('s3')

bucket_name = 'bucketnamehere'

for bucket in s3.buckets.all():
    print(bucket.name)

Upvotes: 1

Views: 3033

Answers (3)

Samuel Nde
Samuel Nde

Reputation: 2743

The config file is supposed to be in the "C:/Users/Username/.aws".

Upvotes: 0

dvnguyen
dvnguyen

Reputation: 3022

Follow their recommendation to put your credentials at ~/.aws/credentials, or run aws configure as Taylor Wood's answer, but never put credentials in your code. It's a big security risk.

Upvotes: 0

Taylor Wood
Taylor Wood

Reputation: 16194

Run the AWS CLI command aws configure in your terminal and enter your credentials, region, etc.

Also see the AWS credentials docs for more options.

Always keep secrets out of your source code whenever possible (it's always possible).

Upvotes: 3

Related Questions