rraj gautam
rraj gautam

Reputation: 395

How do I get resource path for Root Resource in ApiGateway?

I am trying to change cache settings in api gateway for GET/OPTIONS methods of root resource using terraform.

resource "aws_api_gateway_method_settings" "root_get_method_settings" {
  rest_api_id = aws_api_gateway_rest_api.default.id
  stage_name  = terraform.workspace
  method_path = "<root resource path>/GET"

  settings {
    metrics_enabled = true
    logging_level   = "INFO"
    caching_enabled = true
  }
}

I am getting issue on method_path argument since I couldn't figure out correct value for <root resource path>.

method_path for any other resources like {proxy+} resource looks like below:

resource "aws_api_gateway_method_settings" "proxy_get_method_settings" {
  rest_api_id = aws_api_gateway_rest_api.default.id
  stage_name  = terraform.workspace
  method_path = "{proxy+}/GET"
 }

Upvotes: 2

Views: 1151

Answers (1)

Marcin
Marcin

Reputation: 238169

The path is "~1/GET". Below is full working example:


resource "aws_api_gateway_rest_api" "MyDemoAPI" {
  name        = "MyDemoAPI"
  description = "This is my API for demonstration purposes"
}

resource "aws_api_gateway_method" "MyDemoMethod" {
  rest_api_id   = aws_api_gateway_rest_api.MyDemoAPI.id
  resource_id   = aws_api_gateway_rest_api.MyDemoAPI.root_resource_id
  http_method   = "GET"
  authorization = "NONE"
}


resource "aws_api_gateway_deployment" "test" {
  depends_on  = [aws_api_gateway_integration.test]
  rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
  stage_name  = "prod"
}

resource "aws_api_gateway_integration" "test" {
  rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
  resource_id = aws_api_gateway_rest_api.MyDemoAPI.root_resource_id
  http_method = aws_api_gateway_method.MyDemoMethod.http_method
  type        = "MOCK"
}

resource "aws_api_gateway_method_settings" "root_get_method_settings" {
  rest_api_id = aws_api_gateway_rest_api.MyDemoAPI.id
  stage_name  = "prod"
  method_path = "~1/GET"

  settings {
    metrics_enabled = true
    logging_level   = "INFO"
    caching_enabled = true
  }
  
  depends_on  = [aws_api_gateway_deployment.test]
}

Upvotes: 0

Related Questions