MethodOptions

class aws_cdk.aws_apigateway.MethodOptions(*, api_key_required=None, authorization_scopes=None, authorization_type=None, authorizer=None, method_responses=None, operation_name=None, request_models=None, request_parameters=None, request_validator=None, request_validator_options=None)

Bases: object

Parameters:
  • api_key_required (Optional[bool]) – Indicates whether the method requires clients to submit a valid API key. Default: false

  • authorization_scopes (Optional[Sequence[str]]) – A list of authorization scopes configured on the method. The scopes are used with a COGNITO_USER_POOLS authorizer to authorize the method invocation. Default: - no authorization scopes

  • authorization_type (Optional[AuthorizationType]) – Method authorization. If the value is set of Custom, an authorizer must also be specified. If you’re using one of the authorizers that are available via the Authorizer class, such as Authorizer#token(), it is recommended that this option not be specified. The authorizer will take care of setting the correct authorization type. However, specifying an authorization type using this property that conflicts with what is expected by the Authorizer will result in an error. Default: - open access unless authorizer is specified

  • authorizer (Optional[IAuthorizer]) – If authorizationType is Custom, this specifies the ID of the method authorizer resource. If specified, the value of authorizationType must be set to Custom

  • method_responses (Optional[Sequence[Union[MethodResponse, Dict[str, Any]]]]) – The responses that can be sent to the client who calls the method. Default: None This property is not required, but if these are not supplied for a Lambda proxy integration, the Lambda function must return a value of the correct format, for the integration response to be correctly mapped to a response to the client.

  • operation_name (Optional[str]) – A friendly operation name for the method. For example, you can assign the OperationName of ListPets for the GET /pets method.

  • request_models (Optional[Mapping[str, IModel]]) – The models which describe data structure of request payload. When combined with requestValidator or requestValidatorOptions, the service will validate the API request payload before it reaches the API’s Integration (including proxies). Specify requestModels as key-value pairs, with a content type (e.g. 'application/json') as the key and an API Gateway Model as the value.

  • request_parameters (Optional[Mapping[str, bool]]) – The request parameters that API Gateway accepts. Specify request parameters as key-value pairs (string-to-Boolean mapping), with a source as the key and a Boolean as the value. The Boolean specifies whether a parameter is required. A source must match the format method.request.location.name, where the location is querystring, path, or header, and name is a valid, unique parameter name. Default: None

  • request_validator (Optional[IRequestValidator]) – The ID of the associated request validator. Only one of requestValidator or requestValidatorOptions must be specified. Works together with requestModels or requestParameters to validate the request before it reaches integration like Lambda Proxy Integration. Default: - No default validator

  • request_validator_options (Union[RequestValidatorOptions, Dict[str, Any], None]) – Request validator options to create new validator Only one of requestValidator or requestValidatorOptions must be specified. Works together with requestModels or requestParameters to validate the request before it reaches integration like Lambda Proxy Integration. Default: - No default validator

ExampleMetadata:

infused

Example:

# api: apigateway.RestApi
# user_lambda: lambda.Function


user_model = api.add_model("UserModel",
    schema=apigateway.JsonSchema(
        type=apigateway.JsonSchemaType.OBJECT,
        properties={
            "user_id": apigateway.JsonSchema(
                type=apigateway.JsonSchemaType.STRING
            ),
            "name": apigateway.JsonSchema(
                type=apigateway.JsonSchemaType.STRING
            )
        },
        required=["userId"]
    )
)
api.root.add_resource("user").add_method("POST",
    apigateway.LambdaIntegration(user_lambda),
        request_models={
            "application/json": user_model
        }
    )

Attributes

api_key_required

Indicates whether the method requires clients to submit a valid API key.

Default:

false

authorization_scopes

A list of authorization scopes configured on the method.

The scopes are used with a COGNITO_USER_POOLS authorizer to authorize the method invocation.

Default:
  • no authorization scopes

See:

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-method.html#cfn-apigateway-method-authorizationscopes

authorization_type

Method authorization. If the value is set of Custom, an authorizer must also be specified.

If you’re using one of the authorizers that are available via the Authorizer class, such as Authorizer#token(), it is recommended that this option not be specified. The authorizer will take care of setting the correct authorization type. However, specifying an authorization type using this property that conflicts with what is expected by the Authorizer will result in an error.

Default:
  • open access unless authorizer is specified

authorizer

If authorizationType is Custom, this specifies the ID of the method authorizer resource.

If specified, the value of authorizationType must be set to Custom

method_responses

The responses that can be sent to the client who calls the method.

Default:

None

This property is not required, but if these are not supplied for a Lambda proxy integration, the Lambda function must return a value of the correct format, for the integration response to be correctly mapped to a response to the client.

See:

https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-method-settings-method-response.html

operation_name

A friendly operation name for the method.

For example, you can assign the OperationName of ListPets for the GET /pets method.

request_models

The models which describe data structure of request payload.

When combined with requestValidator or requestValidatorOptions, the service will validate the API request payload before it reaches the API’s Integration (including proxies). Specify requestModels as key-value pairs, with a content type (e.g. 'application/json') as the key and an API Gateway Model as the value.

See:

https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-method-settings-method-request.html#setup-method-request-model

Example:

# api: apigateway.RestApi
# user_lambda: lambda.Function


user_model = api.add_model("UserModel",
    schema=apigateway.JsonSchema(
        type=apigateway.JsonSchemaType.OBJECT,
        properties={
            "user_id": apigateway.JsonSchema(
                type=apigateway.JsonSchemaType.STRING
            ),
            "name": apigateway.JsonSchema(
                type=apigateway.JsonSchemaType.STRING
            )
        },
        required=["userId"]
    )
)
api.root.add_resource("user").add_method("POST",
    apigateway.LambdaIntegration(user_lambda),
        request_models={
            "application/json": user_model
        }
    )
request_parameters

The request parameters that API Gateway accepts.

Specify request parameters as key-value pairs (string-to-Boolean mapping), with a source as the key and a Boolean as the value. The Boolean specifies whether a parameter is required. A source must match the format method.request.location.name, where the location is querystring, path, or header, and name is a valid, unique parameter name.

Default:

None

request_validator

The ID of the associated request validator.

Only one of requestValidator or requestValidatorOptions must be specified. Works together with requestModels or requestParameters to validate the request before it reaches integration like Lambda Proxy Integration.

Default:
  • No default validator

request_validator_options

Request validator options to create new validator Only one of requestValidator or requestValidatorOptions must be specified.

Works together with requestModels or requestParameters to validate the request before it reaches integration like Lambda Proxy Integration.

Default:
  • No default validator