aws-cdk-lib.aws_apigateway.MethodOptions

interface MethodOptions

LanguageType name
.NETAmazon.CDK.AWS.APIGateway.MethodOptions
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsapigateway#MethodOptions
Javasoftware.amazon.awscdk.services.apigateway.MethodOptions
Pythonaws_cdk.aws_apigateway.MethodOptions
TypeScript (source)aws-cdk-lib » aws_apigateway » MethodOptions

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
            }
        }
    );

Properties

NameTypeDescription
apiKeyRequired?booleanIndicates whether the method requires clients to submit a valid API key.
authorizationScopes?string[]A list of authorization scopes configured on the method.
authorizationType?AuthorizationTypeMethod authorization. If the value is set of Custom, an authorizer must also be specified.
authorizer?IAuthorizerIf authorizationType is Custom, this specifies the ID of the method authorizer resource.
methodResponses?MethodResponse[]The responses that can be sent to the client who calls the method.
operationName?stringA friendly operation name for the method.
requestModels?{ [string]: IModel }The models which describe data structure of request payload.
requestParameters?{ [string]: boolean }The request parameters that API Gateway accepts.
requestValidator?IRequestValidatorThe ID of the associated request validator.
requestValidatorOptions?RequestValidatorOptionsRequest validator options to create new validator Only one of requestValidator or requestValidatorOptions must be specified.

apiKeyRequired?

Type: boolean (optional, default: false)

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


authorizationScopes?

Type: string[] (optional, default: no 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.

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


authorizationType?

Type: AuthorizationType (optional, default: open access unless authorizer is specified)

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.


authorizer?

Type: IAuthorizer (optional)

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

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


methodResponses?

Type: MethodResponse[] *(optional, 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.)*

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

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


operationName?

Type: string (optional)

A friendly operation name for the method.

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


requestModels?

Type: { [string]: IModel } (optional)

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 also: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-method-settings-method-request.html#setup-method-request-model 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
            }
        }
    );

requestParameters?

Type: { [string]: boolean } (optional, default: None)

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.


requestValidator?

Type: IRequestValidator (optional, default: No default 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.


requestValidatorOptions?

Type: RequestValidatorOptions (optional, default: No default validator)

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.