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
Invokes a deployed function. You can send event data, read logs and display other important information of the function invocation.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With