当我简单地运行下面的代码时,我总是得到这个错误。

s3 = boto3.resource('s3')
bucket_name = "python-sdk-sample-%s" % uuid.uuid4()
print("Creating new bucket with name:", bucket_name)
s3.create_bucket(Bucket=bucket_name)

我已将我的证书文件保存在

C:\Users\myname\.aws\证书,从那里Boto应该读我的证书。

我的设置错了吗?

下面是boto3的输出。set_stream_logger (botocore,级别=“调试”)。

2015-10-24 14:22:28,761 botocore.credentials [DEBUG] Skipping environment variable credential check because profile name was explicitly set.
2015-10-24 14:22:28,761 botocore.credentials [DEBUG] Looking for credentials via: env
2015-10-24 14:22:28,773 botocore.credentials [DEBUG] Looking for credentials via: shared-credentials-file
2015-10-24 14:22:28,774 botocore.credentials [DEBUG] Looking for credentials via: config-file
2015-10-24 14:22:28,774 botocore.credentials [DEBUG] Looking for credentials via: ec2-credentials-file
2015-10-24 14:22:28,774 botocore.credentials [DEBUG] Looking for credentials via: boto-config
2015-10-24 14:22:28,774 botocore.credentials [DEBUG] Looking for credentials via: iam-role

当前回答

我是这样解决这个问题的:

aws configure

之后我手动输入:

AWS Access Key ID [None]: xxxxxxxxxx
AWS Secret Access Key [None]: xxxxxxxxxx
Default region name [None]: us-east-1
Default output format [None]: just hit enter

从那以后,它对我起作用了

其他回答

对于MLflow,如果不能写入AWS3/MinIO数据湖,则调用MLflow .log_artifact()将引发此错误。

原因是没有在你的python env中设置凭据(就像这两个env变量一样):

os.environ['DATA_AWS_ACCESS_KEY_ID'] = 'login'
os.environ['DATA_AWS_SECRET_ACCESS_KEY'] = 'password'

注意,您也可以使用minio客户端直接访问MLflow构件(除了MLflow的连接外,还需要一个到数据湖的单独连接)。这个客户端可以像这样启动:

minio_client_mlflow = minio.Minio(os.environ['MLFLOW_S3_ENDPOINT_URL'].split('://')[1],
                    access_key=os.environ['AWS_ACCESS_KEY_ID'],
                    secret_key=os.environ['AWS_SECRET_ACCESS_KEY'],
                    secure=False)

我是这样解决这个问题的:

aws configure

之后我手动输入:

AWS Access Key ID [None]: xxxxxxxxxx
AWS Secret Access Key [None]: xxxxxxxxxx
Default region name [None]: us-east-1
Default output format [None]: just hit enter

从那以后,它对我起作用了

我只是遇到了这个问题。这对我来说很管用:

pip install botocore==1.13.20

来源:https://github.com/boto/botocore/issues/1892

确保你的~/。Unix中的aws/credentials文件是这样的:

[MyProfile1]
aws_access_key_id = yourAccessId
aws_secret_access_key = yourSecretKey

[MyProfile2]
aws_access_key_id = yourAccessId
aws_secret_access_key = yourSecretKey

你的Python脚本应该是这样的,它可以工作:

from __future__ import print_function
import boto3
import os

os.environ['AWS_PROFILE'] = "MyProfile1"
os.environ['AWS_DEFAULT_REGION'] = "us-east-1"

ec2 = boto3.client('ec2')

# Retrieves all regions/endpoints that work with EC2
response = ec2.describe_regions()
print('Regions:', response['Regions'])

来源:https://boto3.readthedocs.io/en/latest/guide/configuration.html交互性配置。

尝试手动指定键

    s3 = boto3.resource('s3',
         aws_access_key_id=ACCESS_ID,
         aws_secret_access_key= ACCESS_KEY)

出于安全考虑,请确保您没有在代码中直接包含ACCESS_ID和ACCESS_KEY。 考虑使用环境配置,并按照@Tiger_Mike的建议将它们注入到代码中。

对于Prod环境,可以考虑使用旋转访问键: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html#Using_RotateAccessKey