# LambdaInterceptor

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

Implements: [IInterceptor](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-bedrock-agentcore-alpha.IInterceptor.html)
Obtainable from: LambdaInterceptor.forRequest, LambdaInterceptor.forResponse

- Source: [`lib/gateway/interceptor.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/@aws-cdk/aws-bedrock-agentcore-alpha/lib/gateway/interceptor.ts#L100)

## Example

TypeScript:

```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:

```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:

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

C# / .NET:

```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
});
```

Golang:

```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

- `interceptionPoint`: [InterceptionPoint](https://docs.aws.amazon.com/cdk/api/v2/docs/@aws-cdk_aws-bedrock-agentcore-alpha.InterceptionPoint.html) — The interception point (REQUEST or RESPONSE).

## Methods

- `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

  **Parameters**

  - `_scope` — The construct scope (currently unused, reserved for future extensions).
  - `gateway` — The gateway this interceptor is being bound to.

  **Returns:** Configuration for CloudFormation rendering

- `forRequest(lambdaFunction: IFunction, options?: InterceptorOptions): LambdaInterceptor // chainable` (static) — 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.
  - `options` — Optional configuration for the interceptor.

  **Returns:** A configured LambdaInterceptor for request interception

- `forResponse(lambdaFunction: IFunction, options?: InterceptorOptions): LambdaInterceptor // chainable` (static) — 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.
  - `options` — Optional configuration for the interceptor.

  **Returns:** A configured LambdaInterceptor for response interception
