Skip to content

Commit 2b9be3f

Browse files
committed
Get event.json to work when running a function locally
1 parent 00878b8 commit 2b9be3f

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

lib/RuntimeWebpack.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,17 @@ module.exports = function(S) {
6363
*/
6464

6565
run(func, stage, region, event) {
66-
6766
return this
6867
.getEnvVars(func, stage, region)
69-
.then((envVars) => {
68+
.then((envVars) => S.utils.readFile(func.getRootPath('event.json')).then(localEvent => ({
69+
envVars,
70+
localEvent,
71+
})))
72+
.then((locals) => {
7073
const childArgs = [__dirname + '/webpack-runner'];
7174
const resultSep = '___serverless_function_run_results___';
7275
const input = JSON.stringify({
73-
event,
76+
event: event || locals.localEvent,
7477
resultSep,
7578
handler: func.handler,
7679
name: func.getDeployedName({stage, region}),
@@ -79,7 +82,7 @@ module.exports = function(S) {
7982
webpackConfig: this.getWebpackConfig(func, path.join(S.config.projectPath, '_meta/_tmp/', func.name), true),
8083
});
8184

82-
const env = Object.assign(envVars, process.env, {
85+
const env = Object.assign(locals.envVars, process.env, {
8386
NODE_PATH: path.resolve(__dirname, '..', 'node_modules')
8487
});
8588

lib/webpack-runner.js

-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ getConfig().then((config) => {
9090
return stats;
9191
})
9292
.then((stats) => {
93-
// console.log(stats);
94-
9593
const functionFile = path.join(config.webpackConfig.output.path, config.webpackConfig.output.filename);
9694
const functionHandler = handlerArr[1];
9795
const fn = require(functionFile)[functionHandler];

0 commit comments

Comments
 (0)