The `aws-sam-webpack-plugin` is a Webpack plugin designed to integrate Webpack into the AWS Serverless Application Model (SAM) CLI build process. Its primary function is to replace the traditional `sam build` command, offering an alternative for developers working with Node.js runtimes. This plugin emerged to address two key limitations of the SAM CLI at the time: a lack of robust native TypeScript support and slow build times, particularly due to SAM CLI's tendency to run `npm pack` and `npm install` for each function. It facilitates faster builds, comprehensive TypeScript and Babel support via Webpack loaders, and can even auto-generate VS Code debugging configurations. The current stable version is 0.16.0. However, the project is explicitly in a maintenance-only state, as the author now recommends utilizing the AWS SAM CLI's built-in TypeScript support, which has since matured. While community PRs for new runtime support will be merged, active feature development has ceased. This plugin's historical significance lies in providing a more efficient, Webpack-driven build workflow for SAM applications, especially beneficial for TypeScript users, before official tooling caught up.
npm install aws-sam-webpack-pluginVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to install the plugin and configure a `webpack.config.js` file for a typical AWS SAM project using TypeScript. It includes setting up dynamic entry points, output paths, TypeScript loader, and handling `aws-sdk` externals for Lambda.
Evaluate migrating existing projects or starting new projects with the official AWS SAM CLI's TypeScript capabilities to leverage active development and support.
Ensure all Lambda functions in your SAM template use Node.js 10.x runtime or newer. If you must use Node.js 8.10, pin the plugin version to `<0.6.0`.
Verify that all Lambda handler paths specified in your `template.yaml` (or inferred) correctly point to existing files. Webpack's resolution extensions (`resolve.extensions`) are now used for checking existence.
If you are on `v0.5.0` and experienced compatibility issues, immediately upgrade to `v0.5.1` or a newer version to resolve the bug.
Consider refactoring `InlineCode` to use `CodeUri` pointing to a file or directory for better maintainability and to avoid console warnings, or acknowledge the warning if `InlineCode` is explicitly desired.
Verify that the handler path in your `template.yaml` is correct and the file exists. Ensure your `webpack.config.js` `resolve.extensions` array includes the correct file extension (e.g., `.ts`, `.js`) for your handler files.
Modify your `webpack.config.js` to set the entry point as a function: `entry: () => awsSamPlugin.entry()`. This ensures the SAM template is reloaded and parsed on every Webpack rebuild, reflecting any changes.