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

@pckilgore/now-builder-s3

v0.9.3

Published

A now.sh builder that uploads files to S3. It can even build, zip, and upload lambda functions.

Downloads

10

Readme

:cyclone: now-builder-s3

Statusnpm version

Deploy your files and AWS lambdas to AWS S3 using now.sh builders.

Supports arbitrary files, Buckets, and bucket paths.

Compile, minify, and/or bundle your lambdas (or push them as is with dependencies)!

Use Cases

Handles:

  • Uploading one or many files/objects.
  • Zipping one or many objects, and then uploading:
    • Deploy pre-compiled or no-compile AWS lambda functions!
  • Building, zipping, and uploading javascript projects:
    • Upload a node JS project, build in the cloud, and deploy as an AWS lambda!

Examples

See these fixtures for real-life examples!

Upload arbitrary folder of stuff

Note: entry point must be a file, but the builder will upload all files in the directory of the entry point.

now.json

{
  "version": 2,
  "build": {
    "env": {
      "AWS_ACCESS_KEY_ID": "@now_s3_iam_access_key",
      "AWS_SECRET_ACCESS_KEY": "@now_s3_iam_secret_key",
      "AWS_REGION": "us-east-2"
    }
  },
  "builds": [
    {
      "src": "./arbitrary-stuff/index.txt",
      "use": "@pckilgore/now-builder-s3",
      "config": {
        "Bucket": "your bucket",
        "objectPath": "an-arbitrary/nested/path/to/put/object" // (not required)
      }
    }
  ]
}

Upload a simple lambda

All files in the entry point's directory will be zipped (go ahead and deploy python lambdas, or a compiled go lambda!).

now.json

{
  "version": 2,
  "build": {
    "env": {
      /*see above*/
    }
  },
  "builds": [
    {
      "src": "src/index.js",
      "use": "@pckilgore/now-builder-s3",
      "config": {
        "Bucket": "test",
        "lambda": { "name": "my-lambda-fn" }
        // will upload to test/my-lambda-fn.zip
      }
    }
  ]
}

src/index.js

const one = require("./some-module");

exports.handler = (evt, ctx) => one();

src/some-module.js

module.exports = () => 1;

Upload a lambda (build before zipping/deploying)

If you set a package.json file as the entry point, your dependencies will be installed before compressing and uploading. (So your uploaded zip will contain all your node_modules!)

If you set config.lambda.build to true, the builder will run your scripts.now-build script. It will then only zip and upload the files in your config.build.distDir folder (defaults to dist/ if not provided).

now.json

{
  "version": 2,
  "build": {
    "env": {
      /* see above*/
    }
  },
  "builds": [
    {
      "src": "package.json",
      "use": "@pckilgore/now-builder-s3",
      "config": {
        "Bucket": "now-builder-s3-test",
        "lambda": {
          "name": "06-compiled-lambda",
          "build": true,
          "distDir": "arbitrary/"
        },
        "objectPath": "06-compiled-lambda/whynotasubfolder/"
      }
    }
  ]
}

A Note on Monorepo Support

This repo was developed to support a lerna monorepo, and should work out of the box for this use case. However, if you use lerna hoisting or yarn workspaces, or link dependencies with yarn link or npm link you will not be able to deploy the node_module style lambda.

This is because the archiving library cannot currenly identify and resolve the hoisted node_modules:

.
├── node_modules <-- Deps hoisted here!
│   └── left-pad
├── packages
│   └── module <-- But we are trying to zip this folder
│       ├── src
│       │   └── index.js
│       └── package.json
├── lerna.json
└── package.json

For this use case, you'll just have to build your lambda (there are good reasons to do this anyways!)

The compiled lambda will have all its deps along for the ride and no need to resolve a hoisted node_modules folder.

Future plans

Import and compose, rather than duplicate, official builders.

Let me know what your use cases are for this!

Right now, I use it to deploy AWS lambdas that manage features now.sh cannot yet provide (Cloudwatch, SNS, SQS, etc...).