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 能看到哪些表"变得可见,而 DynamoDB 定价计算器帮你规划该账户工作负载的成本。
相关错误
- Unable to locate credentials——根本没找到任何凭证(不涉及显式 profile)。
- Could not load credentials from any providers——同一条链失败的 JS-SDK 版本。
- SSO session expired——profile 存在,但其 SSO 登录已失效。
- 学习:DynamoDB Local & LocalStack setup
References
- 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 官方文档。