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-plugin-global-layers

v0.2.4

Published

A simple serverless plugin that allows you to define a list of ARN layers that should be added to all your defined lambdas

Downloads

9

Readme

serverless-plugin-global-layers

A simple serverless plugin that allows you to define a list of ARN layers that should be added to all your defined lambdas. You should to be sure that the layer that your are listing are compatible with your runtime

This added layers will not override the specific layers field on function definition, also will concatenate the two configurations in a single one, giving you the option to define specific layers for a function in the standard serverless way, and at the same time add the global ones.

Installation

Install plugin via npm:

npm install --save-dev serverless-plugin-global-layers

Add the plugin to your serverless.yml file:

# ...

custom:
  globalLayers:
    layers:
      - <some-layer-arn>
    excludedFuncs:
      - <function-name-to-exclude>

# ...

plugins:
  - serverless-plugin-global-layers

Project structure

As this plugin does not create any layer and is just in charge of modify your serverless configuration to not repeat your self by adding same layers on all your lambdas, is recommended to manage your lambda layers in a different projects in order to ensure you have the proper ARN first before deploying your project.

Sopouse a monorepo with the next struct:

.
├── layers
│   ├── package.json
│   ├── serverless.yml
│   └── some-layer
│       └── some-file.txt
└── service
    ├── package.json
    ├── serverless.yml
    └── src
        └── handler.js

On this project layers/serverless.yml file should look like this:

service: some-layers

provider:
  name: aws
  stage: ${opt:stage, "dev"}

layers:
  layer1:
    path: some-layer
    description: txt shared files

Here we define a layer called layer1 that is deployed independently from the services or lambdas on the repository. Now we can deploy just the layers before all the lambdas an get the latest layer versions for our lambdas.

And by the other hand service/serverless.yml file should look like this:

service: some-name

custom:
  globalLayers:
    layers:
      - ${cf:some-layers-${self:provider.stage}.Layer1LambdaLayerQualifiedArn}

provider:
  name: aws
  stage: ${opt:stage, "dev"}
  runtime: nodejs18.x
  architecture: x86_64

functions:
  some:
    handler: src/handler.hello

plugins:
  - serverless-plugin-global-layers

On this file we are loading the latest lambda layer ARN by suing a CloudFormation reference to an output provided by the some-layers stack according to the stage deployed:

${cf:some-layers-${self:provider.stage}.Layer1LambdaLayerQualifiedArn}

You have to make sure you are using the correct CF output name by replacing Layer1LambdaLayerQualifiedArn with the one that your layers service provide you after deploy.

You can check more about how to reference CF outputs on serverless on the official documentation

Testing

To start testing the plugin locally, you must add it from your local source to the test project with this command:

npm i --save-dev -D <local-path-to-plugin-folder>