Skip to content
v2.278.0

RequestAuthorizerProps ​

Struct Stable

Properties for RequestAuthorizer.

Example ​

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

const auth = new apigateway.RequestAuthorizer(this, 'booksAuthorizer', {
  handler: authFn,
  identitySources: [apigateway.IdentitySource.header('Authorization')]
});

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


auth = apigateway.RequestAuthorizer(self, "booksAuthorizer",
    handler=auth_fn,
    identity_sources=[apigateway.IdentitySource.header("Authorization")]
)

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


RequestAuthorizer auth = RequestAuthorizer.Builder.create(this, "booksAuthorizer")
        .handler(authFn)
        .identitySources(List.of(IdentitySource.header("Authorization")))
        .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 RequestAuthorizer(this, "booksAuthorizer", new RequestAuthorizerProps {
    Handler = authFn,
    IdentitySources = new [] { IdentitySource.Header("Authorization") }
});

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.NewRequestAuthorizer(this, jsii.String("booksAuthorizer"), &RequestAuthorizerProps{
	Handler: authFn,
	IdentitySources: []*string{
		apigateway.IdentitySource_Header(jsii.String("Authorization")),
	},
})

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.

identitySourcesstring[]identity_sourcestyping.List[str]identitySourcesList<String>IdentitySourcesstring[]IdentitySources*[]*string required #
An array of request header mapping expressions for identities.
notes

Supported parameter types are Header, Query String, Stage Variable, and Context. For instance, extracting an authorization token from a header would use the identity source IdentitySource.header('Authorization').

Note: API Gateway uses the specified identity sources as the request authorizer caching key. When caching is enabled, API Gateway calls the authorizer's Lambda function only after successfully verifying that all the specified identity sources are present at runtime. If a specified identify source is missing, null, or empty, API Gateway returns a 401 Unauthorized response without calling the authorizer Lambda function.

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

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