View a markdown version of this page

HTTP 傳遞目標 - Amazon Bedrock AgentCore

HTTP 傳遞目標

您可以新增 HTTP 傳遞目標,將流量透過閘道路由到任何 HTTP 端點。閘道會將請求轉送至目標端點,無需通訊協定轉譯,充當安全的代理層。這使得傳遞目標非常適合前端代理程式 URLs、外部 APIs 或任何您想要透過閘道的集中式身分驗證、政策強制執行和可觀測性存取的 HTTP 服務。

當您想要:

  • 具有統一存取控制的單一閘道端點後方的前端代理程式服務 (例如 A2A 代理程式、外部 MCP 伺服器或自訂推論端點)。

  • 在閘道管理傳入身分驗證和傳出憑證注入時,將流量路由到外部服務。

  • 將閘道政策,例如護欄和存取控制,套用至以外部端點為目標的請求。

  • 使用路徑型路由 (/{targetName}/{path}) 透過單一閘道連接多個外部服務。

目標組態

當您建立 HTTP 傳遞目標時,您會提供目標端點 URL 和通訊協定類型,指出目標實作的應用程式通訊協定。閘道使用通訊協定類型進行可觀測性和政策評估,但不執行通訊協定轉譯。

HTTP 傳遞目標的目標組態使用以下結構:

{ "http": { "passthrough": { "endpoint": "https://partner-agent.example.com", "protocolType": "A2A" } } }

下列範例顯示具有自訂通訊協定和明確 API 結構描述的傳遞目標:

{ "http": { "passthrough": { "endpoint": "https://my-service.example.com", "protocolType": "CUSTOM", "schema": { "source": { "s3": { "uri": "s3://DOC-EXAMPLE-BUCKET/service-schema.yaml" } } } } } }
  • endpoint (必要) – 目標服務的 HTTPS URL。閘道會將請求轉送至此端點。

  • protocolType (必要) – 目標實作的應用程式通訊協定。有效值:

    • MCP – 目標是 MCP 伺服器。路由至您要直接存取的單一 MCP 伺服器時 (未與其他 MCP 目標彙總),請使用此選項。

    • A2A – 目標實作 Agent-to-Agent (A2A) 通訊協定。

    • INFERENCE – 目標是推論端點。

    • CUSTOM – 目標實作自訂或專屬通訊協定。

  • 結構描述 (選用) – 描述傳遞目標請求和回應結構的 API 結構描述。閘道使用此結構描述來啟用政策引擎功能,例如護欄。結構描述格式會自動偵測為 OpenAPI 或 Smithy。

    結構描述需求取決於通訊協定類型:

    • 對於 MCPA2A通訊協定類型,會自動套用預設結構描述。除非您想要覆寫預設值,否則您不需要提供結構描述。

    • 對於具有已知提供者 (OpenAI、Anthropic 或 Amazon Bedrock) 的INFERENCE通訊協定類型,預設結構描述會根據端點網域套用。

    • 對於CUSTOM通訊協定類型,您必須提供結構描述才能使用護欄。

      schema 物件包含source指定結構描述內容位置的 :

    • s3 – 指向結構描述檔案的 S3 URI (例如,s3://DOC-EXAMPLE-BUCKET/service-schema.yaml)。

    • inlinePayload – 直接以字串形式提供的結構描述內容。

建立 HTTP 傳遞目標

下列範例會建立路由至不同類型端點的傳遞目標:A2A 代理程式、外部 MCP 伺服器、IAM 驗證的內部服務,以及使用 API 金鑰驗證的外部 API。

範例
AgentCore CLI
  1. 使用 OAuth 登入資料路由至 A2A 代理程式:

    agentcore add gateway-target \ --name partner-agent \ --type passthrough \ --passthrough-endpoint https://partner-agent.example.com \ --passthrough-protocol A2A \ --outbound-auth oauth \ --credential-name partner-oauth \ --gateway MyGateway agentcore deploy

    使用 OAuth 登入資料路由至外部 MCP 伺服器:

    agentcore add gateway-target \ --name slack-mcp \ --type passthrough \ --passthrough-endpoint https://mcp-slack.example.com \ --passthrough-protocol MCP \ --outbound-auth oauth \ --credential-name slack-oauth \ --gateway MyGateway agentcore deploy

    使用 IAM (SigV4) 角色型身分驗證,搭配CUSTOM通訊協定和 S3 結構描述路由至內部服務:

    agentcore add gateway-target \ --name internal-service \ --type passthrough \ --passthrough-endpoint https://internal-service.example.com \ --passthrough-protocol CUSTOM \ --schema s3://amzn-s3-demo-bucket/internal-service-schema.yaml \ --signing-service execute-api \ --signing-region us-west-2 \ --gateway MyGateway agentcore deploy

    使用 API 金鑰登入資料路由至外部 API:

    agentcore add gateway-target \ --name external-api \ --type passthrough \ --passthrough-endpoint https://api.example.com \ --passthrough-protocol CUSTOM \ --outbound-auth api-key \ --credential-name my-api-key \ --credential-parameter-name x-api-key \ --gateway MyGateway agentcore deploy
AWS CLI
  1. 使用 OAuth 登入資料路由至 A2A 代理程式:

    aws bedrock-agentcore-control create-gateway-target --cli-input-json '{ "gatewayIdentifier": "GATEWAY_ID", "name": "partner-agent", "targetConfiguration": { "http": { "passthrough": { "endpoint": "https://partner-agent.example.com", "protocolType": "A2A" } } }, "credentialProviderConfigurations": [ { "credentialProviderType": "OAUTH", "credentialProvider": { "oauthCredentialProvider": { "providerArn": "arn:aws:bedrock-agentcore:us-west-2:111122223333:token-vault/default/oauthcredentialprovider/partner-oauth" } } } ] }'

    使用 OAuth 登入資料路由至外部 MCP 伺服器:

    aws bedrock-agentcore-control create-gateway-target --cli-input-json '{ "gatewayIdentifier": "GATEWAY_ID", "name": "slack-mcp", "targetConfiguration": { "http": { "passthrough": { "endpoint": "https://mcp-slack.example.com", "protocolType": "MCP" } } }, "credentialProviderConfigurations": [ { "credentialProviderType": "OAUTH", "credentialProvider": { "oauthCredentialProvider": { "providerArn": "arn:aws:bedrock-agentcore:us-west-2:111122223333:token-vault/default/oauthcredentialprovider/slack-oauth" } } } ] }'

    使用 IAM 角色型身分驗證,搭配CUSTOM通訊協定和 S3 結構描述路由至內部服務:

    aws bedrock-agentcore-control create-gateway-target --cli-input-json '{ "gatewayIdentifier": "GATEWAY_ID", "name": "internal-service", "targetConfiguration": { "http": { "passthrough": { "endpoint": "https://internal-service.example.com", "protocolType": "CUSTOM", "schema": { "source": { "s3": { "uri": "s3://DOC-EXAMPLE-BUCKET/internal-service-schema.yaml" } } } } } }, "credentialProviderConfigurations": [ {"credentialProviderType": "GATEWAY_IAM_ROLE"} ] }'

    使用 API 金鑰登入資料路由至外部 API:

    aws bedrock-agentcore-control create-gateway-target --cli-input-json '{ "gatewayIdentifier": "GATEWAY_ID", "name": "external-api", "targetConfiguration": { "http": { "passthrough": { "endpoint": "https://api.example.com", "protocolType": "CUSTOM" } } }, "credentialProviderConfigurations": [ { "credentialProviderType": "API_KEY", "credentialProvider": { "apiKeyCredentialProvider": { "providerArn": "arn:aws:bedrock-agentcore:us-west-2:111122223333:token-vault/default/apikeycredentialprovider/my-api-key", "credentialParameterName": "x-api-key" } } } ] }'

叫用 HTTP 傳遞目標

若要透過閘道叫用 HTTP 傳遞目標,請使用路徑型路由傳送請求至目標。URL 格式為:

https://{gatewayId}.gateway.bedrock-agentcore.{region}.amazonaws.com/{targetName}/{path}

閘道會將請求轉送到目標{endpoint}/{path}上的 。{gatewayId} 將 取代為您的閘道 ID、{region}將 取代為 AWS 區域、將 {targetName}取代為目標名稱,並將 {path}取代為要轉送的路徑。

下列範例會透過閘道傳送 A2A 訊息給合作夥伴代理程式:

curl -X POST https://gateway-id.gateway.bedrock-agentcore.us-west-2.amazonaws.com/partner-agent/invocations \ -H "Content-Type: application/json" \ -H "Authorization: Bearer <token>" \ -d '{ "jsonrpc": "2.0", "id": "req-001", "method": "message/send", "params": { "message": { "role": "user", "parts": [{"kind": "text", "text": "What is the stock price of AMZN?"}], "messageId": "msg-001" } } }'

下列範例會透過閘道呼叫 MCP 伺服器:

curl -X POST https://gateway-id.gateway.bedrock-agentcore.us-west-2.amazonaws.com/slack-mcp/mcp \ -H "Content-Type: application/json" \ -H "Authorization: Bearer <token>" \ -d '{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}'

傳出授權

HTTP 傳遞目標支援下列傳出授權類型:

  • IAM (SigV4) (GATEWAY_IAM_ROLE) – 閘道會擔任閘道服務角色來簽署對目標的請求。

  • OAuth (OAUTH) – 閘道會透過 Amazon Bedrock AgentCore 身分服務,從目標中設定的憑證提供者擷取 OAuth 字符。

  • 來電者 IAM 登入資料 (CALLER_IAM_CREDENTIALS) – 閘道會使用發起人的 IAM 身分和許可,使用 SigV4 簽署對目標的請求。僅適用於具有 AWS_IAMAUTHENTICATE_ONLY授權方類型的閘道。

  • 權杖傳遞 (JWT_PASSTHROUGH) – 閘道會驗證傳入權杖,並將其傳遞至目標,無需修改。

  • API 金鑰 (API_KEY) – 閘道會從字符文件庫中設定的登入資料提供者擷取 API 金鑰,並將其插入傳出請求做為指定的請求標頭。