Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

477
Views
Terraform: How to create a api gateway POST method at root?

I am trying to create POST method using terraform at the root api gateway URL such as https://somehash.execute-api.us-east-1.amazonaws.com/dev which would include the stage. Here is part of the terraform plan of concern:

resource "aws_api_gateway_rest_api" "api" {
  name = "submit-dev-gateway-api"
}

resource "aws_api_gateway_resource" "resource" {
  rest_api_id = "${aws_api_gateway_rest_api.api.id}"
  parent_id = "${aws_api_gateway_rest_api.api.root_resource_id}"
  path_part = "submit"
}

resource "aws_api_gateway_method" "post_form" {
  rest_api_id   = "${aws_api_gateway_rest_api.api.id}"
  resource_id   = "${aws_api_gateway_resource.resource.id}"
  http_method   = "POST"
  authorization = "NONE"
}
...

I tried changing the path_part to "/" but it did not work. I could not create a aws_api_gateway_method resource without aws_api_gateway_resource. I can create a POST at root manually without terraform which looks like this: manual

When I use the above terraform plan I get this: terraform

How do I create POST at root with terraform?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

The "root resource" is created automatically as part of creating an API Gateway REST API. In Terraform, the id of that root resource is exposed as the root_resource_id attribute of the REST API resource instance.

Because that resource is implicitly created as part of the API, we don't need a separate resource for it. Instead, we can just attach methods (and the other necessary downstream objects) directly to that existing root resource:

resource "aws_api_gateway_rest_api" "api" {
  name = "submit-dev-gateway-api"
}

resource "aws_api_gateway_method" "post_form" {
  rest_api_id   = aws_api_gateway_rest_api.api.id
  resource_id   = aws_api_gateway_rest_api.api.root_resource_id
  http_method   = "POST"
  authorization = "NONE"
}
over 4 years ago · Santiago Trujillo Report

0

You must check path_part. Try

path_part   = "{submit}"

The path_part argument will contain a string that represents the endpoint path. Read more path_part

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!