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.
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
.
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.
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
.
- https://github.com/motdotla/node-lambda
- https://github.com/motdotla/node-lambda-template
- http://kennbrodhagen.net/2015/12/06/how-to-create-a-request-object-for-your-lambda-event-from-api-gateway/
(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.