The config profile could not be found
TL;DR — 你使用的 profile 名称并不存在于你的进程正在读取的 AWS 配置文件中。三个常见嫌疑人:一个过期的 AWS_PROFILE 环境变量、--profile/profile_name 里的拼写错误,或者 profile 定义在了错误的节头下——~/.aws/config 文件需要 [profile myprofile],而 ~/.aws/credentials 用的是普通的 [myprofile]。运行 aws configure list-profiles 对比一下。
含义
botocore.exceptions.ProfileNotFound: The config profile (myprofile) could not be found任何 DynamoDB 调用在被签名之前,SDK 都要先解析出一个凭证 profile。如果某个 profile 是被_显式请求_的——通过 AWS_PROFILE、--profile 或 boto3.Session(profile_name=...)——而正在读取的 config/credentials 文件里没有同名的节,解析就会以这个错误停下。什么都没到达 AWS;这完全是本地配置查找失败。
为什么会发生
AWS_PROFILE指向一个不存在的 profile——很久以前设在某个 shell rc 文件、容器镜像或 CI 配置里,之后那个 profile 被改名或删除了。- 拼写错误或大小写不匹配——profile 名称是精确匹配的。
- 节头语法写错——在
~/.aws/config里,一个命名 profile 必须声明为[profile myprofile];在那里写成[myprofile]意味着 CLI/SDK 找不到它(那种朴素写法属于~/.aws/credentials)。 - 文件不在进程查找的位置——
AWS_CONFIG_FILE/AWS_SHARED_CREDENTIALS_FILE覆盖了路径,或者在 sudo/服务用户下换了主目录,又或者容器里没有挂载~/.aws。
如何修复
先列出你的环境实际能看到什么:
aws configure list-profiles env | grep -i '^AWS_'修正或清除那个指针——
unset AWS_PROFILE(或把它设成列表里的某个 profile),并订正--profile/profile_name的拼写。检查节头:
# ~/.aws/config [profile myprofile] region = eu-west-1 # ~/.aws/credentials [myprofile] aws_access_key_id = ... aws_secret_access_key = ...如果这个 profile 从来就不存在,就创建它——
aws configure --profile myprofile(Identity Center 的 profile 用aws configure sso)。在容器/CI 里,优先用环境凭证或角色,而不是 profile 文件——或者把
AWS_CONFIG_FILE挂载/指向一个确实定义了该 profile 的文件。
profile 一旦能解析出来,再验证它是否真的够得着你的表——DynoTable 用你的 AWS profile 来连接,而它的 profile 切换器让“哪个 profile 看得到哪些表”一目了然。
在 DynoTable 中查看
DynoTable 读取与 CLI 相同的 ~/.aws/credentials 和 ~/.aws/config 文件 — 在“设置”→“配置文件”下添加配置文件,从下拉列表中选择配置文件名称,然后运行 测试连接* 以确认它在 SDK 之前解析。当表消失时,Profile切换(⌘P)会使陈旧的AWS_PROFILE变得明显。对于本地,使用端点 http://localhost:8000 和虚拟凭据创建配置文件。参见连接 AWS和安装。连接后打开带有⌘K的表,然后在Query Builder中运行冒烟测试查询。
来源
- Configuration and credential file settings in the AWS CLI(2026-07-13 验证)
- Configuring environment variables for the AWS CLI(2026-07-13 验证)
复现方法
将 boto3 指向不在你的配置中的配置文件,并清除 AWS 环境,以便没有其他内容满足查找:
import boto3
boto3.Session(profile_name='no-such-profile-xyz').client('dynamodb').list_tables()实际输出:
ProfileNotFound: The config profile (no-such-profile-xyz) could not be found这是由客户端上的 botocore 在任何请求达到 AWS 之前引发的 - 这就是为什么没有 HTTP 状态以及重试无济于事的原因。括号中的名称是它要查找的配置文件,因此它会告诉你拼写错误是在代码中还是在配置文件中。
相关错误
- Unable to locate credentials——完全找不到任何凭证(不涉及显式的 profile)。
- Could not load credentials from any providers——同一条链失败的 JS-SDK 版本。
- SSO session expired——profile 存在,但它的 SSO 登录过期了。
- 学习:DynamoDB Local & LocalStack setup
参考资料
- Configuration and credential file settings in the AWS CLI — AWS CLI User Guide
- Configuring environment variables for the AWS CLI — AWS CLI User Guide (AWS_PROFILE, AWS_CONFIG_FILE, AWS_SHARED_CREDENTIALS_FILE)
- Configuring IAM Identity Center authentication with the AWS CLI — AWS CLI User Guide (aws configure sso)
最后核实于 2026-07-13,依据上方链接的 AWS 官方文档。
2026-07-26 针对 boto3 1.43.56 / botocore 1.43.56 复现——上方输出为原样照录。