Skip to content
v2.277.0

Experimental

@aws-cdk/aws-bedrock-agentcore-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.

LambdaInterceptor Class ​

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 ​

ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import * as bedrock_agentcore_alpha from '@aws-cdk/aws-bedrock-agentcore-alpha';
import { aws_lambda as lambda } from 'aws-cdk-lib';

declare const function_: lambda.Function;
const lambdaInterceptor = bedrock_agentcore_alpha.LambdaInterceptor.forRequest(function_, /* all optional props */ {
  passRequestHeaders: false,
});
python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
import aws_cdk.aws_bedrock_agentcore_alpha as bedrock_agentcore_alpha
from aws_cdk import aws_lambda as lambda_

# function_: lambda.Function

lambda_interceptor = bedrock_agentcore_alpha.LambdaInterceptor.for_request(function_,
    pass_request_headers=False
)
java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.bedrock.agentcore.alpha.*;
import software.amazon.awscdk.services.lambda.*;

Function function_;

LambdaInterceptor lambdaInterceptor = LambdaInterceptor.forRequest(function_, InterceptorOptions.builder()
        .passRequestHeaders(false)
        .build());
csharp
// Install: dotnet add package Amazon.CDK.AWS.Bedrock.Agentcore.Alpha
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.Bedrock.Agentcore.Alpha;
using Amazon.CDK.AWS.Lambda;

Function function_;

var lambdaInterceptor = LambdaInterceptor.ForRequest(function_, new InterceptorOptions {
    PassRequestHeaders = false
});
go
// Install: go get github.com/aws/aws-cdk-go/awsbedrockagentcorealpha/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import bedrock_agentcore_alpha "github.com/aws/aws-cdk-go/awsbedrockagentcorealpha"
import "github.com/aws/aws-cdk-go/awscdk"

var function_ Function

lambdaInterceptor := bedrock_agentcore_alpha.LambdaInterceptor_ForRequest(function_, &InterceptorOptions{
	PassRequestHeaders: jsii.Boolean(false),
})

Properties ​

interceptionPointInterceptionPointinterception_pointInterceptionPointinterceptionPointInterceptionPointInterceptionPointInterceptionPointInterceptionPointInterceptionPoint#
The interception point (REQUEST or RESPONSE).

Methods ​

bind(_scope: Construct, gateway: IGateway): InterceptorBindConfigdef bind(self, _scope: Construct, gateway: IGateway) -> InterceptorBindConfigpublic InterceptorBindConfig bind(Construct _scope, IGateway gateway)public InterceptorBindConfig Bind(Construct _scope, IGateway gateway)func Bind(_scope Construct, Gateway IGateway) InterceptorBindConfig#
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
2 parameters · returns

Parameters

  • _scope_scope_scope_scope_scope — The construct scope (currently unused, reserved for future extensions).
  • gatewaygatewaygatewaygatewayGateway — The gateway this interceptor is being bound to.

Returns: Configuration for CloudFormation rendering

forRequest(lambdaFunction: IFunction, options?: InterceptorOptions): LambdaInterceptor // chainable@staticmethod def for_request(lambda_function: IFunction, options: typing.Optional[InterceptorOptions] = None) -> LambdaInterceptorpublic static LambdaInterceptor forRequest(IFunction lambdaFunction, InterceptorOptions options)public static LambdaInterceptor ForRequest(IFunction lambdaFunction, InterceptorOptions? options = null)func ForRequest(LambdaFunction IFunction, Options InterceptorOptions) LambdaInterceptorstatic#
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.

2 parameters · returns

Parameters

  • lambdaFunctionlambda_functionlambdaFunctionlambdaFunctionLambdaFunction — The Lambda function to invoke.
  • optionsoptionsoptionsoptionsOptions — Optional configuration for the interceptor.

Returns: A configured LambdaInterceptor for request interception

forResponse(lambdaFunction: IFunction, options?: InterceptorOptions): LambdaInterceptor // chainable@staticmethod def for_response(lambda_function: IFunction, options: typing.Optional[InterceptorOptions] = None) -> LambdaInterceptorpublic static LambdaInterceptor forResponse(IFunction lambdaFunction, InterceptorOptions options)public static LambdaInterceptor ForResponse(IFunction lambdaFunction, InterceptorOptions? options = null)func ForResponse(LambdaFunction IFunction, Options InterceptorOptions) LambdaInterceptorstatic#
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.

2 parameters · returns

Parameters

  • lambdaFunctionlambda_functionlambdaFunctionlambdaFunctionLambdaFunction — The Lambda function to invoke.
  • optionsoptionsoptionsoptionsOptions — Optional configuration for the interceptor.

Returns: A configured LambdaInterceptor for response interception