12

I have an API Gateway setup using Terraform. I need to be able to visit the API Gateway on the base path, i.e, without the stage name appended to the base URL.

https://{api_id}.execute-api.{region}.amazonaws.com/ <- acceptable

https://{api_id}.execute-api.{region}.amazonaws.com/{StageName} <- not acceptable

I would do this from the console by creating a default deployment stage like here.

I looked but could not find anything in the terraform documentation here for stages

I want to be able to do this by creating the default stage, not using a aws_api_gateway_domain_name resource

2 Answers 2

16

From the AWS documentation:

You can create a $default stage that is served from the base of your API's URL—for example, https://{api_id}.execute-api.{region}.amazonaws.com/. You use this URL to invoke an API stage.

The Terraform documentation doesn't mention this, but you can create a stage with $default as the stage name. Calling the base path should then use that stage.

resource "aws_apigatewayv2_stage" "example" {
  api_id = aws_apigatewayv2_api.example.id
  name   = "$default"
}
Sign up to request clarification or add additional context in comments.

1 Comment

Note that this is only available for the HTTP version of the API Gateway. It's not supported by the REST version.
7

aws_api_gateway_domain_name is for REST API which does not have a default stage. To create such a stage you have to use HTTP API which in terraform is provided by the family of apigatewayv2 methods.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.