View a markdown version of this page

組態 - Amazon Bedrock AgentCore

組態

可以使用名為 的輸入參數來設定攔截器 passRequestHeaders

攔截器輸入組態

設定攔截器時,您可以使用 passRequestHeaders 欄位指定是否應將請求標頭傳遞給攔截器函數:

passRequestHeaders

布林值,決定請求標頭是否包含在攔截器輸入承載中。設為 true 時,所有請求標頭都會傳遞到您的攔截器 Lambda 函數。設為 false(預設) 時,不包含標頭。

警告

將此設定為 時請小心,true因為請求標頭可能包含敏感資訊,例如身分驗證字符和登入資料。

payloadFilter

對於共用http攔截器承載形狀的 HTTP 目標 (AgentCore 執行期和傳遞期) 和推論目標,這是從攔截器輸入承載中排除欄位的選用篩選條件。Lambda 同步調用對請求和回應組合有 6 MB 的限制,因此排除大型回應內文會將承載保持在該限制內。若要排除回應內文,請將 payloadFilter.exclude設定為包含 RESPONSE_BODY 欄位的清單:

{ "inputConfiguration": { "passRequestHeaders": false, "payloadFilter": { "exclude": [{ "field": "RESPONSE_BODY" }] } } }
注意

passRequestHeaders 在 中為必要項目inputConfiguration。將其與 一起包含 (例如 "passRequestHeaders": false)payloadFilter

排除回應內文時,回應攔截器輸入承載中的 body 欄位為 null。您的函數仍然可以檢查 statusCodecontentTypeheaders,並且可以插入標頭或覆寫狀態碼。如果您的函數傳回 body: null,閘道會使用原始回應內文。

在閘道建立期間設定攔截器

下列範例示範如何使用已passRequestHeaders設為 的攔截器建立閘道true

範例
AgentCore CLI
  1. 使用 AgentCore CLI,首先建立和部署閘道,然後使用 CLI 或 AWS Python SDK (Boto3) AWS 設定攔截器。

    建立閘道:

    agentcore add gateway \ --name my-gateway-with-headers \ --authorizer-type CUSTOM_JWT \ --discovery-url "https://cognito-idp.us-west-2.amazonaws.com/some-user-pool/.well-known/openid-configuration" \ --allowed-audience "api.example.com" agentcore deploy

    部署之後,使用 CLI AWS update-gateway命令或 AWS Python SDK (Boto3) 在閘道上設定攔截器,如其他索引標籤所示。

AWS CLI
  1. 使用下列 AWS CLI 命令建立閘道,並將攔截器設定為傳遞請求標頭:

    aws bedrock-agentcore-control create-gateway \ --name my-gateway-with-headers \ --role-arn arn:aws:iam::123456789012:role/my-gateway-service-role \ --protocol-type MCP \ --authorizer-type CUSTOM_JWT \ --authorizer-configuration '{ "customJWTAuthorizer": { "discoveryUrl": "https://cognito-idp.us-west-2.amazonaws.com/some-user-pool/.well-known/openid-configuration", "allowedClients": ["clientId"] } }' \ --interceptor-configurations '[{ "interceptor": { "lambda": { "arn":"arn:aws:lambda:us-west-2:123456789012:function:my-interceptor-lambda" } }, "interceptionPoints": ["REQUEST", "RESPONSE"], "inputConfiguration": { "passRequestHeaders": true } }]'
AWS Python SDK (Boto3)
  1. 將下列 Python 程式碼與 AWS Python SDK (Boto3) 搭配使用,以建立具有設定為傳遞請求標頭之攔截器的閘道:

    import boto3 # Initialize the AgentCore client client = boto3.client('bedrock-agentcore-control') # Create a gateway gateway = client.create_gateway( name="my-gateway-with-headers", roleArn="arn:aws:iam::123456789012:role/my-gateway-service-role", protocolType="MCP", authorizerType="CUSTOM_JWT", authorizerConfiguration={ "customJWTAuthorizer": { "discoveryUrl": "https://cognito-idp.us-west-2.amazonaws.com/some-user-pool/.well-known/openid-configuration", "allowedClients": ["clientId"] } }, interceptorConfigurations=[{ "interceptor": { "lambda": { "arn":"arn:aws:lambda:us-west-2:123456789012:function:my-interceptor-lambda" } }, "interceptionPoints": ["REQUEST", "RESPONSE"], "inputConfiguration": { "passRequestHeaders": True } }] ) print(f"MCP Endpoint: {gateway['gatewayUrl']}")

更新攔截器組態

您可以使用更新閘道 API 操作來更新現有的閘道攔截器組態,以修改passRequestHeaders設定或其他參數。