Shared APIGateway to invoke lambda as proxy as multiple stage

Use case :

  • Need to have 1 API Gateway with multiple stages as dev, test and prod, so that i can invoke different lambdas corresponding to each environment as https://APIGW_ENDPOINT/dev/{proxy} or https://APIGW_ENDPOINT/test/{proxy} or https://APIGW_ENDPOINT/prod/${proxy}

serverless.yml file is as follows

service: whatsapp-k8-orchestration
plugins:
  - serverless-python-requirements
  - serverless-wsgi

custom:
  wsgi:
    app: app.app
    packRequirements: false
  pythonRequirements:
    dockerizePip: true
  currentStage: ${opt:stage, self:custom.defaultStage}
  configs: ${file(sls_config.yml):${self:custom.currentStage}}

provider:
  name: aws
  runtime: python3.6
  stage: ${self:custom.currentStage}
  region: ${self:custom.configs.REGION}
  endpointType: PRIVATE
  timeout: 300
  vpc:
    securityGroupIds: ${self:custom.configs.LAMBDA_SECURITYGROUPS}
    subnetIds: ${self:custom.configs.SUBNETS}

functions:
  app:
    handler: wsgi.handler
    events:
      - http: ANY /
      - http: 'ANY {proxy+}'

However, when i run sls deploy --stage dev and sls deploy --stage test , two separate APIGateways are created.

What changes i should do, so that there is only 1 APIGateway created, but with different stages for each environment lambda ???

Currently serverless does not support AWS ‘stages’ for the API Gateway but you can use the alias plugin for this:

A year later (Nov. 2019), it looks like it possible to avoid this hurdle by deploying a single API gateway with the framework and then create a new stage from another template.
The single API still needs a stage name (I use ‘common’) so I end up with MyApi-common, with another project (i.e MyApp) deploying stages with ‘# serverless deploy --stage dev/prod/[…]’.

You have to use stage variables in the API, as a single template there has to be used by every stage.
We end up with things like ‘TableName: MyApp-${stageVariables.Stage}-table1’ in the templates.