> For the complete documentation index, see [llms.txt](https://docs-beta.flex83.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs-beta.flex83.com/table-of-contents/code/faas.md).

# Lambda

**Lambda** provides you a capability to write your business logic code in form of lambda functions that can be used/executed via API Gateway or Schedules. Think of it like the functions/methods that are written in service layer of a backend application to interact with databases and executing business logic.

To create a Lambda Function just go to **Code > Lambda** and click on **Add New**. Enter the basic details - Name, Description, Interpreter & Docker Image - pymongo (Refer Lambda Runtime Section for creating docker runtime images) & select runtime memory accordingly.

![Code > Lambda > Add New](https://1057759320-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MYj_V9XBSMgIZWFxZiX%2Fsync%2Fc8034e748414654c5f7d3eaeec6ce220ec41947a.png?generation=1631955231804052\&alt=media)

In this example we will fetch data from MongoDB that is being created by **Bidata Pipeline**. Get the MongoDB connection details from **Market Place > MongoDB** and use the same in Lambda code to connect to MongoDB.

Add a new **parameter** in upper right corner of the screen to pass it into lambda function when it will be called.

![Code > Lambda > Parameters](https://1057759320-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MYj_V9XBSMgIZWFxZiX%2Fsync%2F3ad482ff379d741aa2238a7b41cc173cd48c4da6.png?generation=1631955233772557\&alt=media)

Write your MongoDB code in the available main function to get data for a specific device id which can be passed into function using parameters, all the parameters will be available in **args** variable of main function.

![Code > Lambda > Create](https://1057759320-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MYj_V9XBSMgIZWFxZiX%2Fsync%2F3083ca589c95d0067fd50347c72a3b074fd4095b.png?generation=1631955232768412\&alt=media)

Once you are done with the code then save the details, and navigate to Lambda List page.

![Code > Lambda](https://1057759320-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MYj_V9XBSMgIZWFxZiX%2Fsync%2Fa953685cf65d84668914669367bcb9a7b032828f.png?generation=1631955234893929\&alt=media)

To test the functionality of this lambda function click on **{} Invoke** button available in actions of Lambda. Then click on **Try It Out** and click on **Execute** button, wait for a few seconds to see the output in the **Result** tab.

![Code > Lambda > Invoke](https://1057759320-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MYj_V9XBSMgIZWFxZiX%2Fsync%2F5bd481621ff61dd4c816e4dcb14bcefd627bf3fc.png?generation=1631955234702310\&alt=media)
