
AWS AgentCore Session endpoints:coding agent 同会话实时预览 Vite 站,端口白名单 + SigV4 本机代理
工程AgentCoreSession endpointscoding agentVite预览Bedrock
一句话结论
在 AgentCore Runtime 会话里声明 allowedPorts,用会话级预览 URL 加本机 SigV4/JWT 代理,让 coding agent 改 CSS 后 Vite HMR 经 WebSocket 回灌浏览器,把「导出再部署」改成同 microVM 秒级热更。
打开原文
AWS:Preview web apps live as your coding agent builds them with Amazon Bedrock AgentCore runtime
背景与理念
评审环被「导出再部署」拖慢时,预览应留在 coding agent 同一会话里。团队要在左聊右站的布局里看 Vite/Web 应用边改边亮,而不是另开一套托管环境。
具体做法
- CreateAgentRuntime 声明 allowedPorts(1–5 项,端口 8000–12000,排除平台保留口);典型:agent 8080、Vite 8090、status 8081。
- Invoke 拿到会话预览 URL(响应头 X-Amzn-Bedrock-AgentCore-Runtime-Session-Endpoint-Url);本机用 SDK session_endpoint_client / open_local_endpoint 做 localhost 代理并加签(SigV4/JWT)。
- 浏览器连本机代理;agent 改样式后 Vite HMR 经 WebSocket 回灌,无需另部署。SDK 要求 bedrock-agentcore ≥1.25.2、boto3 ≥1.43.122;演示用 Claude Haiku 5.5。拒绝场景:越权端口/无凭证 403、无监听 502、会话没了 404。
关键数据/例子
allowedPorts 限 1–5 个、端口区间 8000–12000。文中把失败码表写进产品契约,而不是只展示 happy path。
创新点
第一,把「会话级鉴权预览 URL + 本机代理加签 + 端口白名单」做成 Runtime 一等能力,而不是外挂预览沙箱。第二,用 HMR/WebSocket 把评审环收进同一 microVM。
可否复用
- 自建 coding-agent 预览先钉端口白名单与会话级凭证,再谈 iframe。
- 本机代理只转发已声明端口,并把 403/502/404 写进运维手册。
- 对照时核对 SDK 最低版本,避免旧客户端拿不到 Session Endpoint。