
agents-deploy
熱門當您要將 Agent 部署至 AWS,或是部署失敗時使用。處理行前檢查與驗證、CDK/IAM/配額錯誤診斷、版本管理、復原(rollback)以及金絲雀部署(canary deployments)。觸發條件包括:"deploy my agent"、"agentcore deploy"、"deploy failed"、"CDK error"、"rollback"、"canary deploy"、"pin version"、"redeploy"、"deploy stuck"。不適用於生產環境強化(請改用 agents-harden)。不適用於部署前新增功能(請改用 agents-build 或 agents-connect)。不適用於 VPC 設定錯誤(請改用 agents-build)。
當您要將 Agent 部署至 AWS,或是部署失敗時使用。處理行前檢查與驗證、CDK/IAM/配額錯誤診斷、版本管理、復原(rollback)以及金絲雀部署(canary deployments)。觸發條件包括:"deploy my agent"、"agentcore deploy"、"deploy failed"、"CDK error"、"rollback"、"canary deploy"、"pin version"、"redeploy"、"deploy stuck"。不適用於生產環境強化(請改用 agents-harden)。不適用於部署前新增功能(請改用 agents-build 或 agents-connect)。不適用於 VPC 設定錯誤(請改用 agents-build)。
deploy
將您的 AgentCore Agent 部署至 AWS,或是診斷部署失敗的原因。
何時使用
- 您已準備好進行部署,並希望先驗證設定
agentcore deploy失敗並出現錯誤- 您希望在不實際部署的情況下,預覽部署將建立的資源
- 您希望部署至特定的目標環境(如 staging、production)
- 您需要復原至先前的版本、固定在特定版本,或設定金絲雀部署
輸入
$ARGUMENTS 為選擇性參數:
/agents-deploy # 互動式 — 行前檢查或診斷失敗原因
/agents-deploy preflight # 在部署前驗證設定與 IAM 權限
/agents-deploy diagnose # 診斷失敗的部署(貼上錯誤訊息或讀取日誌)
/agents-deploy preview # 預覽部署將建立的內容而不進行實際部署
/agents-deploy rollback # 復原至先前的版本
流程
步驟 0:檢查 CLI 版本
執行 agentcore --version。本 Skill 需要 v0.9.0 或更新版本。如果版本較舊,請請開發人員在繼續之前先執行 agentcore update。
步驟 1:判斷目前狀況
讀取 agentcore/agentcore.json 與 agentcore/aws-targets.json(若存在)。
詢問開發人員(或從上下文推論):
「請問您是:
- 準備進行部署,想先檢查所有設定
- 遇到了部署失敗 — 您看到了什麼錯誤訊息?
- 需要復原版本或是固定在特定版本?」
如果開發人員需要版本管理、復原或金絲雀部署,請載入 references/versioning.md 並依照其指引操作。
路徑 A:行前驗證
在執行 agentcore deploy 前,請先進行以下檢查:
檢查 1:驗證設定檔
向開發人員展示並請其執行此命令:
agentcore validate
這可以在 CDK 啟動之前,先擷取出格式不正確的 agentcore.json。
檢查 2:驗證區域(Region)對齊
最常見的部署失敗是區域不符。向開發人員展示這些命令進行驗證:
# 您設定的 AWS 區域
aws configure get region
# 您部署目標中的區域
cat agentcore/aws-targets.json
# 您目前驗證身分的帳號
aws sts get-caller-identity
aws-targets.json 中的 region 必須與您的 aws configure 預設區域相符。account 則必須與 sts get-caller-identity 傳回的帳號 ID 相符。
檢查 3:驗證 Bedrock 模型存取權限
向開發人員展示此命令,以檢查其區域中已啟用的模型:
aws bedrock list-foundation-models --region $(aws configure get region) \
--query 'modelSummaries[?modelLifecycle.status==`ACTIVE`].modelId' \
--output table
跨區域推論描述檔(Profile)ID 會使用地理字首(us.、eu.、apac.)或 global. 來控制推論執行的位置。CLI 預設會建構 global.(例如 global.anthropic.claude-sonnet-4-5-20250929-v1:0),可路由至任何商業區域。地理字首會將推論限制在該地理區域內(例如 eu. 會留在歐洲區域)。所有字首都需要在描述檔包含的每一個目標區域中都已啟用模型存取權。請參閱 Bedrock 文件以瞭解各描述檔字首包含哪些區域。
檢查 4:預覽將部署的內容
agentcore deploy --dry-run
agentcore deploy --diff
--dry-run 會顯示將建立哪些資源。--diff 則會顯示與目前已部署內容相比的 CDK 差異。
檢查 5:驗證 IAM 權限
向開發人員展示所需的權限以及此驗證命令:
aws iam simulate-principal-policy \
--policy-source-arn $(aws sts get-caller-identity --query Arn --output text) \
--action-names iam:CreateRole \
--resource-arns "arn:aws:iam::*:role/*BedrockAgentCore*"
執行部署
agentcore deploy -y # 自動確認 (別名: agentcore dp -y)
agentcore deploy -y -v # 詳細模式 — 顯示資源層級事件
agentcore deploy --target staging -y # 部署至特定的目標環境
記憶體資源佈署說明: 如果您的專案包含記憶體(Memory),在記憶體資源轉為 ACTIVE 狀態期間,部署將多耗費 2–5 分鐘。這是正常現象 — 並非錯誤。請檢查狀態:
agentcore status --type memory
路徑 B:診斷失敗的部署
步驟 B1:讀取錯誤訊息
如果開發人員貼上了錯誤訊息,請直接進行診斷。如果沒有,請讀取部署日誌:
# 檢視最近的部署日誌
ls -lt agentcore/.cli/logs/
cat agentcore/.cli/logs/deploy-*.log 2>/dev/null | tail -100
步驟 B2:比對已知失敗模式
IAM 權限錯誤:
User: arn:aws:iam::123456789012:user/dev is not authorized to perform: iam:CreateRole
修正方法:附加所需的 IAM 權限(請參閱上方檢查 5)。部署身分需要對範圍限定在 *BedrockAgentCore* 角色的 IAM 寫入存取權。
未執行 CDK Bootstrap:
This stack uses assets, so the toolkit stack must be deployed to the environment
修正方法:
npx cdk bootstrap aws://<YOUR_ACCOUNT_ID>/<REGION>
ECR 驗證授權錯誤:
no basic auth credentials
Error response from daemon: Head "https://<YOUR_ACCOUNT_ID>.dkr.ecr.<REGION>.amazonaws.com/..."
修正方法:
aws ecr get-login-password --region <REGION> | \
docker login --username AWS --password-stdin <YOUR_ACCOUNT_ID>.dkr.ecr.<REGION>.amazonaws.com
部署期間模型存取遭拒:
ValidationException: The provided model identifier is invalid
修正方法:前往 Bedrock 控制台 → Model access 啟用該模型。請確保 agentcore.json 中的模型 ID 與您目標區域中已啟用的模型一致。
區域不符:
Stack ... is in region us-east-1 but the target is us-west-2
修正方法:更新 agentcore/aws-targets.json 以符您的 aws configure 預設區域,或執行 aws configure set region <REGION>。
記憶體卡在 CREATING 狀態:
Memory resource is in CREATING state after 10 minutes
這極為罕見 — 正常的佈署過程需時約 2–5 分鐘。請檢查:
agentcore status --type memory --json
如果卡住,請嘗試移除並重新新增記憶體資源。
超越服務配額(Service Quota Exceeded):
LimitExceededException: Account limit for AgentCore runtimes exceeded
修正方法:前往 AWS 控制台 → Service Quotas → Amazon Bedrock AgentCore 申請提高配額。
步驟 B3:修正後重新執行
agentcore deploy -y
如果持續出現相同的錯誤,請執行 agentcore status 以檢視所有資源的當前狀態:
agentcore status
agentcore status --state pending-removal # 標記為待刪除的資源
部署至多個目標環境
請在 agentcore/aws-targets.json 中定義目標環境:
[
{
"name": "staging",
"description": "Staging environment",
"account": "123456789012",
"region": "us-east-1"
},
{
"name": "production",
"description": "Production environment",
"account": "987654321098",
"region": "us-west-2"
}
]
部署至特定的目標環境:
agentcore deploy --target staging -y
agentcore deploy --target production -y
輸出
- 行前檢查結果,並針對發現的任何問題提供具體修正建議
- 部署失敗診斷以及具體的修正方法
- 套用修正後可執行的部署命令





