Menu
AWS CloudFormation
User Guide (API Version 2010-05-15)

AWS::ApiGateway::Method

The AWS::ApiGateway::Method resource creates Amazon API Gateway (API Gateway) methods that define the parameters and body that clients must send in their requests.

Syntax

To declare this entity in your AWS CloudFormation template, use the following syntax:

JSON

Copy
{ "Type" : "AWS::ApiGateway::Method", "Properties" : { "ApiKeyRequired" : Boolean, "AuthorizationType" : String, "AuthorizerId" : String, "HttpMethod" : String, "Integration" : Integration, "MethodResponses" : [ MethodResponse, ... ], "OperationName" : String, "RequestModels" : { String:String, ... }, "RequestParameters" : { String:Boolean, ... }, "RequestValidatorId" : String, "ResourceId" : String, "RestApiId" : String } }

YAML

Copy
Type: "AWS::ApiGateway::Method" Properties: ApiKeyRequired: Boolean AuthorizationType: String AuthorizerId: String HttpMethod: String Integration: Integration MethodResponses: - MethodResponse OperationName: String RequestModels: String: String RequestParameters: String: Boolean RequestValidatorId: String ResourceId: String RestApiId: String

Properties

ApiKeyRequired

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

Required: No

Type: Boolean

Update requires: No interruption

AuthorizationType

The method's authorization type.

Required: Yes. If you specify the AuthorizerId property, specify CUSTOM for this property.

Type: String

Update requires: No interruption

AuthorizerId

The identifier of the authorizer to use on this method. If you specify this property, specify CUSTOM for the AuthorizationType property.

Required: No

Type: String

Update requires: No interruption

HttpMethod

The HTTP method that clients use to call this method.

Required: Yes

Type: String

Update requires: No interruption

Integration

The backend system that the method calls when it receives a request.

Required: No

Type: Amazon API Gateway Method Integration

Update requires: No interruption

MethodResponses

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

Required: No

Type: List of Amazon API Gateway Method MethodResponse property types.

Update requires: No interruption

OperationName

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

Required: No

Type: String

Update requires: No interruption

RequestModels

The resources that are used for the response's content type. Specify response models as key-value pairs (string-to-string mapping), with a content type as the key and a Model resource name as the value.

Required: No

Type: Mapping of key-value pairs

Update requires: No interruption

RequestParameters

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.

Required: No

Type: Mapping of key-value pairs

Update requires: No interruption

RequestValidatorId

The ID of the associated request validator.

Required: No

Type: String

Update requires: No interruption

ResourceId

The ID of an API Gateway resource. For root resource methods, specify the RestApi root resource ID, such as { "Fn::GetAtt": ["MyRestApi", "RootResourceId"] }.

Required: Yes

Type: String

Update requires: No interruption

RestApiId

The ID of the RestApi resource in which API Gateway creates the method.

Required: Yes

Type: String

Update requires: No interruption

Return Value

Ref

When the logical ID of this resource is provided to the Ref intrinsic function, Ref returns the method ID, such as mysta-metho-01234b567890example.

For more information about using the Ref function, see Ref.

Examples

Mock Method

The following example creates a mock GET method for the MyApi API.

JSON

Copy
"MockMethod": { "Type": "AWS::ApiGateway::Method", "Properties": { "RestApiId": { "Ref": "MyApi" }, "ResourceId": { "Fn::GetAtt": ["RestApi", "RootResourceId"] }, "HttpMethod": "GET", "AuthorizationType": "NONE", "Integration": { "Type": "MOCK" } } }

YAML

Copy
MockMethod: Type: "AWS::ApiGateway::Method" Properties: RestApiId: Ref: "MyApi" ResourceId: Fn::GetAtt: - "RestApi" - "RootResourceId" HttpMethod: "GET" AuthorizationType: "NONE" Integration: Type: "MOCK"

Lambda Proxy

The following example creates a proxy resource to enable clients to call a Lambda function with a single integration setup on a catch-all ANY method. The Uri property specifies the Lambda function. For more information about Lambda proxy integration and a sample Lambda function, see Create an API with Lambda Proxy Integration through a Proxy Resource in the API Gateway Developer Guide.

Note

Use the AWS::Lambda::Permission resource to grant API Gateway permission to invoke your Lambda function.

JSON

Copy
"ProxyResource": { "Type": "AWS::ApiGateway::Resource", "Properties": { "RestApiId": { "Ref":"LambdaSimpleProxy"}, "ParentId": { "Fn::GetAtt" : [ "LambdaSimpleProxy", "RootResourceId" ]}, "PathPart": "{proxy+}" } }, "ProxyResourceANY": { "Type": "AWS::ApiGateway::Method", "Properties": { "RestApiId": {"Ref":"LambdaSimpleProxy"}, "ResourceId": {"Ref":"ProxyResource"}, "HttpMethod": "ANY", "AuthorizationType": "NONE", "Integration": { "Type": "AWS_PROXY", "IntegrationHttpMethod": "POST", "Uri": { "Fn::Sub":"arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${LambdaForSimpleProxy.Arn}/invocations"} } } }

YAML

Copy
ProxyResource: Type: AWS::ApiGateway::Resource Properties: RestApiId: !Ref LambdaSimpleProxy ParentId: !GetAtt [LambdaSimpleProxy, RootResourceId] PathPart: '{proxy+}' ProxyResourceANY: Type: AWS::ApiGateway::Method Properties: RestApiId: !Ref LambdaSimpleProxy ResourceId: !Ref ProxyResource HttpMethod: ANY AuthorizationType: NONE Integration: Type: AWS_PROXY IntegrationHttpMethod: POST Uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${LambdaForSimpleProxy.Arn}/invocations

Associated Request Validator

The following example creates a REST API, method, and request validator, and associates the request validator with the method. It also lets you specify how to convert the request payload.

JSON

Copy
{ "Parameters": { "contentHandling": { "Type": "String" }, "operationName": { "Type": "String", "Default": "testoperationName" }, "restApiName": { "Type": "String", "Default": "testrestApiName" }, "validatorName": { "Type": "String", "Default": "testvalidatorName" }, "validateRequestBody": { "Type": "String", "Default": "testvalidateRequestBody" }, "validateRequestParameters": { "Type": "String", "Default": true } }, "Resources": { "RestApi": { "Type": "AWS::ApiGateway::RestApi", "Properties": { "Name": { "Ref": "restApiName" } } }, "Method": { "Type": "AWS::ApiGateway::Method", "Properties": { "HttpMethod": "POST", "ResourceId": { "Fn::GetAtt": [ "RestApi", "RootResourceId" ] }, "RestApiId": { "Ref": "RestApi" }, "AuthorizationType": "NONE", "Integration": { "Type": "MOCK", "ContentHandling": { "Ref": "contentHandling" }, "IntegrationResponses": [ { "ContentHandling": { "Ref": "contentHandling" }, "StatusCode": 400 } ] }, "RequestValidatorId": { "Ref": "RequestValidator" }, "OperationName": { "Ref": "operationName" } } }, "RequestValidator": { "Type": "AWS::ApiGateway::RequestValidator", "Properties": { "Name": { "Ref": "validatorName" }, "RestApiId": { "Ref": "RestApi" }, "ValidateRequestBody": { "Ref": "validateRequestBody" }, "ValidateRequestParameters": { "Ref": "validateRequestParameters" } } } }, "Outputs": { "RootResourceId": { "Value": { "Fn::GetAtt": [ "RestApi", "RootResourceId" ] } } } }

YAML

Copy
Parameters: contentHandling: Type: String operationName: Type: String Default: testoperationName restApiName: Type: String Default: testrestApiName validatorName: Type: String Default: testvalidatorName validateRequestBody: Type: String Default: testvalidateRequestBody validateRequestParameters: Type: String Default: true Resources: RestApi: Type: 'AWS::ApiGateway::RestApi' Properties: Name: !Ref restApiName Method: Type: 'AWS::ApiGateway::Method' Properties: HttpMethod: POST ResourceId: !GetAtt RestApi.RootResourceId RestApiId: !Ref RestApi AuthorizationType: NONE Integration: Type: MOCK ContentHandling: !Ref contentHandling IntegrationResponses: - ContentHandling: !Ref contentHandling StatusCode: 400 RequestValidatorId: !Ref RequestValidator OperationName: !Ref operationName RequestValidator: Type: 'AWS::ApiGateway::RequestValidator' Properties: Name: !Ref validatorName RestApiId: !Ref RestApi ValidateRequestBody: !Ref validateRequestBody ValidateRequestParameters: !Ref validateRequestParameters Outputs: RootResourceId: Value: !GetAtt RestApi.RootResourceId

See Also

  • Method in the Amazon API Gateway REST API Reference