Skip to content
v2.278.0

TokenAuthorizerProps Struct ​

Properties for TokenAuthorizer.

Example ​

ts
declare const authFn: lambda.Function;
declare const books: apigateway.Resource;

const auth = new apigateway.TokenAuthorizer(this, 'booksAuthorizer', {
  handler: authFn
});

books.addMethod('GET', new apigateway.HttpIntegration('http://amazon.com'), {
  authorizer: auth
});
python
# auth_fn: lambda.Function
# books: apigateway.Resource


auth = apigateway.TokenAuthorizer(self, "booksAuthorizer",
    handler=auth_fn
)

books.add_method("GET", apigateway.HttpIntegration("http://amazon.com"),
    authorizer=auth
)
java
Function authFn;
Resource books;


TokenAuthorizer auth = TokenAuthorizer.Builder.create(this, "booksAuthorizer")
        .handler(authFn)
        .build();

books.addMethod("GET", new HttpIntegration("http://amazon.com"), MethodOptions.builder()
        .authorizer(auth)
        .build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
Function authFn;
Resource books;


var auth = new TokenAuthorizer(this, "booksAuthorizer", new TokenAuthorizerProps {
    Handler = authFn
});

books.AddMethod("GET", new HttpIntegration("http://amazon.com"), new MethodOptions {
    Authorizer = auth
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var authFn Function
var books Resource


auth := apigateway.NewTokenAuthorizer(this, jsii.String("booksAuthorizer"), &TokenAuthorizerProps{
	Handler: authFn,
})

books.AddMethod(jsii.String("GET"), apigateway.NewHttpIntegration(jsii.String("http://amazon.com")), &MethodOptions{
	Authorizer: auth,
})

Properties ​

assumeRoleoptionalIRoleassume_roleoptionalIRoleassumeRoleoptionalIRoleAssumeRoleoptionalIRoleAssumeRoleoptionalIRole #
An optional IAM role for APIGateway to assume before calling the Lambda-based authorizer.

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

The IAM role must be assumable by 'apigateway.amazonaws.com'.

authorizerNameoptionalstringauthorizer_nameoptionalstrauthorizerNameoptionalStringAuthorizerNameoptionalstringAuthorizerNameoptional*string #
An optional human friendly name for the authorizer.

Default: the unique construct ID

Note that, this is not the primary identifier of the authorizer.

handlerIFunctionhandlerIFunctionhandlerIFunctionHandlerIFunctionHandlerIFunction required #
The handler for the authorizer lambda function.
notes

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 and output specification.

identitySourceoptionalstringidentity_sourceoptionalstridentitySourceoptionalStringIdentitySourceoptionalstringIdentitySourceoptional*string #
The request header mapping expression for the bearer token.

Default: IdentitySource.header('Authorization')

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.

resultsCacheTtloptionalDurationresults_cache_ttloptionalDurationresultsCacheTtloptionalDurationResultsCacheTtloptionalDurationResultsCacheTtloptionalDuration = Duration.minutes(5) #
How long APIGateway should cache the results.

Max 1 hour. Disable caching by setting this to 0.

validationRegexoptionalstringvalidation_regexoptionalstrvalidationRegexoptionalStringValidationRegexoptionalstringValidationRegexoptional*string #
An optional regex to be matched against the authorization token.

Default: no regex filter will be applied.

When matched the authorizer lambda is invoked, otherwise a 401 Unauthorized is returned to the client.