Can't set API Gateway stageVariables

Hi there,

First of all, a big thank you to the Serverless team that is doing a huge work!

My question is pretty simple. Why can’t I set API Gateway stage Variables. It actually acts as ENV variables and it would be more than helpful to be able to set them.

Actually, in the last documentation version ( link: https://goo.gl/aJe2gj ), it’s written:

Both templates give you access to the following properties you can access with the help of the event object:

  • […]
  • stageVariables

So I set my serverless.yml like this:

functions:
  eventsPost:
    handler: dist/eventsPost.index
    events:
      - http:
          method: post
          path: events
          stageVariables:
            myVar: helloWorld

But nothing is set on API Gateway… Am I doing something wrong ?

I also have an extra question. Why different stages are creating a whole new cloudFormation stack on AWS instead of simply create an API Gateway stage in the same stack?

Many thanks!
Emmanuel

Hi Emmanuel,

we’re currently working on better environment variable support for your functions. Will be released in the near future and is a very important feature for us. This should replace APIG stage variables completely.

I also have an extra question. Why different stages are creating a whole new cloudFront stack on AWS instead of simply create an API Gateway stage in the same stack?

We believe that every infrastructure should be completely separate from each other, so updating staging should not influence your production system (which it would if we would be setting up APIG with different stages). We simply disagree with AWS that this is a good way to build systems so we didn’t use this feature.

1 Like

Hi @flomotlik,

Thank you for your answer ! Is there any github issue related to this feature that I can follow to stay up to date?

Cheers

@flomotlik, I’d like to clarify the following statement:
We believe that every infrastructure should be completely separate from each other, so updating staging should not influence your production system (which it would if we would be setting up APIG with different stages). We simply disagree with AWS that this is a good way to build systems so we didn’t use this feature.

Does this actually mean that now new API will be created per environment (DEV/TEST/PROD) and every single API will contain only one stage?
I am asking to finalize migration from 0.5 to 1.0, so after initial deployment I identified that my dev resources were moved to completely new API instance and I this causes some problems for consumers which currently use the old URL…

Thank you!

Here is the Issue for Environment Variables: https://github.com/serverless/serverless/issues/1455

Does this actually mean that now new API will be created per environment (DEV/TEST/PROD) and every single API will contain only one stage?

Yup exactly. We also want to add an easier way for you to set up DNS for your API Gateway, so you don’t have to send out your actual API Gateway URL and can use a custom name in the future.

1 Like

Thanks, @flomotlik! That’s useful information and now I am good to go.