# Can't set API Gateway stageVariables

**URL:** <https://forum.serverless.com/t/cant-set-api-gateway-stagevariables/314>\
**Category:** Serverless Framework\
**Tags:** aws\
**Created:** [September 16, 2016, 4:01pm UTC](https://forum.serverless.com/t/cant-set-api-gateway-stagevariables/314 "2016-09-16T16:01:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gozup](https://avatars.discourse-cdn.com/v4/letter/g/47e85d/32.png) [@gozup](https://forum.serverless.com/u/gozup)\
**Post date:** [September 16, 2016, 4:01pm UTC](https://forum.serverless.com/t/cant-set-api-gateway-stagevariables/314/1 "2016-09-16T16:01:41Z")

</div>

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: [Serverless Framework - AWS Lambda Events - REST API (API Gateway v1)](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

---

<div class="post-metadata">

**Author:** ![flomotlik](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/flomotlik/32/3_2.png) [@flomotlik](https://forum.serverless.com/u/flomotlik)\
**Post date:** [September 17, 2016, 1:43pm UTC](https://forum.serverless.com/t/cant-set-api-gateway-stagevariables/314/2 "2016-09-17T13:43:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gozup](https://avatars.discourse-cdn.com/v4/letter/g/47e85d/32.png) [@gozup](https://forum.serverless.com/u/gozup)\
**Post date:** [September 19, 2016, 8:00am UTC](https://forum.serverless.com/t/cant-set-api-gateway-stagevariables/314/3 "2016-09-19T08:00:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dtabolich](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/dtabolich/32/1171_2.png) [@dtabolich](https://forum.serverless.com/u/dtabolich)\
**Post date:** [September 20, 2016, 1:47pm UTC](https://forum.serverless.com/t/cant-set-api-gateway-stagevariables/314/4 "2016-09-20T13:47:02Z")

</div>

@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!

---

<div class="post-metadata">

**Author:** ![flomotlik](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/flomotlik/32/3_2.png) [@flomotlik](https://forum.serverless.com/u/flomotlik)\
**Post date:** [September 20, 2016, 2:03pm UTC](https://forum.serverless.com/t/cant-set-api-gateway-stagevariables/314/5 "2016-09-20T14:03:18Z")

</div>

Here is the Issue for Environment Variables: [Access environment variables in code · Issue #1455 · serverless/serverless · GitHub](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.

---

<div class="post-metadata">

**Author:** ![dtabolich](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/dtabolich/32/1171_2.png) [@dtabolich](https://forum.serverless.com/u/dtabolich)\
**Post date:** [September 20, 2016, 6:51pm UTC](https://forum.serverless.com/t/cant-set-api-gateway-stagevariables/314/7 "2016-09-20T18:51:27Z")

</div>

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