Skip to content
This repository has been archived by the owner on Feb 5, 2020. It is now read-only.

A minimal template for an ES2015+ Node.js app running on AWS Lambda (w/ babel and webpack).

License

Notifications You must be signed in to change notification settings

flesch/node-lambda-babel-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-lambda-babel-template

NPM version Dependencies Dev-dependencies Known Vulnerabilities Build Status

This project adds webpack and Babel to @motdotla's node-lambda-template so you can run the lastest version of Javascript on AWS Lambda.

babel-preset-latest is automatically included, but you can easily add additional presets and plugins.

webpack transforms index.js outputting to dist/index.js, which is then pushed up to AWS Lambda with node-lambda.

Getting Started

To get started, download the latest template files:

$ curl -o- https://ribjyr1g9l.execute-api.us-east-1.amazonaws.com/nodelambdababeltemplate/latest | bash

Before running the command above, please take a look at https://ribjyr1g9l.execute-api.us-east-1.amazonaws.com/nodelambdababeltemplate/latest directly. Piping anything unknown through bash can be dangerous!

The install script is created using this: https://gist.github.com/flesch/8ed6f47942350e858ebd3283e10f8a9b.

To download a specific release, use the following:

$ curl -o- https://ribjyr1g9l.execute-api.us-east-1.amazonaws.com/nodelambdababeltemplate/v2.1.0 | bash

Or clone this repository and remove the .git folder.

$ git clone --depth 1 https://github.com/flesch/node-lambda-babel-template.git && cd node-lambda-babel-template && rm -rf .git

Next, install the dependencies.

$ npm install

The postinstall npm hook will run node-lambda setup, giving you the context.json, event.json, .env, and deploy.env files.

See https://github.com/motdotla/node-lambda#setup for more details.

Note: AWS_ENVIRONMENT and AWS_HANDLER are defined in the npm scripts in package.json, not .env.

Developing

webpack will watch index.js and transform it as dist/index.js while you make changes.

$ npm start

Modify webpack.config.js and .babelrc to add addtional plugins and presets.

You can test your changes by running:

$ npm test

Modify event.json to mock your event.

Deploying

To deploy your compiled index.js to AWS Lambda, simply run:

$ npm run deploy

The predeploy npm hook will recompile index.js using Webpack in production mode. node-lambda deploy is then executed, including deploy.env.

See Also

License

(The MIT License)

Copyright (c) 2016 John Flesch.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.