Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I reference a function that is not in the root folder using the Serverless Framework?

I'm using the Serverless Framework 1.x and I want to define my serverless.yml to reference a function that is located in another folder (not in the root level).

For example, in the following folder structure, I want to reference a handler() function that is defined in a function1.js file inside the folder functions.

serverless.yml
functions/
  function1.js
  function2.js
  function3.js
package.json
node_modules/
  ..

All examples that I see consider the following basic scenario where the file is in the root:

serverless.yml
handler.js

Where the serverless.yml file is defined by:

functions:
  hello:
    handler: handler.hello
like image 872
Zanon Avatar asked Feb 24 '17 01:02

Zanon


People also ask

Which command is used to call the functions in Serverless Framework?

Invokes a deployed function. You can send event data, read logs and display other important information of the function invocation.

How do I refer to a property in serverless Yaml file?

To reference properties in other YAML files use the ${file(./myFile. yml):someProperty} syntax in your serverless. yml configuration file. To reference properties in other JSON files use the ${file(./myFile.

How do you trigger http events in serverless?

HTTP Trigger Azure Functions has an API endpoint created for each Function App. This service allows you to define public HTTP endpoints for your serverless functions. To create HTTP endpoints as Event sources for your Azure Functions, use the Serverless Framework's easy HTTP Events syntax.


1 Answers

The Serverless Framework access functions inside other folders using the following syntax:

folder/filename.function

So, if we have a file named function1.js with a function handler() that we want to execute when our Lambda function is invoked, we use the following definition inside the serverless.yml file:

service: example

functions:
  func1:
    handler: functions/function1.handler
  func2:
    handler: functions/function2.handler

The same would apply for multiple levels of folders:

folder/folder/folder/filename.function
like image 189
Zanon Avatar answered Sep 24 '22 15:09

Zanon