MethodOptions Struct
Example
declare const api: apigateway.RestApi;
declare const userLambda: lambda.Function;
const userModel: apigateway.Model = api.addModel('UserModel', {
schema: {
type: apigateway.JsonSchemaType.OBJECT,
properties: {
userId: {
type: apigateway.JsonSchemaType.STRING
},
name: {
type: apigateway.JsonSchemaType.STRING
}
},
required: ['userId']
}
});
api.root.addResource('user').addMethod('POST',
new apigateway.LambdaIntegration(userLambda), {
requestModels: {
'application/json': userModel
}
}
);
# 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
}
)
RestApi api;
Function userLambda;
Model userModel = api.addModel("UserModel", ModelOptions.builder()
.schema(JsonSchema.builder()
.type(JsonSchemaType.OBJECT)
.properties(Map.of(
"userId", JsonSchema.builder()
.type(JsonSchemaType.STRING)
.build(),
"name", JsonSchema.builder()
.type(JsonSchemaType.STRING)
.build()))
.required(List.of("userId"))
.build())
.build());
api.root.addResource("user").addMethod("POST",
new LambdaIntegration(userLambda), MethodOptions.builder()
.requestModels(Map.of(
"application/json", userModel))
.build());
// Install: dotnet add package Amazon.CDK.Lib
RestApi api;
Function userLambda;
var userModel = api.AddModel("UserModel", new ModelOptions {
Schema = new JsonSchema {
Type = JsonSchemaType.OBJECT,
Properties = new Dictionary<string, JsonSchema> {
{ "userId", new JsonSchema {
Type = JsonSchemaType.STRING
} },
{ "name", new JsonSchema {
Type = JsonSchemaType.STRING
} }
},
Required = new [] { "userId" }
}
});
api.Root.AddResource("user").AddMethod("POST",
new LambdaIntegration(userLambda), new MethodOptions {
RequestModels = new Dictionary<string, IModel> {
{ "application/json", userModel }
}
});
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var api RestApi
var userLambda Function
userModel := api.AddModel(jsii.String("UserModel"), &ModelOptions{
Schema: &JsonSchema{
Type: apigateway.JsonSchemaType_OBJECT,
Properties: map[string]JsonSchema{
"userId": &JsonSchema{
"type": apigateway.JsonSchemaType_STRING,
},
"name": &JsonSchema{
"type": apigateway.JsonSchemaType_STRING,
},
},
Required: []*string{
jsii.String("userId"),
},
},
})
api.Root.AddResource(jsii.String("user")).AddMethod(jsii.String("POST"),
apigateway.NewLambdaIntegration(userLambda), &MethodOptions{
RequestModels: map[string]IModel{
"application/json": userModel,
},
})
Properties
apiKeyRequiredoptionalbooleanapi_key_requiredoptionalboolapiKeyRequiredoptionalBooleanApiKeyRequiredoptionalboolApiKeyRequiredoptional*bool= false#authorizationScopesoptionalstring[]authorization_scopesoptionaltyping.List[str]authorizationScopesoptionalList<String>AuthorizationScopesoptionalstring[]AuthorizationScopesoptional*[]*string#Default: no authorization scopes
The scopes are used with a COGNITO_USER_POOLS authorizer to authorize the method invocation.
authorizationTypeoptionalAuthorizationTypeauthorization_typeoptionalAuthorizationTypeauthorizationTypeoptionalAuthorizationTypeAuthorizationTypeoptionalAuthorizationTypeAuthorizationTypeoptionalAuthorizationType#Default: open access unless authorizer is specified
notes
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.
authorizeroptionalIAuthorizerauthorizeroptionalIAuthorizerauthorizeroptionalIAuthorizerAuthorizeroptionalIAuthorizerAuthorizeroptionalIAuthorizer#If specified, the value of authorizationType must be set to Custom
methodResponsesoptionalMethodResponse[]method_responsesoptionaltyping.List[MethodResponse]methodResponsesoptionalList<MethodResponse>MethodResponsesoptionalMethodResponse[]MethodResponsesoptional*[]MethodResponse#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.
operationNameoptionalstringoperation_nameoptionalstroperationNameoptionalStringOperationNameoptionalstringOperationNameoptional*string#For example, you can assign the OperationName of ListPets for the GET /pets method.
requestModelsoptional{ [key: string]: IModel }request_modelsoptionaltyping.Mapping[str, IModel]requestModelsoptionalMap<String, IModel>RequestModelsoptionalIDictionary<string, IModel>RequestModelsoptional*map[string]IModel#notes · example
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.
declare const api: apigateway.RestApi;
declare const userLambda: lambda.Function;
const userModel: apigateway.Model = api.addModel('UserModel', {
schema: {
type: apigateway.JsonSchemaType.OBJECT,
properties: {
userId: {
type: apigateway.JsonSchemaType.STRING
},
name: {
type: apigateway.JsonSchemaType.STRING
}
},
required: ['userId']
}
});
api.root.addResource('user').addMethod('POST',
new apigateway.LambdaIntegration(userLambda), {
requestModels: {
'application/json': userModel
}
}
);
requestParametersoptional{ [key: string]: boolean }request_parametersoptionaltyping.Mapping[str, bool]requestParametersoptionalMap<String, Boolean>RequestParametersoptionalIDictionary<string, bool>RequestParametersoptional*map[string]*bool= None#notes
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.
requestValidatoroptionalIRequestValidatorrequest_validatoroptionalIRequestValidatorrequestValidatoroptionalIRequestValidatorRequestValidatoroptionalIRequestValidatorRequestValidatoroptionalIRequestValidator#Default: No default 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.
requestValidatorOptionsoptionalRequestValidatorOptionsrequest_validator_optionsoptionalRequestValidatorOptionsrequestValidatorOptionsoptionalRequestValidatorOptionsRequestValidatorOptionsoptionalRequestValidatorOptionsRequestValidatorOptionsoptionalRequestValidatorOptions#Default: No default validator
Works together with requestModels or requestParameters to validate the request before it reaches integration like Lambda Proxy Integration.