InterceptorOptions Struct
Options for configuring an interceptor.
| Source | aws-bedrockagentcore/lib/gateway/interceptor.ts |
|---|---|
| Type last changed |
Example
ts
// Create Lambda functions for interceptors
const requestInterceptorFn = new lambda.Function(this, "RequestInterceptor", {
runtime: lambda.Runtime.PYTHON_3_12,
handler: "index.handler",
code: lambda.Code.fromInline(`
def handler(event, context):
# Validate and transform request
return {
"interceptorOutputVersion": "1.0",
"mcp": {
"transformedGatewayRequest": event["mcp"]["gatewayRequest"]
}
}
`),
});
const responseInterceptorFn = new lambda.Function(this, "ResponseInterceptor", {
runtime: lambda.Runtime.PYTHON_3_12,
handler: "index.handler",
code: lambda.Code.fromInline(`
def handler(event, context):
# Filter or transform response
return {
"interceptorOutputVersion": "1.0",
"mcp": {
"transformedGatewayResponse": event["mcp"]["gatewayResponse"]
}
}
`),
});
// Create gateway with interceptors
const gateway = new agentcore.Gateway(this, "MyGateway", {
gatewayName: "my-gateway",
interceptorConfigurations: [
agentcore.LambdaInterceptor.forRequest(requestInterceptorFn, {
passRequestHeaders: true // Only if you need to inspect headers
}),
agentcore.LambdaInterceptor.forResponse(responseInterceptorFn)
]
});
python
# Create Lambda functions for interceptors
request_interceptor_fn = lambda_.Function(self, "RequestInterceptor",
runtime=lambda_.Runtime.PYTHON_3_12,
handler="index.handler",
code=lambda_.Code.from_inline("""
def handler(event, context):
# Validate and transform request
return {
"interceptorOutputVersion": "1.0",
"mcp": {
"transformedGatewayRequest": event["mcp"]["gatewayRequest"]
}
}
""")
)
response_interceptor_fn = lambda_.Function(self, "ResponseInterceptor",
runtime=lambda_.Runtime.PYTHON_3_12,
handler="index.handler",
code=lambda_.Code.from_inline("""
def handler(event, context):
# Filter or transform response
return {
"interceptorOutputVersion": "1.0",
"mcp": {
"transformedGatewayResponse": event["mcp"]["gatewayResponse"]
}
}
""")
)
# Create gateway with interceptors
gateway = agentcore.Gateway(self, "MyGateway",
gateway_name="my-gateway",
interceptor_configurations=[
agentcore.LambdaInterceptor.for_request(request_interceptor_fn,
pass_request_headers=True
),
agentcore.LambdaInterceptor.for_response(response_interceptor_fn)
]
)
java
// Create Lambda functions for interceptors
Function requestInterceptorFn = Function.Builder.create(this, "RequestInterceptor")
.runtime(Runtime.PYTHON_3_12)
.handler("index.handler")
.code(Code.fromInline("\ndef handler(event, context):\n # Validate and transform request\n return {\n \"interceptorOutputVersion\": \"1.0\",\n \"mcp\": {\n \"transformedGatewayRequest\": event[\"mcp\"][\"gatewayRequest\"]\n }\n }\n "))
.build();
Function responseInterceptorFn = Function.Builder.create(this, "ResponseInterceptor")
.runtime(Runtime.PYTHON_3_12)
.handler("index.handler")
.code(Code.fromInline("\ndef handler(event, context):\n # Filter or transform response\n return {\n \"interceptorOutputVersion\": \"1.0\",\n \"mcp\": {\n \"transformedGatewayResponse\": event[\"mcp\"][\"gatewayResponse\"]\n }\n }\n "))
.build();
// Create gateway with interceptors
Gateway gateway = Gateway.Builder.create(this, "MyGateway")
.gatewayName("my-gateway")
.interceptorConfigurations(List.of(LambdaInterceptor.forRequest(requestInterceptorFn, InterceptorOptions.builder()
.passRequestHeaders(true)
.build()), LambdaInterceptor.forResponse(responseInterceptorFn)))
.build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
// Create Lambda functions for interceptors
var requestInterceptorFn = new Function(this, "RequestInterceptor", new FunctionProps {
Runtime = Runtime.PYTHON_3_12,
Handler = "index.handler",
Code = Code.FromInline(@"
def handler(event, context):
# Validate and transform request
return {
""interceptorOutputVersion"": ""1.0"",
""mcp"": {
""transformedGatewayRequest"": event[""mcp""][""gatewayRequest""]
}
}
")
});
var responseInterceptorFn = new Function(this, "ResponseInterceptor", new FunctionProps {
Runtime = Runtime.PYTHON_3_12,
Handler = "index.handler",
Code = Code.FromInline(@"
def handler(event, context):
# Filter or transform response
return {
""interceptorOutputVersion"": ""1.0"",
""mcp"": {
""transformedGatewayResponse"": event[""mcp""][""gatewayResponse""]
}
}
")
});
// Create gateway with interceptors
var gateway = new Gateway(this, "MyGateway", new GatewayProps {
GatewayName = "my-gateway",
InterceptorConfigurations = new [] { LambdaInterceptor.ForRequest(requestInterceptorFn, new InterceptorOptions {
PassRequestHeaders = true
}), LambdaInterceptor.ForResponse(responseInterceptorFn) }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// Create Lambda functions for interceptors
requestInterceptorFn := lambda.NewFunction(this, jsii.String("RequestInterceptor"), &FunctionProps{
Runtime: lambda.Runtime_PYTHON_3_12(),
Handler: jsii.String("index.handler"),
Code: lambda.Code_FromInline(jsii.String(`
def handler(event, context):
# Validate and transform request
return {
"interceptorOutputVersion": "1.0",
"mcp": {
"transformedGatewayRequest": event["mcp"]["gatewayRequest"]
}
}
`)),
})
responseInterceptorFn := lambda.NewFunction(this, jsii.String("ResponseInterceptor"), &FunctionProps{
Runtime: lambda.Runtime_PYTHON_3_12(),
Handler: jsii.String("index.handler"),
Code: lambda.Code_*FromInline(jsii.String(`
def handler(event, context):
# Filter or transform response
return {
"interceptorOutputVersion": "1.0",
"mcp": {
"transformedGatewayResponse": event["mcp"]["gatewayResponse"]
}
}
`)),
})
// Create gateway with interceptors
gateway := agentcore.NewGateway(this, jsii.String("MyGateway"), &GatewayProps{
GatewayName: jsii.String("my-gateway"),
InterceptorConfigurations: []IInterceptor{
agentcore.LambdaInterceptor_ForRequest(requestInterceptorFn, &InterceptorOptions{
PassRequestHeaders: jsii.Boolean(true),
}),
agentcore.LambdaInterceptor_ForResponse(responseInterceptorFn),
},
})
Properties
passRequestHeadersoptionalbooleanpass_request_headersoptionalboolpassRequestHeadersoptionalBooleanPassRequestHeadersoptionalboolPassRequestHeadersoptional*bool #Whether to pass request headers to the interceptor Lambda function.
Default: false - Headers are not passed to interceptor for security
notes
Security Warning: Request headers can contain sensitive information such as authentication tokens and credentials. Only enable this if your interceptor needs access to headers and you have verified that sensitive information is not logged or exposed.