HttpLambdaAuthorizer

class aws_cdk.aws_apigatewayv2_authorizers.HttpLambdaAuthorizer(id, handler, *, authorizer_name=None, identity_source=None, response_types=None, results_cache_ttl=None)

Bases: object

(experimental) Authorize Http Api routes via a lambda function.

Stability:

experimental

ExampleMetadata:

infused

Example:

from aws_cdk.aws_apigatewayv2_authorizers import HttpLambdaAuthorizer, HttpLambdaResponseType
from aws_cdk.aws_apigatewayv2_integrations import HttpUrlIntegration

# This function handles your auth logic
# auth_handler: lambda.Function


authorizer = HttpLambdaAuthorizer("BooksAuthorizer", auth_handler,
    response_types=[HttpLambdaResponseType.SIMPLE]
)

api = apigwv2.HttpApi(self, "HttpApi")

api.add_routes(
    integration=HttpUrlIntegration("BooksIntegration", "https://get-books-proxy.myproxy.internal"),
    path="/books",
    authorizer=authorizer
)

(experimental) Initialize a lambda authorizer to be bound with HTTP route.

Parameters:
  • id (str) – The id of the underlying construct.

  • handler (IFunction) –

  • authorizer_name (Optional[str]) – (experimental) Friendly authorizer name. Default: - same value as id passed in the constructor.

  • identity_source (Optional[Sequence[str]]) – (experimental) The identity source for which authorization is requested. Default: [‘$request.header.Authorization’]

  • response_types (Optional[Sequence[HttpLambdaResponseType]]) – (experimental) The types of responses the lambda can return. If HttpLambdaResponseType.SIMPLE is included then response format 2.0 will be used. Default: [HttpLambdaResponseType.IAM]

  • results_cache_ttl (Optional[Duration]) – (experimental) How long APIGateway should cache the results. Max 1 hour. Disable caching by setting this to Duration.seconds(0). Default: Duration.minutes(5)

Stability:

experimental

Methods

bind(*, route, scope)

(experimental) Bind this authorizer to a specified Http route.

Parameters:
  • route (IHttpRoute) – (experimental) The route to which the authorizer is being bound.

  • scope (Construct) – (experimental) The scope for any constructs created as part of the bind.

Stability:

experimental

Return type:

HttpRouteAuthorizerConfig