AWS Fundamentals Logo
AWS Fundamentals
L2 Construct

TokenAuthorizer

Token based lambda authorizer that recognizes the caller's identity as a bearer token, such as a JSON Web Token (JWT) or an OAuth token. Based on the token, authorization is performed by a lambda function.

Import

import { TokenAuthorizer } from 'aws-cdk-lib/aws-apigateway';

Or use the module namespace:

import * as apigateway from 'aws-cdk-lib/aws-apigateway';
// apigateway.TokenAuthorizer

Properties

Configuration passed to the constructor as TokenAuthorizerProps.

identitySourceOptional
string

The request header mapping expression for the bearer token. This is typically passed as part of the header, in which case this should be `method.request.header.Authorizer` where `Authorizer` is the header containing the bearer token.

Default: `IdentitySource.header('Authorization')`

validationRegexOptional
string

An optional regex to be matched against the authorization token. When matched the authorizer lambda is invoked, otherwise a 401 Unauthorized is returned to the client.

Default: - no regex filter will be applied.

4 properties inherited from LambdaAuthorizerProps
handlerRequiredinherited from LambdaAuthorizerProps
IFunction

The handler for the authorizer lambda function. The handler must follow a very specific protocol on the input it receives and the output it needs to produce. API Gateway has documented the handler's [input specification](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-input.html) and [output specification](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-output.html).

assumeRoleOptionalinherited from LambdaAuthorizerProps
IRole

An optional IAM role for APIGateway to assume before calling the Lambda-based authorizer. The IAM role must be assumable by 'apigateway.amazonaws.com'.

Default: - A resource policy is added to the Lambda function allowing apigateway.amazonaws.com to invoke the function.

authorizerNameOptionalinherited from LambdaAuthorizerProps
string

An optional human friendly name for the authorizer. Note that, this is not the primary identifier of the authorizer.

Default: - the unique construct ID

resultsCacheTtlOptionalinherited from LambdaAuthorizerProps
Duration

How long APIGateway should cache the results. Max 1 hour. Disable caching by setting this to 0.

Default: - Duration.minutes(5)

Get the Amazon API Gateway Cheat Sheet

Everything you need to know about Amazon API Gateway on one page. HD quality, print-friendly.

Download Free Infographic