Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test aws lambda functions locally

I have a mobile application backend developed with node.js express. I tried it to deploy it as lambda service. For that I created a Serverless Framework project (https://github.com/serverless). Previously I tested mobile app locally by starting express backend application. Now I can't find a method to test my mobile app locally without local backend. jaws run command only run once I called it.

Is there any method to start the lambda function as a web service? Or is there any alternative to Serverless Framework?

like image 399
Supun Induwara Avatar asked Nov 24 '15 03:11

Supun Induwara


People also ask

How do I run a Lambda function locally?

Step 1: Download SAM local Windows Install SAM CLI using an MSI in either the 64 bit or 32 bit versions. Step 2: Verify that the installation succeeded and version with the command below. Step 3: Write your lambda function or clone it from Github to run locally, making sure to add Template. yaml on the root level.

Can we run AWS Lambda locally?

You can invoke your AWS Lambda function locally by using the sam local invoke AWS SAM CLI command and providing the function's logical ID and an event file. Alternatively, sam local invoke also accepts stdin as an event. For more information about events, see Event in the AWS Lambda Developer Guide.


2 Answers

It doesn't look like there's way to do this right now, but version 1.4.0 is about to be released and, among other things, it should include a new command "jaws serve" which should address your problem.

Here's the PR: https://github.com/jaws-framework/JAWS/pull/269

UPDATE: you can now use the new serverless-serve plugin for this.

UPDATE 2: serverless-serve hasn't been updated in a while, it looks like serverless-offline is a much better option now to emulate Lambda functions.

like image 101
Santiag00 Avatar answered Sep 19 '22 19:09

Santiag00


You can now use lambda-local.

Install it like this:

sudo -H npm install -g lambda-local 

Add your parameters as a JSON object to a file, in this example event.json, and call the index.js file like this:

lambda-local -l index.js -h handler -e event.json 
like image 24
Nicolay77 Avatar answered Sep 23 '22 19:09

Nicolay77