How to use lambda-local - 9 common examples

To help you get started, we’ve selected a few lambda-local examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rmtuckerphx / alexa-skill-serverless-starter-template / test / debugger / main.js View on Github external
var lambdalocal = require("lambda-local");
var winston = require("winston");
var lambda = require('../../src/main.js');

var functionName = "handler";
var timeoutMs = 3000;
var region = config.region;
var profileName = config.awsProfile;

winston.level = "error";
lambdalocal.setLogger(winston);



lambdalocal.execute({
    event: event,
    lambdaFunc: lambda,
    lambdaHandler: functionName,
    region: region,
    profileName : profileName,
    callbackWaitsForEmptyEventLoop: false,
    timeoutMs: timeoutMs,
    callback: function (_err, _done) {
        done = _done;
        err = _err;

        if (done) {
            console.log('context.done');
            console.log(done);
        }
github alan-turing-institute / alexa-room-finder / test / test-lambda-local-example.js View on Github external
},
  "request": {
    "type": "IntentRequest", //Change this to change type of request. Options: "IntentRequest" or "LaunchRequest"
    "requestId": "",
    "locale": "en-GB", //Change this to change language. Options: "en-US" or "en-GB"
    "timestamp": "",
    "intent": {
      "name": "BookIntent", //Change this to change the intent sent with the request. Options: "AMAZON.NoIntent", "AMAZON.YesIntent", "AMAZON.CancelIntent", "AMAZON.StopIntent", "AMAZON.RepeatIntent", "AMAZON.HelpIntent", "BookIntent", "Unhandled"
      "slots": {} //Change this to put something in slots
    }
  },
  "version": "1.0"
}

//Main
lambdaLocal.execute({
    event: jsonPayload,
    lambdaPath: '../lambda/index.js',
    profileName: 'default',
    timeoutMs: 3000,
    callback: function(err, data) {
        if (err) {
            console.log(err);
        } else {
            console.log(data);
        }
    }
});
github rmtuckerphx / alexa-skill-serverless-starter-template / test / e2e / handlerTests.js View on Github external
before(function (cb) {
            const lambdalocal = require("lambda-local");
            lambdalocal.setLogger(winston);
            const lambda = require('../../src/main.js');
            let event = getEvent('SessionEndedRequest.json');

            lambdalocal.execute({
                event: event,
                lambdaFunc: lambda,
                lambdaHandler: functionName,
                region: region,
                profileName : profileName,
                callbackWaitsForEmptyEventLoop: false,
                timeoutMs: timeoutMs,
                callback: function (_err, _done) {
                    done = _done;
                    err = _err;

                    if (done) {
                        console.log('context.done');
                        console.log(done);
                    }
github tlovett1 / alexa-skill-test / server.js View on Github external
app.post('/lambda', function(req, res) {
  res.setHeader('Content-Type', 'application/json');

  debug('Lambda event:');
  debug(req.body.event);

  lambdaLocal.execute({
    event: req.body.event,
    lambdaPath: process.argv[2],
    lambdaHandler: 'handler',
    timeoutMs: 10000,
    callback: function(error, data) {
        if (error) {
          debug('Lambda returned error');
          debug(error);
          res.end(JSON.stringify(data));
        } else {
          debug('Lambda returned response')
          debug(data);
          res.end(JSON.stringify(data));
        }
    }
  });
github rmtuckerphx / alexa-skill-serverless-starter-template / test / e2e / handlerTests.js View on Github external
before(function (cb) {
            const lambdalocal = require("lambda-local");
            lambdalocal.setLogger(winston);
            const lambda = require('../../src/main.js');
            let event = getEvent('AMAZON.StopIntent.json');

            lambdalocal.execute({
                event: event,
                lambdaFunc: lambda,
                lambdaHandler: functionName,
                region: region,
                profileName : profileName,
                callbackWaitsForEmptyEventLoop: false,
                timeoutMs: timeoutMs,
                callback: function (_err, _done) {
                    done = _done;
                    err = _err;

                    if (done) {
github rmtuckerphx / alexa-skill-serverless-starter-template / test / debugger / main.js View on Github external
var event = require('../requests/LaunchRequest.json');

event.session.application.applicationId = config.skillAppID;
event.request.useLocalTranslations = false;

var lambdalocal = require("lambda-local");
var winston = require("winston");
var lambda = require('../../src/main.js');

var functionName = "handler";
var timeoutMs = 3000;
var region = config.region;
var profileName = config.awsProfile;

winston.level = "error";
lambdalocal.setLogger(winston);



lambdalocal.execute({
    event: event,
    lambdaFunc: lambda,
    lambdaHandler: functionName,
    region: region,
    profileName : profileName,
    callbackWaitsForEmptyEventLoop: false,
    timeoutMs: timeoutMs,
    callback: function (_err, _done) {
        done = _done;
        err = _err;

        if (done) {
github taimos / serverless-todo-demo / backend / tst / todoDAO.spec.ts View on Github external
import * as AWS from 'aws-sdk-mock';
import { DocumentClient } from 'aws-sdk/lib/dynamodb/document_client';
import { expect } from 'chai';
import * as lambdaLocal from 'lambda-local';
import ScanOutput = DocumentClient.ScanOutput;
import PutItemInput = DocumentClient.PutItemInput;
import ScanInput = DocumentClient.ScanInput;
import { env } from 'process';
import { listTodos, save, ToDo } from '../lib/data';

lambdaLocal.getLogger().level = 'error';
env.TABLE_NAME = 'SomeTable';

describe('Test ToDo DAO - save', () => {

    it('should save todo', async () => {

        AWS.mock('DynamoDB.DocumentClient', 'put', (params : PutItemInput, callback) => {
            expect(params).to.haveOwnProperty('Item');
            expect(params.Item).to.have.property('id', 'todoId');
            expect(params.Item).to.have.property('text', 'ToDoText');
            expect(params.Item).to.have.property('state', 'OPEN');
            expect(params).to.have.property('TableName', 'SomeTable');
            callback(null, {});
        });

        const todo : ToDo = await save({
github taimos / serverless-todo-demo / backend / tst / todoApi.spec.ts View on Github external
multiValueHeaders: {},
            multiValueQueryStringParameters: {},
            stageVariables: {},
            requestContext: undefined,
            resource: '',
            headers: {},
            body: JSON.stringify({
                id: 'someId',
                text: 'SomeText',
                state: 'OPEN',
            }),
            path: '/todos/{id}',
            isBase64Encoded: false,
        };

        const response : APIGatewayProxyResult = await lambdaLocal.execute({
            event,
            lambdaFunc: api,
            lambdaHandler: 'apiUpdateTodo',
        });

        expect(response.statusCode).to.equal(200);
        expect(response).to.haveOwnProperty('body');
        const todo = JSON.parse(response.body);
        expect(todo).to.have.property('id', 'someId');
        expect(todo).to.have.property('text', 'SomeText');
        expect(todo).to.have.property('state', 'OPEN');
    });
github taimos / serverless-todo-demo / backend / tst / todoApi.spec.ts View on Github external
import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
import { expect } from 'chai';
import * as lambdaLocal from 'lambda-local';
import { describe, it } from 'mocha';
import * as proxyquire from 'proxyquire';
import { ToDo } from '../lib/data';

lambdaLocal.getLogger().level = 'error';

const todoStub = {
    listTodos: undefined,
    save: undefined,
};
const uuidStub = {
    v4: undefined,
};

const api = proxyquire('../lib/index', { './data': todoStub, 'node-uuid': uuidStub });

describe('GetAPI', () => {
    beforeEach(() => {
        delete todoStub.listTodos;
    });

lambda-local

Commandline tool and API to run Lambda functions on your local machine.

MIT
Latest version published 7 months ago

Package Health Score

72 / 100
Full package analysis