How to specify credentials when connecting to boto3 S3?

后端 未结 5 2099
我在风中等你
我在风中等你 2020-12-04 08:10

On boto I used to specify my credentials when connecting to S3 in such a way:

import boto
from boto.s3.connection import Key, S3Connection
S3 = S3Connection(         


        
5条回答
  •  没有蜡笔的小新
    2020-12-04 09:12

    I'd like expand on @JustAGuy's answer. The method I prefer is to use AWS CLI to create a config file. The reason is, with the config file, the CLI or the SDK will automatically look for credentials in the ~/.aws folder. And the good thing is that AWS CLI is written in python.

    You can get cli from pypi if you don't have it already. Here are the steps to get cli set up from terminal

    $> pip install awscli  #can add user flag 
    $> aws configure
    AWS Access Key ID [****************ABCD]:[enter your key here]
    AWS Secret Access Key [****************xyz]:[enter your secret key here]
    Default region name [us-west-2]:[enter your region here]
    Default output format [None]:
    

    After this you can access boto and any of the api without having to specify keys (unless you want to use a different credentials).

提交回复
热议问题