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 復現——上方輸出為原樣照錄。