Serverless Functions


The serverless/functions directory contains the code for Lambda functions. The developer first creates the lambda resource in template.yaml, then adds a typescript file containing code under the functions directory. The lambda resource in template.yaml must have a reference to the filename of the corresponding function.

Every SOMOD function must have a lambda handler as the default export. The SOMOD prepare command will generate a javascript bundle capable of running inside nodeJs runtime at the .somod/serverless/functions/{moduleName}/{functionName} directory.

The SOMOD excludes the npm packages in the attached layers from the function bundle.

Layers

The developer can add common libraries used across multiple functions in a custom layer. Refer SOMOD::Function and SOMOD::FunctionLayer keywords in template.yaml for syntax.

Invoking the functions

AWS SAM documentation describes the event sources to configure the invocation of the function.

The lambda function can handle any of the event described in the event sources. SOMOD recommends that each function must handle only one type of event.

For HttpApi and Api event sources SOMOD automatically tries to resolve the conflicting API Routes. For conflict resolution strategy refer Namespaces.

Does this page need improvements?
Edit This Page in GitHub
Did this page help you?
Provide feedback in the GitHub Discussion Page
Need More help?

Write an email to somod@sodaru.com

This documentation is built using
Developed and Maintained By
Sodaru Technologies
https://sodaru.com
© 2022