环境准备

所有代码内容均可在 GitHub 上的公开 AgentCore CLI 仓库中获取

设置本地环境:

  1. 安装 Node.js 20.x 或更高版本
node --version  # 应为 v20.x 或更高版本
  1. 安装 uv(Python 包管理器)
# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# 验证
uv --version
  1. 安装 AgentCore CLI
npm install -g @aws/agentcore

# 验证
agentcore --version

Note: 如果我们之前安装了 bedrock-agentcore-starter-toolkit,请先卸载以避免冲突:


uv tool uninstall bedrock-agentcore-starter-toolkit

# 或
pip3 uninstall bedrock-agentcore-starter-toolkit -y

部署aws环境

使用这个cloudformation来部署用于身份验证的 Cognito、用于 Gateway 实验的 Lambda 函数等:

https://console.aws.amazon.com/cloudformation/home#/stacks/create/review?stackName=agentcore-workshop-prereqs&templateURL=https://pingfan.s3.amazonaws.com/files/prereqs-agentcore.yaml"

启用 Transaction Search(用于可观测性)

这是在 CloudWatch 中查看可观测性指标的一次性前提条件。

  1. 导航到 CloudWatch 控制台
  2. 在左侧面板中,找到 GenAI ObservabilityBedrock AgentCore
  3. 点击 Configure,跳转到 X-Ray Transaction Search 页面
  4. 启用Transaction Search

切换 Enable Transaction Search 并点击 Save