Registry / aws / serverless-offline-edge-lambda

serverless-offline-edge-lambda

JSON →
library1.3.1jsnpmunverified

A Serverless Framework plugin (v1.3.1, last updated August 2023) that simulates AWS CloudFront Edge Lambda behavior in local development, enabling testing of viewer-request, viewer-response, origin-request, and origin-response events without deploying to AWS. Unlike serverless-offline (which it cannot be used with), it targets CloudFront edge functions specifically, supporting custom headers, transpilers (serverless-webpack, serverless-plugin-typescript serverless-bundle, esbuild), hot reload via chokidar, and configuration through serverless.yml. Requires serverless >=1.36.0 and ships TypeScript types. Release cadence is sporadic with minor fixes and features.

npm install serverless-offline-edge-lambda
INSTALL
IMPORT
SIG · SERVERLESS-OFFLINE
S
serverless-offline-edge-lambda
awsjavascriptv1.3.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

plugin
plugins: - serverless-offline-edge-lambda
constants: - serverless-offline-edge-lambda
Must be listed in the plugins section of serverless.yml, not as a require in code.
custom.offlineEdgeLambda
custom: offlineEdgeLambda: path: '.build'
custom: serverless-offline-edge-lambda: path: '.build'
Configuration goes under custom.offlineEdgeLambda, not a plugin-specific top-level key.
lambdaAtEdge
functions: myFunction: handler: src/handler.onViewerRequest lambdaAtEdge: distribution: 'MyDistribution' eventType: 'viewer-request'
functions: myFunction: handler: src/handler.onViewerRequest lambdaAtEdge: Distribution: 'MyDistribution' eventType: 'viewer-request'
The case for lambdaAtEdge fields must be lowercase (distribution, eventType, pathPattern) matching the convention used by serverless-plugin-cloudfront-lambda-edge.

Shows complete setup of serverless-offline-edge-lambda with a sample function and CloudFront distribution in serverless.yml, plus the command to start offline.

npm install --save-dev serverless serverless-offline-edge-lambda # serverless.yml service: edge-lambdas plugins: - serverless-offline-edge-lambda provider: name: aws runtime: nodejs12.x functions: lambda: handler: src/handlers.onViewerRequest lambdaAtEdge: distribution: 'WebsiteDistribution' eventType: 'viewer-request' pathPattern: '/lambda' resources: Resources: WebsiteDistribution: Type: 'AWS::CloudFront::Distribution' Properties: DistributionConfig: DefaultCacheBehavior: # Start offline npx serverless offline start --port=3000
Debug
Known issues
gotchaCannot use with serverless-offline: both plugins define the 'offline' command, causing conflicts.
fix
Use only serverless-offline-edge-lambda for CloudFront edge testing; do not install serverless-offline.
affects: >=1.0.0
gotchaHot reload requires path to built handlers; incorrect path causes no hot reload.
fix
Specify custom.offlineEdgeLambda.path to point to the output directory of your transpiler (e.g., '.build', '.webpack/service').
affects: >=1.2.0
deprecatedNode.js 12 runtime is used in example; newer runtimes (14, 16, 18) are supported but not shown.
fix
Set provider.runtime to nodejs14.x, nodejs16.x, or nodejs18.x as needed.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'serverless-offline-edge-lambda'
Plugin not installed or not in devDependencies.
fix
Run npm install --save-dev serverless-offline-edge-lambda
Configuration error: 'lambdaAtEdge' is not defined
The plugin is not listed in the plugins section of serverless.yml.
fix
Add 'serverless-offline-edge-lambda' to the plugins list.
Error: Cannot start offline because serverless-offline is also installed
Both plugins define the 'offline' command.
fix
Remove serverless-offline from dependencies.
TypeError: Cannot read property 'startsWith' of undefined
The handler path in lambdaAtEdge is incorrectly formatted or missing.
fix
Ensure handler format is like 'src/handlers.onViewerRequest' with function name after the dot.
Upgrade
Version history
1.3.1latest on npm
Audit
Dependencies
serverlessrequiredPeer dependency required for the plugin to function
Agent activity
15 hits · last 30 days
node
14
Resources
serverless-offline-edge-lambda — npm install serverless-offline-edge-lambda · libregistry