Boto3 Error: botocore.exceptions.NoCredentialsError: Unable to locate credentials

后端 未结 12 2263
逝去的感伤
逝去的感伤 2020-11-30 23:00

When I simply run the following code, I always gets this error.

s3 = boto3.resource(\'s3\')
    bucket_name = \"python-sdk-sample-%s\" % uuid.uuid4()
    pri         


        
12条回答
  •  臣服心动
    2020-11-30 23:39

    If you have multiple aws profiles in ~/.aws/credentials like...

    [Profile 1]
    aws_access_key_id = *******************
    aws_secret_access_key = ******************************************
    [Profile 2]
    aws_access_key_id = *******************
    aws_secret_access_key = ******************************************
    

    Follow two steps:

    1. Make one you want to use as a default using export AWS_DEFAULT_PROFILE=Profile 1 command in terminal.

    2. Make sure to run above command in the same terminal from where you use boto3 or you open an editor.[Understand the following scenario]

    Scenario:

    • If you have two terminal open called t1 and t2.
    • And you run the export command in t1 and you open JupyterLab or any other from t2, you will get NoCredentialsError: Unable to locate credentials error.

    Solution:

    • Run the export command in t1 and then open JupyterLab or any other from the same terminal t1.

提交回复
热议问题