RequestAuthorizer

class aws_cdk.aws_apigateway.RequestAuthorizer(scope, id, *, identity_sources, handler, assume_role=None, authorizer_name=None, results_cache_ttl=None)

Bases: Authorizer

Request-based lambda authorizer that recognizes the caller’s identity via request parameters, such as headers, paths, query strings, stage variables, or context variables.

Based on the request, authorization is performed by a lambda function.

Resource:

AWS::ApiGateway::Authorizer

ExampleMetadata:

infused

Example:

# 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
)
Parameters:
  • scope (Construct) –

  • id (str) –

  • identity_sources (Sequence[str]) – An array of request header mapping expressions for identities. 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.

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

  • assume_role (Optional[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.

  • authorizer_name (Optional[str]) – An optional human friendly name for the authorizer. Note that, this is not the primary identifier of the authorizer. Default: - the unique construct ID

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

Methods

apply_removal_policy(policy)

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you’ve removed it from the CDK application or because you’ve made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).

Parameters:

policy (RemovalPolicy) –

Return type:

None

to_string()

Returns a string representation of this construct.

Return type:

str

Attributes

authorization_type

The authorization type of this authorizer.

authorizer_arn

The ARN of the authorizer to be used in permission policies, such as IAM and resource-based grants.

authorizer_id

The id of the authorizer.

env

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.

node

The tree node.

stack

The stack in which this resource is defined.

Static Methods

classmethod is_authorizer(x)

Return whether the given object is an Authorizer.

Parameters:

x (Any) –

Return type:

bool

classmethod is_construct(x)

Checks if x is a construct.

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters:

x (Any) – Any object.

Return type:

bool

Returns:

true if x is an object created from a class which extends Construct.

classmethod is_owned_resource(construct)

Returns true if the construct was created by CDK, and false otherwise.

Parameters:

construct (IConstruct) –

Return type:

bool

classmethod is_resource(construct)

Check whether the given construct is a Resource.

Parameters:

construct (IConstruct) –

Return type:

bool