Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

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

1 Answer

0 votes
by (44.4k points)

Use the following syntax because the Serverless Framework considers functions inside other folders:

folder/filename.function

If a file function1.js exists with a function handler() which has to be executed when our Lambda function is invoked, use this following serverless.yml file:

service: example

functions:

  func1:

    handler: functions/function1.handler

  func2:

    handler: functions/function2.handler

Same for a multiple of storage hierarchy:

folder/folder/folder/filename.function

Browse Categories

...