How to remove a scene from URLs for AWS Lambda + serverless features?

I use the Serverless Framework to deploy functions in AWS Lambda, but I cannot find where / how I can remove the stage qualifier from the generated URL endpoints. The documentation does not seem to cover this part.

For example, this is my serverless.yml (with inappropriate parts):

 service: cd-mock provider: name: aws runtime: python3.6 region: eu-west-1 package: include: - handler.py functions: index: handler: handler.index events: - http: path: / method: get 

After serverless deploy , the following overhead information is returned:

 service: cd-mock stage: dev region: eu-west-1 stack: cd-mock-dev api keys: None endpoints: GET - https://ab1cd2ef3g.execute-api.eu-west-1.amazonaws.com/dev/ functions: index: cd-mock-dev-index 

Note the /dev part of the endpoint of the URL, as well as the function. This dev value is the default value for the stage parameter in the configuration file.

The stage: something serverless.yml in serverless.yml will have /something as a suffix in the URL and as part of the function.

Question: how can I remove the stage specification from the generated URL endpoints or: how can I prevent this stage specification from becoming part of the generated URLs?

(The fact that this part is part of the function is fine. It will be easy to separate the staging and production functions on the AWS lambda control panel.)

+14
source share
3 answers

This is the Serverless Framework's NOT gateway NOT function / convention, so serverless can't do anything about it.

The Gateway API requires you with a scene and is added at the end of your endpoint.

Gateway API endpoints are intended for developers, although this does not mean that they are user-friendly.

If you want it to be user-friendly, you can add your own domain for it. There may be different user subdomains at different stages.

+15
source

One thing you can do is use your own domain that you use (e.g. mycompany.com ) and map it to your API gateway. Thus, instead of requesting https://ab1cd2ef3g.execute-api.eu-west-1.amazonaws.com/dev/ , you should make a request https://api.mycompany.com/ .

There's a plugin called serverless-domain-manager that makes it easy to set up these custom domains. Check out this blog post for a complete step-by-step guide on how to use it.

+22
source

Triggered by @dashnug's answer, "The Gateway API requires a stage, and it is added at the end of your endpoint," as well as another answer that I read elsewhere. I “solved” the problem by making the stage specification a little less expressive (which the environment stage was mentioned about) using v1 as the stage. This also assumes some version of the API, which is also acceptable in my case.

So, my serverless.yml section now contains:

 provider: name: aws runtime: python3.6 memorySize: 512 region: ${opt:region, 'eu-west-1'} profile: ${opt:profile, 'default'} stage: ${opt:stage, 'v1'} # A trick to don't end up with "production" or "staging" as stage. 
0
source

Source: https://habr.com/ru/post/1272787/


All Articles