Custom API Gateway Stage name not working?

I have API Gateway Resources that share a common API Gateway. I would like these resources to all fall under a single API Gateway Stage (regardless of the Serverless stage I’m deploying to).

I’ve tried configuring apiGateway.stage along with restApiId and restApiRootResourceId (per these docs) but no stage with the configured name is created. Below is an example of my configs.

provider:
  apiGateway:
    restApiId: 1111
    restApiRootResourceId: 2222
    stage: foobar
...

functions:
  func1:
    name: func1-${opt:stage, 'dev'}
    handler: bin/func1
    events:
      - http:
        path: /${opt:stage, 'dev'}/f1
        method: get
  func2:
    name: func2-${opt:stage, 'dev'}
    handler: bin/func2
    events:
      - http:
        path: /${opt:stage, 'dev'}/f2
        method: post

I want my URLs to look like this under my custom API Gateway Stage:

https://asdfjkl.execute-api.my-region.amazonaws.com/foobar/dev/f1
https://asdfjkl.execute-api.my-region.amazonaws.com/foobar/dev/f2
https://asdfjkl.execute-api.my-region.amazonaws.com/foobar/prod/f1
https://asdfjkl.execute-api.my-region.amazonaws.com/foobar/prod/f2

Instead I see:

https://asdfjkl.execute-api.my-region.amazonaws.com/dev/dev/f1
https://asdfjkl.execute-api.my-region.amazonaws.com/dev/dev/f2
https://asdfjkl.execute-api.my-region.amazonaws.com/prod/prod/f1
https://asdfjkl.execute-api.my-region.amazonaws.com/prod/prod/f2

Am I missing something here? Thanks!!

I’m having the exact same issue. I’ve tried using ‘serverless remove’ to redeploy the full stack, but the endpoint stage is still set to ‘dev’.

Provider:

provider:
    name: aws
    region: eu-west-2
    runtime: provided.al2
    apiGateway:
        stage: production
        restApiId: !Ref ApiGatewayRestApi
        restApiRootResourceId: !GetAtt ApiGatewayRestApi.RootResourceId

Lambda:

functions:
    sync:
        handler: SyncHandler.php
        layers:
            - ${bref:layer.php-81}
        events:
            - http:
                path: sync
                method: post

Endpoint output:

https://<gateway-id>.execute-api.<region>.amazonaws.com/dev/sync

@potatochips did you manage to figure out the issue?

Not yet. I’ve opened this issue:

AWS API Gateway provider.apiGateway.stage not working · Issue #11675 · serverless/serverless · GitHub.

1 Like