# Serverless Plugin: resolving variable references

**URL:** <https://forum.serverless.com/t/serverless-plugin-resolving-variable-references/2233>\
**Category:** Serverless Framework\
**Tags:** aws\
**Created:** [July 6, 2017, 7:21pm UTC](https://forum.serverless.com/t/serverless-plugin-resolving-variable-references/2233 "2017-07-06T19:21:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![breathe](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/breathe/32/859_2.png) [@breathe](https://forum.serverless.com/u/breathe)\
**Post date:** [July 6, 2017, 7:21pm UTC](https://forum.serverless.com/t/serverless-plugin-resolving-variable-references/2233/1 "2017-07-06T19:21:57Z")

</div>

I’m trying to write a simple serverless plugin. The main reason for this tool to exist as a plugin is so that I can make the serverless.yml serve as source of truth for some configuration data that needs to exist in some lambda’s as well as some other automation invoked by plugin.  
How do I resolve the variable references in the serverless.yml from my plugin?  
For example – i have a key in serverless.yml:

```
custom:
  defaultStage: stage
  stage: ${opt:stage, self:custom.defaultStage}
  config: ${file(env-vars/${self:custom.stage}.yml)}

```

within my plugin constructor:

```
  constructor(serverless: any) {
    console.log(serverless.service.custom.config);
  }

```

above prints:

`${file(env-vars/${self:custom.stage}.yml)}`

…

Thanks!

---

<div class="post-metadata">

**Author:** ![dschep](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/dschep/32/783_2.png) [@dschep](https://forum.serverless.com/u/dschep)\
**Post date:** [July 6, 2017, 9:15pm UTC](https://forum.serverless.com/t/serverless-plugin-resolving-variable-references/2233/2 "2017-07-06T21:15:31Z")

</div>

I also ran into this in [serverless-python-requirements](https://github.com/UnitedIncome/serverless-python-requirements). Serverless changed it’s behavior a few releases ago. That variable substitution is not called by the time plugin constructors get called. Unless you actually _need_ it then, just access it in your lifecycle hooks, it’ should be resolved by then.

here was my fix: [https://github.com/UnitedIncome/serverless-python-requirements/commit/2d1e218c383070d8f8244caa585c12843812f3d4](https://github.com/UnitedIncome/serverless-python-requirements/commit/2d1e218c383070d8f8244caa585c12843812f3d4)

---

<div class="post-metadata">

**Author:** ![breathe](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/breathe/32/859_2.png) [@breathe](https://forum.serverless.com/u/breathe)\
**Post date:** [July 6, 2017, 9:44pm UTC](https://forum.serverless.com/t/serverless-plugin-resolving-variable-references/2233/3 "2017-07-06T21:44:52Z")

</div>

This is the issue – and the fix!! Many thanks! It might be nice to explicitly call out in the documentation that variables aren’t resolved until after plugin creation has completed.

Thanks again!

---

<div class="post-metadata">

**Author:** ![dschep](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/dschep/32/783_2.png) [@dschep](https://forum.serverless.com/u/dschep)\
**Post date:** [July 7, 2017, 1:43am UTC](https://forum.serverless.com/t/serverless-plugin-resolving-variable-references/2233/4 "2017-07-07T01:43:25Z")

</div>

That’s a good idea. I’ve gone ahead and made a PR 😃 [https://github.com/serverless/serverless/pull/3911](https://github.com/serverless/serverless/pull/3911)
