aws-lambda-nodejs-webpack
Advanced tools
CDK Construct to build Node.js AWS lambdas using webpack
Weekly downloads
Readme
CDK Construct to build Node.js AWS lambdas using webpack
Table of contents:
yarn add aws-lambda-nodejs-webpack
// infra/super-app-stack.js
const sns = require("@aws-cdk/aws-sns");
const subscriptions = require("@aws-cdk/aws-sns-subscriptions");
const core = require("@aws-cdk/core");
const { NodejsFunction } = require("aws-lambda-nodejs-webpack");
module.exports = class SuperAppProductionStack extends core.Stack {
constructor(scope, id, props) {
super(scope, id, props);
const slackNotificationsLambda = new NodejsFunction(
this,
"slack-notifications-lambda",
{
entry: "events/slack-notifications.js", // required
},
);
}
};
// events/slack-notifications.js
import { WebClient as SlackWebClient } from "@slack/web-api";
export function handler(event) {
const message = event.Records[0].Sns.Message;
// do something with message
}
vendor.js
file. Allowing you to debug your own code in AWS console most of the timeThere's already a dedicated aws-lambda-nodejs module for CDK but I had two major issues with it:
I want to be clear: I respect a LOT the work of the CDK team, and especially @jogold, author of aws-lambda-nodejs) that helped me a lot into debugging performance issues and explaining to me how everything works.
⚠️ the only configuration file from your project that we will read is tsconfig.json
(not including compilerOptions, which are overwritten using https://www.npmjs.com/package/@tsconfig/node12).
Other files won't be used (example: .babelrc). If you need to reuse part of your babel configuration, please open an issue with details on your usecase so we can build the best API for how to do this.
// fork and clone
cd aws-lambda-nodejs-webpack
yarn
yarn link
yarn start
# in another terminal and project where you want to test changes
yarn link aws-lambda-nodejs-webpack
# cdk commands will now use your local aws-lambda-nodejs-webpack