Boto3 配置文件创建:botocore.exceptions.ProfileNotFound:找不到配置文件

Boto3 profile creation: botocore.exceptions.ProfileNotFound: The config profile could not be found

我正在尝试 运行 python 在没有 aws 配置文件设置的远程无服务器服务器上编写代码。在查看了 boto3 文档之后,如果我说:

session = boto3.session.Session(profile_name='dev') 

client = session.client(service_name="secretsmanager",
        region_name=region_name 
) 
get_secret_value_response = client.get_secret_value(
            SecretId=secret_name 
)

我将获得一个新的 boto3 名称配置文件,但我收到错误消息:

secret_class = get_secret(name, region, profile)

File "/metaflow/func_get_aws_secrets.py", line 45, in get_secret session = boto3.session.Session(profile_name=profile)

...

raise ProfileNotFound(profile=profile_name)

botocore.exceptions.ProfileNotFound: The config profile (dev) could not be found

我不明白它遗漏了什么?

发生的情况是,您正在尝试获取一个 Session,其配置文件名为 dev

如果您想了解更多关于 aws 配置文件的信息,可以试试这个:Named Profiles

如果您想保留您的代码,您需要在您的凭据文件中添加一个名为 dev 的配置文件:

  • ~/.aws/credentials (Linux/Mac)
  • %USERPROFILE%\.aws\credentials (Windows)

您的凭据文件类似于:

[default]
aws_access_key_id=
aws_secret_access_key=

[dev]
aws_access_key_id=
aws_secret_access_key=

如果您不想创建开发配置文件,只需删除 profile_name 参数,它将使用您的默认配置