Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
}
},
"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);
}
}
});
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);
}
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));
}
}
});
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) {
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) {
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({
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');
});
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;
});