serverless / serverless/serverless

Support function arguments in variables referencing javascript ( ${file(./file.js):functionName(argument1, argument2)} )

Open
#5,617 1 comment 9 reactions 1 assignee View on GitHub

@zoellner is already working on this.

Since Apr 12, 2021.

cat/variable enhancement needs feedback
Dominant language
JavaScript
Stars
46.9k
Forks
5.7k
Avg merge
10h 7m
Merged PRs (30d)
57

Description

This is a Feature Proposal

Description

This is a follow up to #3073 and more specifically to one comment therein https://github.com/serverless/serverless/issues/3073#issuecomment-294636809

Quoting from that comment:

What I think would be a natural and very necessary extension of this work would be to allow you to call a JS file and pass a function arguments to resolve variables. Consider a case where you have a piece of config in a configuration database table (or any other external system), and you want your serverless template to be able to pull a value from the config DB and use it. If you could pass arguments to the JS function, you could make it extensible. For example, the usecase that @tgjorgoski first posted could be more extensible by allowing for this:

custom:
  someValue: ${file(./variables-helpers.js):getFromS3(secret-data-bucket, secret-data.json)}

In that case your JS file would be something like:

module.exports = {
   getFromS3: function(bucketName, key) {
      return somePromiseThatLoadsJSONFrom(bucketName, key);
   }
};

Similar or dependent issues:

  • #3073

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.