Removing the stage name from the API Gateway path

I am deploying code to AWS Lambda / API Gateway.

At the moment, the generated API gateway endpoint contains the stage name in the path. However each stage also has its own API endpoint anyway: e.g. if I deploy the same project to both “dev” and “prod” stages I get e.g.

https://asdfasdfasdf.execute-api.eu-west-1.amazonaws.com/dev
https://wxyzwxyzwxyz.execute-api.eu-west-1.amazonaws.com/prod

I therefore don’t see what benefit having the stage in the path is doing, and indeed it’s making life really difficult for me with generating URLs within my app.

Is there any way to keep the stage name out of the API gateway path, and expose the application at ‘/’ instead? Or is this a fundamental limitation of API Gateway?

Aside: I found https://github.com/serverless/serverless/issues/2067 but this is making the opposite request: to use a single shared API gateway instance with /dev, /prod etc mounted on it. I am quite happy to have separate API gateway instances with their own URLs for each stage, I just don’t want the stage name to be inserted into the path.

Any clues gratefully received.

Cheers… Brian.

1 Like

Hmm… I think I can answer this myself. It looks like API gateway has its own concept of “stage” and this is hard-coded into the URLs it generates:

https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-call-api.html

If so, the only way to get rid of them would be to attach a custom domain:

https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-custom-domains.html

I guess it might be workable to get a cert for *.app.mydomain.com, and then publish each app under foo-dev.app.mydomain.com, foo-prod.app.mydomain.com etc - that would avoid the 40 minute delay each time I have a new app or stage to deploy.

This would be especially fine if API Gateway can get its own certs from Amazon Certificate Manager, which apparently it can now. Previously people were manually deploying letsencrypt certs.

1 Like