RequestValidatorOptions Struct
| Source | aws-apigateway/lib/requestvalidator.ts |
|---|
Example
ts
declare const integration: apigateway.LambdaIntegration;
declare const resource: apigateway.Resource;
declare const responseModel: apigateway.Model;
declare const errorResponseModel: apigateway.Model;
resource.addMethod('GET', integration, {
// We can mark the parameters as required
requestParameters: {
'method.request.querystring.who': true
},
// we can set request validator options like below
requestValidatorOptions: {
requestValidatorName: 'test-validator',
validateRequestBody: true,
validateRequestParameters: false
},
methodResponses: [
{
// Successful response from the integration
statusCode: '200',
// Define what parameters are allowed or not
responseParameters: {
'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
responseModels: {
'application/json': responseModel
}
},
{
// Same thing for the error responses
statusCode: '400',
responseParameters: {
'method.response.header.Content-Type': true,
'method.response.header.Access-Control-Allow-Origin': true,
'method.response.header.Access-Control-Allow-Credentials': true
},
responseModels: {
'application/json': errorResponseModel
}
}
]
});
python
# integration: apigateway.LambdaIntegration
# resource: apigateway.Resource
# response_model: apigateway.Model
# error_response_model: apigateway.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
}
)
]
)
java
LambdaIntegration integration;
Resource resource;
Model responseModel;
Model errorResponseModel;
resource.addMethod("GET", integration, MethodOptions.builder()
// We can mark the parameters as required
.requestParameters(Map.of(
"method.request.querystring.who", true))
// we can set request validator options like below
.requestValidatorOptions(RequestValidatorOptions.builder()
.requestValidatorName("test-validator")
.validateRequestBody(true)
.validateRequestParameters(false)
.build())
.methodResponses(List.of(MethodResponse.builder()
// Successful response from the integration
.statusCode("200")
// Define what parameters are allowed or not
.responseParameters(Map.of(
"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
.responseModels(Map.of(
"application/json", responseModel))
.build(), MethodResponse.builder()
// Same thing for the error responses
.statusCode("400")
.responseParameters(Map.of(
"method.response.header.Content-Type", true,
"method.response.header.Access-Control-Allow-Origin", true,
"method.response.header.Access-Control-Allow-Credentials", true))
.responseModels(Map.of(
"application/json", errorResponseModel))
.build()))
.build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
LambdaIntegration integration;
Resource resource;
Model responseModel;
Model errorResponseModel;
resource.AddMethod("GET", integration, new MethodOptions {
// We can mark the parameters as required
RequestParameters = new Dictionary<string, boolean> {
{ "method.request.querystring.who", true }
},
// we can set request validator options like below
RequestValidatorOptions = new RequestValidatorOptions {
RequestValidatorName = "test-validator",
ValidateRequestBody = true,
ValidateRequestParameters = false
},
MethodResponses = new [] { new MethodResponse {
// Successful response from the integration
StatusCode = "200",
// Define what parameters are allowed or not
ResponseParameters = new Dictionary<string, boolean> {
{ "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
ResponseModels = new Dictionary<string, IModel> {
{ "application/json", responseModel }
}
}, new MethodResponse {
// Same thing for the error responses
StatusCode = "400",
ResponseParameters = new Dictionary<string, boolean> {
{ "method.response.header.Content-Type", true },
{ "method.response.header.Access-Control-Allow-Origin", true },
{ "method.response.header.Access-Control-Allow-Credentials", true }
},
ResponseModels = new Dictionary<string, IModel> {
{ "application/json", errorResponseModel }
}
} }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var integration LambdaIntegration
var resource Resource
var responseModel Model
var errorResponseModel Model
resource.AddMethod(jsii.String("GET"), integration, &MethodOptions{
// We can mark the parameters as required
RequestParameters: map[string]*bool{
"method.request.querystring.who": jsii.Boolean(true),
},
// we can set request validator options like below
RequestValidatorOptions: &RequestValidatorOptions{
RequestValidatorName: jsii.String("test-validator"),
ValidateRequestBody: jsii.Boolean(true),
ValidateRequestParameters: jsii.Boolean(false),
},
MethodResponses: []MethodResponse{
&MethodResponse{
// Successful response from the integration
StatusCode: jsii.String("200"),
// Define what parameters are allowed or not
ResponseParameters: map[string]*bool{
"method.response.header.Content-Type": jsii.Boolean(true),
"method.response.header.Access-Control-Allow-Origin": jsii.Boolean(true),
"method.response.header.Access-Control-Allow-Credentials": jsii.Boolean(true),
},
// Validate the schema on the response
ResponseModels: map[string]IModel{
"application/json": responseModel,
},
},
&MethodResponse{
// Same thing for the error responses
StatusCode: jsii.String("400"),
ResponseParameters: map[string]*bool{
"method.response.header.Content-Type": jsii.Boolean(true),
"method.response.header.Access-Control-Allow-Origin": jsii.Boolean(true),
"method.response.header.Access-Control-Allow-Credentials": jsii.Boolean(true),
},
ResponseModels: map[string]IModel{
"application/json": errorResponseModel,
},
},
},
})
Properties
requestValidatorNameoptionalstringrequest_validator_nameoptionalstrrequestValidatorNameoptionalStringRequestValidatorNameoptionalstringRequestValidatorNameoptional*string = None #The name of this request validator.
validateRequestBodyoptionalbooleanvalidate_request_bodyoptionalboolvalidateRequestBodyoptionalBooleanValidateRequestBodyoptionalboolValidateRequestBodyoptional*bool = false #Indicates whether to validate the request body according to the configured schema for the targeted API and method.
validateRequestParametersoptionalbooleanvalidate_request_parametersoptionalboolvalidateRequestParametersoptionalBooleanValidateRequestParametersoptionalboolValidateRequestParametersoptional*bool = false #Indicates whether to validate request parameters.