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));
}
}
});
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');
});