RequestValidatorOptions

class aws_cdk.aws_apigateway.RequestValidatorOptions(*, request_validator_name=None, validate_request_body=None, validate_request_parameters=None)

Bases: object

Parameters
  • request_validator_name (Optional[str]) – The name of this request validator. Default: None

  • validate_request_body (Optional[bool]) – Indicates whether to validate the request body according to the configured schema for the targeted API and method. Default: false

  • validate_request_parameters (Optional[bool]) – Indicates whether to validate request parameters. Default: false

ExampleMetadata

infused

Example:

# integration is of type LambdaIntegration
# resource is of type Resource
# response_model is of type Model
# error_response_model is of type Model


resource.add_method("GET", integration,
    # We can mark the parameters as required
    request_parameters={
        "method.request.querystring.who": True
    },
    # we can set request validator options like below
    request_validator_options=apigateway.RequestValidatorOptions(
        request_validator_name="test-validator",
        validate_request_body=True,
        validate_request_parameters=False
    ),
    method_responses=[apigateway.MethodResponse(
        # Successful response from the integration
        status_code="200",
        # Define what parameters are allowed or not
        response_parameters={
            "method.response.header._content-_type": True,
            "method.response.header._access-_control-_allow-_origin": True,
            "method.response.header._access-_control-_allow-_credentials": True
        },
        # Validate the schema on the response
        response_models={
            "application/json": response_model
        }
    ), apigateway.MethodResponse(
        # Same thing for the error responses
        status_code="400",
        response_parameters={
            "method.response.header._content-_type": True,
            "method.response.header._access-_control-_allow-_origin": True,
            "method.response.header._access-_control-_allow-_credentials": True
        },
        response_models={
            "application/json": error_response_model
        }
    )
    ]
)

Attributes

request_validator_name

The name of this request validator.

Default

None

Return type

Optional[str]

validate_request_body

Indicates whether to validate the request body according to the configured schema for the targeted API and method.

Default

false

Return type

Optional[bool]

validate_request_parameters

Indicates whether to validate request parameters.

Default

false

Return type

Optional[bool]