RequestAuthorizerProps
Properties for RequestAuthorizer.
| Source | aws-apigateway/lib/authorizers/lambda.ts |
|---|
Example
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
});
# 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
)
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());
// 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
});
// 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 #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 #Default: the unique construct ID
Note that, this is not the primary identifier of the authorizer.
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 #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.