2

I'm using AWS SAM.

From the docs, I see "Stage names can contain only alphanumeric characters, hyphens, and underscores, or be $default."

But when I try:

Resources:
  ExpressApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: '$default'

The stack create fails with message:

Stage name only allows a-zA-Z0-9_

I just want to be able to use the API base URL without the StageName in the path. My API has only one stage.

Is there a way to do that without hooking up a custom domain to the API?

Wintermute
  • 2,973
  • 4
  • 32
  • 52
  • Are you creating a Rest Api or Http Api ? if its Rest api, stage name is just `default` , if its Http Api , it need not be given, by default it creates `$default` – Balu Vyamajala Feb 16 '21 at 16:44

1 Answers1

1

For HTTP API:

StageName is optional as HTTP API creates $default stage by default which can be accessed without any prefix and auto deployes.

If no name is specified, AWS SAM uses the $default stage from API Gateway

For REST API

StageName is required. There is no auto deploy for Rest APIs. SAM Template behind the scenes it creates that stage and deploy code to that stage and it allows only a-zA-Z0-9_

Balu Vyamajala
  • 9,287
  • 1
  • 20
  • 42
  • Hi. This is `AWS::Serverless::Api` which is REST API. Can you eliminate stage name from URL of the rest api? I think this is the OPs question? – Marcin Feb 16 '21 at 23:21