npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

serverless-offline-edge-lambda

v1.3.1

Published

A plugin for the Serverless Framework that simulates the behavior of AWS CloudFront Edge Lambdas while developing offline.

Downloads

4,467

Readme

serverless-offline-edge-lambda

A plugin for the Serverless Framework that simulates the behavior of AWS CloudFront Edge Lambdas while developing offline.

Setup

npm install --save-dev serverless
npm install --save-dev serverless-offline-edge-lambda

serverless.yml

service:
  name: 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:
npx serverless offline start --port=<port>

Use with serverless-offline

The plugin should not be used in conjunction with serverless-offline because both plugins define the offline command.

Use with serverless-plugin-cloudfront-lambda-edge

This plugin does not handle packaging and deploying edge lambdas to the cloud. Therefore this plugin can be used with serverless-plugin-cloudfront-lambda-edge. Again, doing so is optional. The schema in serverless.yml derives from that used by serverless-plugin-cloudfront-lambda-edge.

Use with Transpilers

This plugin can also be used with transpilers such as serverless-plugin-typescript. In the cases where the transpiler outputs built files to a path that differs from the path specified for the handlers (e.g. .build/src/handers.onViewerRequest), this plugin accepts a configuration option path that it uses to resolve function handlers.

plugins:
  - serverless-plugin-typescript

custom:
  offlineEdgeLambda:
    path: '.build'

For usage with serverless-webpack and serverless-bundle the config is similar but the build path changes.

plugins:
  - serverless-webpack # or serverless-bundle

custom:
  offlineEdgeLambda:
    path: './.webpack/service/'

Hot Reload Support

Hot reload for serverless-esbuild and serverless-plugin-typescript are available with extra configuration.

The watch/reload mechanism is available form serverless-webpack, but is disabled by default for esbuild and typescript.

The flag "watchReload: true" will turn on the watcher so that typescript and esbuild solutions use the watcher to hot reload the handlers. The path to the built handlers must be specified for the watcher to work correctly.

example:

custom:
  offlineEdgeLambda:
    path: '.esbuild/service'
    watchReload: true

Additional options can be used to modify the behavior of the file watcher and debounce logic (ignoreInitial, awaitWriteFinish, interval, debounce, and any other chokidar option).

example:

custom:
  offlineEdgeLambda:
    path: '.dist/service'
    watchReload: true
    ignoreInitial: true
    awaitWriteFinish: true
    interval: 500,
    debounce: 750

Options

--headersFile

Default: undefined

CloudFront injects some headers into the request. You can set these by creating a JSON file and passing its path as an option.

Example:

// .cf-headers.json
{
    "CloudFront-Viewer-Country": "us",
    "CloudFront-Viewer-Country-Region": "tx"
}
npx serverless offline start --headersFile .cf-headers.json