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-ephemeral

v0.8.8

Published

Serverless Framework plugin to bundles stateless zipped dependencies into the deployable Lambda artifact

Downloads

61

Readme

Serverless Ephemeral

NPM Version Build Status

Serephem

Serverless Ephemeral (or Serephem) is a Serverless Framework plugin that helps bundle any stateless library into a Lambda deployment artifact.

Pre-requirements

  • Node >= 6.9
  • Serverless Framework >= 1.12.0
  • Docker (with docker compose)

Examples

Add the plugin

  1. Install it

    npm i --save-dev serverless-ephemeral
  2. Add it to your serverless.yml file and exclude the .ephemeral directory

    plugins:
      - serverless-ephemeral
    
    package:
      exclude:
        - package.json
        - package-lock.json
        - node_modules/**
        - .ephemeral/**
  3. Add the .ephemeral directory to .gitignore

# Serverless Framework
.serverless
.ephemeral

Configuration

The configuration for the Ephemeral plugin is set inside the custom section of the serverless.yml file. In it, you can define the list of stateless libraries you wish to pull into the final Lambda artifact.

There are two types of configuration:

Both can be enhanced with global configuration options.

Build a library

You can build a specific library during runtime. This is achieved via a Docker container that outputs a zip library.

The Serepehm plugin provides some useful packagers out of the box. However, you can create your own packager via Docker files.

Serephem packagers

You can use one of the Docker packagers provided with the Serephem plugin.

TensorFlow
custom:
  ephemeral:
    libraries:
      - packager:
          name: tensorflow
          version: 1.8.0
  • packager.name is required. This is the packager name identifier for TensorFlow: tensorflow
  • packager.version is required. This will determine which TensorFlow version you want to build.

Build your own packager

You can create your own packager via Docker. To do so:

  1. Create a directory where you will store all your Docker files:

    mkdir my-packager
    cd my-packager
  2. Create a docker-compose.yml file. For example:

    version: "3"
    services:
      packager:
        build: .

    Keep note of the name of your packager service, in this case packager.

  3. Create a Dockerfile and any other support files. For example:

    Dockerfile

    FROM amazonlinux
    
    COPY scripts/build.sh scripts/build.sh
    RUN yum -y install zip && \
    chmod +x scripts/build.sh
    
    CMD [ "scripts/build.sh" ]

    scripts/build.sh

    # create zip destination directory
    mkdir -p /tmp/lambda-libraries
    
    # download library files
    mkdir /tmp/files
    cd /tmp/files
    curl http://example.com/file-1.py --output file-1.py
    curl http://example.com/file-2.py --output file-2.py
    zip -9rq /tmp/lambda-libraries/library-a.zip *

    IMPORTANT: the container must generate a zip file containing the stateless library files. Thus:

    • Your container must zip the stateless library files.

    • You must create a directory where the final zip(s) will be stored. This directory will be mounted to the Serephem's libraries directory, so add only the necessary zip files.

    • It is recommended that your Docker container extends from amazonlinux image to maximize compatibility with the Lambda environment.

  4. Add this configuration to your serverless.yml:

    custom:
      ephemeral:
        libraries:
          - packager:
              compose: my-packager/docker-compose.yml
              service: packager
              output: /tmp/lambda-libraries/library-a.zip

    Notice how each of the values correspond to a setting previously created:

    • compose: points to your Docker compose file, inside the directory you created

    • service: the name of the service inside the docker-compose.yml file

    • output: the output path for the zip file in the Docker container

Download a library

You can download a previously zipped library that contains all the necessary files and automatically add it to your Lambda deployment.

custom:
  ephemeral:
    libraries:
      - url: https://xxxxx.s3.amazonaws.com/my-library.zip
  • url is required. This is the packaged library you want to include. The library must be a zip file.

Documentation explaining how to create a deployable TensorFlow zipped package can be found here: docs/build-tensorflow-package.md. This approach can be used as a base to create other stateless libraries.

Global options

custom:
  ephemeral:
    libraries:
      - packager:
          name: tensorflow
          version: 1.8.0
        directory: tfpackage
      - url: https://xxxxx.s3.amazonaws.com/my-library.zip
        nocache: true
  • directory is optional. When ommitted, the package contents will be unzipped at service root level. If entered, a new folder will be created at that level using the specified name and everything will be unzipped there. The folder can only be named using alphanumeric characters and the symbols . _ -

  • nocache is optional. When ommitted or set to false, it will use the locally cached copy of the library. Otherwise, if set to true, it will re-fetch (download or build) the library every time the service is packaged.

    Note: the forceDownload option has been deprecated in favor of nocache

Deploy

Deploy your service normally with the serverless deploy (or sls deploy) command. If you use the -v option, Ephemeral will show more information about the process.

sls deploy -v

If the Serverless deployment is timing out, use the AWS_CLIENT_TIMEOUT environment variable: https://github.com/serverless/serverless/issues/490#issuecomment-204976134

The .ephemeral directory

During the deployment process, the .ephemeral directory will be created. The purpose of this directory is:

  • Saving the libraries' zip files inside the .ephemeral/lib folder
  • Bundling the libraries and the Serverless Lambda function file(s) inside the .ephemeral/pkg folder

Development

This plugin is created with Node and uses the Serverless Framework hooks to execute the necessary actions.

Getting started

  1. Clone this repo
  2. Install dependencies via npm i

Running Lint

The plugin code uses the AirBnB ESLint rule set with some enhancements (see .eslintrc file). To run the linter:

npm run lint

Tests

The unit tests are coded with Ava and SinonJS. They can be found inside the spec folder.

To run the tests:

npm test

To run tests on "watch" mode and add verbosity:

npm test -- --watch -v

Test via examples

Refer to the examples directory, for instance the TensorFlow example.