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

meteor-lambdify

v0.1.3

Published

Compile and upload a MeteorJS application to AWS Lambda

Downloads

7

Readme

Use this to compile and upload a MeteorJS CLI application to AWS Lambda.

Installing

$ npm install -g meteor-lambdify

Prepping your Meteor App

Requirements

Make sure you remove meteor-platform as a package dependency for your app and replace it with just meteor plus whichever packages you rely on. If you keep meteor-platform, or specifically webapp, your Lambda function will run forever (or at least until your timeout) and cost you tons of cash.

Now, since your Meteor application no longer has webapp, it needs a new main function. In your server code, make sure you define a global main function that takes argv as its singular argument. The value that this function returns will be passed to Lambda's context.succeed, and any error that this function throws will be passed to Lambda's context.fail.

You can install any package you want (as long as they don't rely on webapp) and use them normally inside of your main function.

Development

If you just run meteor inside of your project folder, it'll keep dying with Exit code 0 until it realizes that your app is "crashing". By default, Meteor expects to be running a web application so it assumes your process will be long-running. However, you can tell Meteor to only run it once by using the --once flag, like so: meteor --once.

Accessing the Lambda Event object

The event argument passed to the Lambda handler is appended to process.argv. When running in the Lambda environment, there are no arguments passed to the process, so the event will be the lone element in argv. So, you can access it like so in your main function:

main = function(argv) {
  var event = argv[0];
  console.log('Event data:', event);
  return 'Got event!';
};

Deploying to Lambda

Create the Lambda function in AWS

This script will not create the Lambda function for you - this is intentional, because we don't want to make assumptions about the instance size, timeout, etc. When you create it, make sure you set the following options:

  1. Runtime: "nodejs"
  2. Handler: "exec.handler"
  3. Timeout: At least 4 seconds. From our testing, it takes around 3 seconds to boot the Meteor application and reach your main.

Deploy your function

Run lambdify inside of your project root. This script assumes that you already have the awscli installed AND authenticated (IE, have AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY set in environment variables) on your system. It runs aws lambda update-function-code with the compiled and zipped code.

Flags

The following flags are available:

Function Name (--function)

The name of your AWS Lambda function

Environment Variables (--env)

Set an environment variable inside of your Lambda function (this works by dynamically generating the execution wrapper and setting variables on process.env prior to loading the Meteor program). You can have multiple environment variables. E.g.: --env "MONGO_URL=mongodb://mymongohost:27017/mydb" --env "SOME_OTHER_ENV=testing"

Meteor Settings (--settings)

Similar to environment variables, but this will load a settings JSON file that you can specify to the meteor command with the --settings flag. This will read in the settings file and set it as the METEOR_SETTINGS environment variable. E.g. --settings settings.development.json

No Upload (--noupload)

Set this flag (no argument) to skip the uploading and just bundle your application in a zip archive.

Debug (--debug)

This flag changes the behavior significantly. The application will be built inside of the current directory in a folder called lambda-bundle. It will not be zipped nor will it be uploaded to AWS. Additionally, there will be an additional file inside of the bundle called debug.js that you can use to run your Lambda function, with an optional argument for JSON event data.

For example, this will execute your function passing {"foo":"bar"} as the event data:

$ lambdify --debug
$ cd lambda-bundle/bundle
$ echo "{\"foo\":\"bar\"}" > event.json
$ node debug.js event.json

Example

$ lambdify --function MyLambdaFunction --settings settings.production.json 
/ --env "MONGO_URL=mongodb://mymongohost:27017/mydb"
/ --env "SOME_OTHER_ENV=testing" --upload