Registry / aws / aws-sam-webpack-plugin

aws-sam-webpack-plugin

JSON →
library0.16.0jsnpmunverified

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-plugin
INSTALL
IMPORT
SIG · AWS-SAM-WEBPACK-PL
A
aws-sam-webpack-plugin
awsjavascriptv0.16.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AwsSamPlugin
import AwsSamPlugin from 'aws-sam-webpack-plugin';
const AwsSamPlugin = require('aws-sam-webpack-plugin');
The plugin is typically consumed as a default export in modern TypeScript/ESM projects. The CommonJS 'require' syntax is also shown in examples but less common for new ESM projects.

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.

npm install webpack webpack-cli typescript ts-loader aws-sam-webpack-plugin @types/aws-lambda rimraf --save-dev # OR yarn add webpack webpack-cli typescript ts-loader aws-sam-webpack-plugin @types/aws-lambda rimraf -D # Production dependencies (often externalized for Lambda) npm install aws-sdk --save # OR yarn add aws-sdk --save // webpack.config.js const path = require("path"); const AwsSamPlugin = require("aws-sam-webpack-plugin"); const awsSamPlugin = new AwsSamPlugin(); module.exports = { // Loads the entry object from the AWS::Serverless::Function resources in your // SAM config. Setting this to a function will reload your SAM config on rebuild. entry: () => awsSamPlugin.entry(), // Write the output to the .aws-sam/build folder output: { filename: (chunkData) => awsSamPlugin.filename(chunkData), libraryTarget: "commonjs2", path: path.resolve("."), }, // Create source maps devtool: "source-map", // Resolve .ts and .js extensions resolve: { extensions: [".ts", ".js"], }, // Target node for Lambda environment target: "node", // Exclude aws-sdk from bundle by default for smaller package size externals: process.env.NODE_ENV === "development" ? [] : ["aws-sdk"], // Set the webpack mode mode: process.env.NODE_ENV || "production", // Add the TypeScript loader module: { rules: [{ test: /\.tsx?$/, loader: "ts-loader" }], }, // Add the AWS SAM Webpack Plugin plugins: [ awsSamPlugin ] };
Debug
Known issues
deprecatedThe author now recommends using the native AWS SAM CLI's built-in TypeScript support. This plugin is primarily in maintenance mode with limited updates, only accepting PRs for new runtime support.
fix
Evaluate migrating existing projects or starting new projects with the official AWS SAM CLI's TypeScript capabilities to leverage active development and support.
affects: >=0.1.0
breakingNode.js 8.10 runtime support was removed.
fix
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`.
affects: >=0.6.0
breakingThe build process will now fail if the specified handler file for a Lambda function does not exist.
fix
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.
affects: >=0.5.0
breakingVersion 0.5.0 introduced a bug that broke backwards compatibility with v0.4.0 projects.
fix
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.
affects: 0.5.0
gotchaUsing `InlineCode` in your SAM template, rather than a `CodeUri`, will generate a warning message on the console.
fix
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.
affects: >=0.4.0
Errors
Common errors & fixes
Error: Webpack can't resolve '[HANDLER_PATH]' in '[PROJECT_ROOT]'
The handler file specified for a Lambda function in your SAM template (or derived) cannot be found by Webpack's module resolution.
fix
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.
Changes in SAM template (e.g., new functions, changed runtimes) are not reflected after Webpack rebuilds.
The `entry` option in your `webpack.config.js` is set to `awsSamPlugin.entry()` directly instead of a function that re-evaluates the entry points on each build.
fix
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.
Upgrade
Version history
0.16.0latest on npm
Audit
Dependencies
webpackrequiredCore dependency as this is a Webpack plugin.
webpack-clirequiredNeeded to run Webpack commands.
typescriptoptionalRequired for TypeScript projects, often used with this plugin.
ts-loaderoptionalWebpack loader for TypeScript files, commonly used with this plugin.
@types/aws-lambdaoptionalProvides TypeScript definitions for AWS Lambda handler types.
aws-sdkoptionalAlthough often externalized in Lambda bundles, it's a common runtime dependency. If not externalized, it must be included.
Agent activity
17 hits · last 30 days
node
16
OpenAI (training)
1
Resources
aws-sam-webpack-plugin — npm install aws-sam-webpack-plugin · libregistry