Class LambdaInterceptor

java.lang.Object
software.amazon.jsii.JsiiObject
software.amazon.awscdk.services.bedrockagentcore.LambdaInterceptor
All Implemented Interfaces:
IInterceptor, software.amazon.jsii.JsiiSerializable

@Generated(value="jsii-pacmak/1.129.0 (build eaca441)", date="2026-05-19T08:18:44.452Z") @Stability(Stable) public class LambdaInterceptor extends software.amazon.jsii.JsiiObject implements IInterceptor
A Lambda-based interceptor for Gateway.

Interceptors allow you to run custom code during each invocation of your gateway:

  • REQUEST interceptors execute before calling the target
  • RESPONSE interceptors execute after the target responds

Example:

 // 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();
 

See Also:
  • Constructor Details

    • LambdaInterceptor

      protected LambdaInterceptor(software.amazon.jsii.JsiiObjectRef objRef)
    • LambdaInterceptor

      protected LambdaInterceptor(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
  • Method Details

    • forRequest

      @Stability(Stable) @NotNull public static LambdaInterceptor forRequest(@NotNull IFunction lambdaFunction, @Nullable InterceptorOptions options)
      Create a REQUEST interceptor that executes before the gateway calls the target.

      Important: When this interceptor is added to a gateway, the gateway's IAM role will automatically be granted lambda:InvokeFunction permission on the specified Lambda function.

      Parameters:
      lambdaFunction - The Lambda function to invoke. This parameter is required.
      options - Optional configuration for the interceptor.
      Returns:
      A configured LambdaInterceptor for request interception
    • forRequest

      @Stability(Stable) @NotNull public static LambdaInterceptor forRequest(@NotNull IFunction lambdaFunction)
      Create a REQUEST interceptor that executes before the gateway calls the target.

      Important: When this interceptor is added to a gateway, the gateway's IAM role will automatically be granted lambda:InvokeFunction permission on the specified Lambda function.

      Parameters:
      lambdaFunction - The Lambda function to invoke. This parameter is required.
      Returns:
      A configured LambdaInterceptor for request interception
    • forResponse

      @Stability(Stable) @NotNull public static LambdaInterceptor forResponse(@NotNull IFunction lambdaFunction, @Nullable InterceptorOptions options)
      Create a RESPONSE interceptor that executes after the target responds.

      Important: When this interceptor is added to a gateway, the gateway's IAM role will automatically be granted lambda:InvokeFunction permission on the specified Lambda function.

      Parameters:
      lambdaFunction - The Lambda function to invoke. This parameter is required.
      options - Optional configuration for the interceptor.
      Returns:
      A configured LambdaInterceptor for response interception
    • forResponse

      @Stability(Stable) @NotNull public static LambdaInterceptor forResponse(@NotNull IFunction lambdaFunction)
      Create a RESPONSE interceptor that executes after the target responds.

      Important: When this interceptor is added to a gateway, the gateway's IAM role will automatically be granted lambda:InvokeFunction permission on the specified Lambda function.

      Parameters:
      lambdaFunction - The Lambda function to invoke. This parameter is required.
      Returns:
      A configured LambdaInterceptor for response interception
    • bind

      @Stability(Stable) @NotNull public InterceptorBindConfig bind(@NotNull software.constructs.Construct _scope, @NotNull IGateway gateway)
      Binds this Lambda interceptor to a Gateway.

      This method:

      1. Grants the Gateway's IAM role permission to invoke the Lambda function
      2. Returns the CloudFormation configuration for this interceptor

      Specified by:
      bind in interface IInterceptor
      Parameters:
      _scope - The construct scope (currently unused, reserved for future extensions). This parameter is required.
      gateway - The gateway this interceptor is being bound to. This parameter is required.
      Returns:
      Configuration for CloudFormation rendering
    • getInterceptionPoint

      @Stability(Stable) @NotNull public InterceptionPoint getInterceptionPoint()
      The interception point (REQUEST or RESPONSE).
      Specified by:
      getInterceptionPoint in interface IInterceptor