Skip to content

create_authorizer

create_authorizer(
    rest_api_id: String,
    name: String,
    type: AuthorizerType,
    *,
    config_overrides: Optional[APIGatewayClientConfig] = None,
    provider_ar_ns: Optional[ListOfARNs] = None,
    auth_type: Optional[String] = None,
    authorizer_uri: Optional[String] = None,
    authorizer_credentials: Optional[String] = None,
    identity_source: Optional[String] = None,
    identity_validation_expression: Optional[String] = None,
    authorizer_result_ttl_in_seconds: Optional[NullableInteger] = None,
) -> Authorizer

Adds a new Authorizer resource to an existing RestApi resource.

Parameters:

  • rest_api_id (String) –

    The string identifier of the associated RestApi.

  • name (String) –

    The name of the authorizer.

  • type (AuthorizerType) –

    The authorizer type. Valid values are TOKEN for a Lambda function using a single authorization token submitted in a custom header, REQUEST for a Lambda function using incoming request parameters, and COGNITO_USER_POOLS for using an Amazon Cognito user pool.

  • provider_ar_ns (Optional[ListOfARNs], default: None ) –

    A list of the Amazon Cognito user pool ARNs for the COGNITO_USER_POOLS authorizer. Each element is of this format: arn:aws:cognito-idp:{region}:{account_id}:userpool/{user_pool_id}. For a TOKEN or REQUEST authorizer, this is not defined.

  • auth_type (Optional[String], default: None ) –

    Optional customer-defined field, used in OpenAPI imports and exports without functional impact.

  • authorizer_uri (Optional[String], default: None ) –

    Specifies the authorizer's Uniform Resource Identifier (URI). For TOKEN or REQUEST authorizers, this must be a well-formed Lambda function URI, for example, arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:{account_id}:function:{lambda_function_name}/invocations. In general, the URI has this form arn:aws:apigateway:{region}:lambda:path/{service_api}, where {region} is the same as the region hosting the Lambda function, path indicates that the remaining substring in the URI should be treated as the path to the resource, including the initial /. For Lambda functions, this is usually of the form /2015-03-31/functions/[FunctionARN]/invocations.

  • authorizer_credentials (Optional[String], default: None ) –

    Specifies the required credentials as an IAM role for API Gateway to invoke the authorizer. To specify an IAM role for API Gateway to assume, use the role's Amazon Resource Name (ARN). To use resource-based permissions on the Lambda function, specify null.

  • identity_source (Optional[String], default: None ) –

    The identity source for which authorization is requested. For a TOKEN or COGNITO_USER_POOLS authorizer, this is required and specifies the request header mapping expression for the custom header holding the authorization token submitted by the client. For example, if the token header name is Auth, the header mapping expression is method.request.header.Auth. For the REQUEST authorizer, this is required when authorization caching is enabled. The value is a comma-separated string of one or more mapping expressions of the specified request parameters. For example, if an Auth header, a Name query string parameter are defined as identity sources, this value is method.request.header.Auth, method.request.querystring.Name. These parameters will be used to derive the authorization caching key and to perform runtime validation of the REQUEST authorizer by verifying all of the identity-related request parameters are present, not null and non-empty. Only when this is true does the authorizer invoke the authorizer Lambda function, otherwise, it returns a 401 Unauthorized response without calling the Lambda function. The valid value is a string of comma-separated mapping expressions of the specified request parameters. When the authorization caching is not enabled, this property is optional.

  • identity_validation_expression (Optional[String], default: None ) –

    A validation expression for the incoming identity token. For TOKEN authorizers, this value is a regular expression. For COGNITO_USER_POOLS authorizers, API Gateway will match the aud field of the incoming token from the client against the specified regular expression. It will invoke the authorizer's Lambda function when there is a match. Otherwise, it will return a 401 Unauthorized response without calling the Lambda function. The validation expression does not apply to the REQUEST authorizer.

  • authorizer_result_ttl_in_seconds (Optional[NullableInteger], default: None ) –

    The TTL in seconds of cached authorizer results. If it equals 0, authorization caching is disabled. If it is greater than 0, API Gateway will cache authorizer responses. If this field is not set, the default value is 300. The maximum value is 3600, or 1 hour.

Raises:

  • BadRequestException –

    The submitted request is not valid, for example, the input is incomplete or incorrect. See the accompanying error message for details.

  • ConflictException –

    The request configuration has conflicts. For details, see the accompanying error message.

  • LimitExceededException –

    The request exceeded the rate limit. Retry after the specified time period.

  • NotFoundException –

    The requested resource is not found. Make sure that the request URI is correct.

  • TooManyRequestsException –

    The request has reached its throttling limit. Retry after the specified time period.

  • UnauthorizedException –

    The request is denied because the caller has insufficient permissions.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_api_gateway/_services/api_gateway.py
def create_authorizer(
    self,
    rest_api_id: "capo_api_gateway.types.string.String",
    name: "capo_api_gateway.types.string.String",
    type: "capo_api_gateway.types.authorizer_type.AuthorizerType",
    *,
    config_overrides: Optional[APIGatewayClientConfig] = None,
    provider_ar_ns: Optional[
        "capo_api_gateway.types.list_of_ar_ns.ListOfARNs"
    ] = None,
    auth_type: Optional["capo_api_gateway.types.string.String"] = None,
    authorizer_uri: Optional["capo_api_gateway.types.string.String"] = None,
    authorizer_credentials: Optional["capo_api_gateway.types.string.String"] = None,
    identity_source: Optional["capo_api_gateway.types.string.String"] = None,
    identity_validation_expression: Optional[
        "capo_api_gateway.types.string.String"
    ] = None,
    authorizer_result_ttl_in_seconds: Optional[
        "capo_api_gateway.types.nullable_integer.NullableInteger"
    ] = None,
) -> "capo_api_gateway.types.authorizer.Authorizer":
    """<p>Adds a new Authorizer resource to an existing RestApi resource.</p>

    Args:
        rest_api_id: <p>The string identifier of the associated RestApi.</p>
        name: <p>The name of the authorizer.</p>
        type: <p>The authorizer type. Valid values are <code>TOKEN</code> for a Lambda function using a single authorization token submitted in a custom header, <code>REQUEST</code> for a Lambda function using incoming request parameters, and <code>COGNITO_USER_POOLS</code> for using an Amazon Cognito user pool.</p>
        provider_ar_ns: <p>A list of the Amazon Cognito user pool ARNs for the <code>COGNITO_USER_POOLS</code> authorizer. Each element is of this format: <code>arn:aws:cognito-idp:{region}:{account_id}:userpool/{user_pool_id}</code>. For a <code>TOKEN</code> or <code>REQUEST</code> authorizer, this is not defined. </p>
        auth_type: <p>Optional customer-defined field, used in OpenAPI imports and exports without functional impact.</p>
        authorizer_uri: <p>Specifies the authorizer's Uniform Resource Identifier (URI). For <code>TOKEN</code> or <code>REQUEST</code> authorizers, this must be a well-formed Lambda function URI, for example, <code>arn:aws:apigateway:us-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:us-west-2:{account_id}:function:{lambda_function_name}/invocations</code>. In general, the URI has this form <code>arn:aws:apigateway:{region}:lambda:path/{service_api}</code>, where <code>{region}</code> is the same as the region hosting the Lambda function, <code>path</code> indicates that the remaining substring in the URI should be treated as the path to the resource, including the initial <code>/</code>. For Lambda functions, this is usually of the form <code>/2015-03-31/functions/[FunctionARN]/invocations</code>.</p>
        authorizer_credentials: <p>Specifies the required credentials as an IAM role for API Gateway to invoke the authorizer. To specify an IAM role for API Gateway to assume, use the role's Amazon Resource Name (ARN). To use resource-based permissions on the Lambda function, specify null.</p>
        identity_source: <p>The identity source for which authorization is requested. For a <code>TOKEN</code> or <code>COGNITO_USER_POOLS</code> authorizer, this is required and specifies the request header mapping expression for the custom header holding the authorization token submitted by the client. For example, if the token header name is <code>Auth</code>, the header mapping expression is <code>method.request.header.Auth</code>. For the <code>REQUEST</code> authorizer, this is required when authorization caching is enabled. The value is a comma-separated string of one or more mapping expressions of the specified request parameters. For example, if an <code>Auth</code> header, a <code>Name</code> query string parameter are defined as identity sources, this value is <code>method.request.header.Auth, method.request.querystring.Name</code>. These parameters will be used to derive the authorization caching key and to perform runtime validation of the <code>REQUEST</code> authorizer by verifying all of the identity-related request parameters are present, not null and non-empty. Only when this is true does the authorizer invoke the authorizer Lambda function, otherwise, it returns a 401 Unauthorized response without calling the Lambda function. The valid value is a string of comma-separated mapping expressions of the specified request parameters. When the authorization caching is not enabled, this property is optional.</p>
        identity_validation_expression: <p>A validation expression for the incoming identity token. For <code>TOKEN</code> authorizers, this value is a regular expression. For <code>COGNITO_USER_POOLS</code> authorizers, API Gateway will match the <code>aud</code> field of the incoming token from the client against the specified regular expression. It will invoke the authorizer's Lambda function when there is a match. Otherwise, it will return a 401 Unauthorized response without calling the Lambda function. The validation expression does not apply to the <code>REQUEST</code> authorizer.</p>
        authorizer_result_ttl_in_seconds: <p>The TTL in seconds of cached authorizer results. If it equals 0, authorization caching is disabled. If it is greater than 0, API Gateway will cache authorizer responses. If this field is not set, the default value is 300. The maximum value is 3600, or 1 hour.</p>

    Raises:
        capo_api_gateway.errors.bad_request_exception.BadRequestException: <p>The submitted request is not valid, for example, the input is incomplete or incorrect. See the accompanying error message for details.</p>
        capo_api_gateway.errors.conflict_exception.ConflictException: <p>The request configuration has conflicts. For details, see the accompanying error message.</p>
        capo_api_gateway.errors.limit_exceeded_exception.LimitExceededException: <p>The request exceeded the rate limit. Retry after the specified time period.</p>
        capo_api_gateway.errors.not_found_exception.NotFoundException: <p>The requested resource is not found. Make sure that the request URI is correct.</p>
        capo_api_gateway.errors.too_many_requests_exception.TooManyRequestsException: <p>The request has reached its throttling limit. Retry after the specified time period.</p>
        capo_api_gateway.errors.unauthorized_exception.UnauthorizedException: <p>The request is denied because the caller has insufficient permissions.</p>
        capo_api_gateway.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_api_gateway.types.create_authorizer_request.CreateAuthorizerRequest]",
    ) -> OperationResponse["capo_api_gateway.types.authorizer.Authorizer"]:
        import capo_api_gateway._operations.backplane_control_service.create_authorizer

        output, http_response = (
            capo_api_gateway._operations.backplane_control_service.create_authorizer.create_authorizer(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateAuthorizer")
    )
    input_: capo_api_gateway.types.create_authorizer_request.CreateAuthorizerRequest = {
        "rest_api_id": rest_api_id,
        "name": name,
        "type": type,
    }
    if provider_ar_ns is not None:
        input_["provider_ar_ns"] = provider_ar_ns
    if auth_type is not None:
        input_["auth_type"] = auth_type
    if authorizer_uri is not None:
        input_["authorizer_uri"] = authorizer_uri
    if authorizer_credentials is not None:
        input_["authorizer_credentials"] = authorizer_credentials
    if identity_source is not None:
        input_["identity_source"] = identity_source
    if identity_validation_expression is not None:
        input_["identity_validation_expression"] = identity_validation_expression
    if authorizer_result_ttl_in_seconds is not None:
        input_["authorizer_result_ttl_in_seconds"] = (
            authorizer_result_ttl_in_seconds
        )

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output