Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serverless Variables #1834

Merged
merged 26 commits into from Aug 31, 2016
Merged

Serverless Variables #1834

merged 26 commits into from Aug 31, 2016

Conversation

eahefnawy
Copy link
Member

@eahefnawy eahefnawy commented Aug 12, 2016

This PR implements the new Serverelss Variables system as described here and discussed in #1801.

  • populating from env vars: ${env:my_arn}
  • populating from cli options: ${opt:stage}
  • populating from the self serverless.yml file: ${self:service}
  • move defaults into provider with backward compatibility
  • indefinite recursive nesting: ${env:${opt:stage}_arn}
  • populating from another file: ${file(./config.yml):data.subProp}
  • unit tests
  • update docs

cc/ @serverless/vip

@eahefnawy eahefnawy added this to the v1.0.0-beta.2 milestone Aug 12, 2016
@eahefnawy eahefnawy self-assigned this Aug 12, 2016

```

In the previous example you're dynamically adding a prefix to the function names by referencing the `stage` option that you pass in the CLI. So when you deploy, the function name will always include the stage you're deploying to.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to add an actual example CLI command. For example: sls deploy --stage=dev

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing. Note though that the command hasn't changed. It's still sls deploy --stage dev as usual, but what's new is that you have access to this stage CLI option in the configuration file.

@pmuens
Copy link
Contributor

pmuens commented Aug 16, 2016

Just played around with it and it's really rock solid!
Great work 🎉

Here's just something I was wondering when using self. What about if we parse the file self references into JSON and use this JSON representation to find the correct value?

This way we can also e.g. access properties which are nested inside the events array like self.functions.hello.events[0].http.path. Not sure if it's necessary at all.

Another thing was that I still found several serverless.env.yml references (especially in the docs) while doing a global search (CMD + Shift + F in WebStorm). Those should be removed as well.

@eahefnawy
Copy link
Member Author

@pmuens not sure I understand what you mean about JSON. The self is already accessing the parsed serverless.yml file as a Javascript Object, and we can access any value type. But just like you mention, the limitation is parsing the referencing string itself. So yeah we can't really go deep into arrays because that syntax it's not supported (not really sure if there's a need for that though), but how would JSON help here?

@pmuens
Copy link
Contributor

pmuens commented Aug 16, 2016

Yes. Just something random I stumbled upon when I tried to access the path property of the http event in the serverless.yml file.

Maybe a wrong usage on my side but also not a high priority IMHO.

@pmuens
Copy link
Contributor

pmuens commented Aug 19, 2016

Awesome! Will test it ASAP. Just one note. Could you do another global search for serverless.env.yml and serverless.env.yaml? There are still some references (e.g. in the root README.md file) in other files which might be removed.

@eahefnawy
Copy link
Member Author

@pmuens Good catch! 👍 .... I was only searching in the docs folder

@flomotlik
Copy link
Contributor

@eahefnawy please resolve conflicts

@ac360
Copy link
Member

ac360 commented Aug 23, 2016

@eahefnawy You are so fantastic and talented, I bet you can still squeeze in support for var.myVar in populate(). Just imagine how simple and elegant var will look in serverless.yml, as an alternative to these other awesome variable sources you've implemented. It will be like art. Can you picture it?

Also, @maciej will give you a kiss.

@hellolijin
Copy link

serverless.yml
....
config: ${opt:target}
custom: ${file(./${self:config}.yml)}
...

when I run,
$ sls deploy --target dev

error happens.

Serverless Error ---------------------------------------

 Trying to populate non string value into a string for
 variable ${self:config}. Please make sure the value
 of the property is a string.

...

@hellolijin
Copy link

serverless.yml (the ./foo/function.yml is defined correctly)
...
functions:
foo: ${file(./foo/function.yml)}
...
When deploy, I got

Type Error ---------------------------------------------

 Cannot assign to read only property 'events' of ${file(./foo/function.yml)}

Could I know how to resolve it? I really want to define the functions in the sub folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet