awscc_apigateway_method (Resource)

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

Example Usage

Mock Method

Creates a mock method GET

resource "awscc_apigateway_rest_api" "example" {
  name = "ExampleAPI"
}

resource "awscc_apigateway_resource" "example" {
  rest_api_id = awscc_apigateway_rest_api.example.id
  parent_id   = awscc_apigateway_rest_api.example.root_resource_id
  path_part   = "path"
}

resource "awscc_apigateway_method" "example" {
  rest_api_id = awscc_apigateway_rest_api.example.id
  resource_id = awscc_apigateway_resource.example.resource_id
  http_method = "GET"

  authorization_type = "NONE"

  integration = {
    type = "MOCK"

    request_templates = {
      "application/json" = jsonencode({
        "statusCode" : 200
      })
    }

    integration_responses = [{
      status_code = "200"
      response_templates = {
        "application/json" = jsonencode({
          "ip" : "$context.identity.sourceIp",
          "userAgent" : "$context.identity.userAgent",
          "time" : "$context.requestTime",
          "epochTime" : "$context.requestTimeEpoch"
        })
      }
    }]
  }

  method_responses = [{
    status_code = "200"
  }]
}

Basic use of API method response

Basic use of API method response with only status code

resource "awscc_apigateway_rest_api" "terraform_apigateway_rest_api" {
  name = "TestRestApi"
  endpoint_configuration = {
    types = [
      "REGIONAL"
    ]
  }
}

resource "awscc_apigateway_method" "terraform_apigateway_method" {
  http_method        = "GET"
  authorization_type = "NONE"
  integration = {
    type = "MOCK"
  }
  rest_api_id = awscc_apigateway_rest_api.terraform_apigateway_rest_api.id
  resource_id = awscc_apigateway_rest_api.terraform_apigateway_rest_api.root_resource_id

  method_responses = [{ status_code = "200" }]

  depends_on = [awscc_apigateway_rest_api.terraform_apigateway_rest_api]
}

Use of API method response with response parameters and response models

API method response using response models and response parameters

resource "awscc_apigateway_rest_api" "terraform_apigateway_rest_api" {
  name = "TestRestApi"
  endpoint_configuration = {
    types = [
      "REGIONAL"
    ]
  }
}

resource "awscc_apigateway_method" "terraform_apigateway_method" {
  http_method        = "GET"
  authorization_type = "NONE"
  integration = {
    type = "MOCK"
  }
  rest_api_id = awscc_apigateway_rest_api.terraform_apigateway_rest_api.id
  resource_id = awscc_apigateway_rest_api.terraform_apigateway_rest_api.root_resource_id

  method_responses = [{ status_code = "200", response_models = { "application/json": "Empty"} , response_parameters = {"method.response.header.Content-Type" = false}}]

  depends_on = [awscc_apigateway_rest_api.terraform_apigateway_rest_api]
}

Schema

Required

Optional

Read-Only

Nested Schema for integration

Required:

Optional:

Nested Schema for integration.integration_responses

Required:

Optional:

Nested Schema for method_responses

Required:

Optional:

Import

Import is supported using the following syntax:

$ terraform import awscc_apigateway_method.example <resource ID>