API Gateway + Lambda + Express development tool
JavaScript
Latest commit 7bff159 Nov 17, 2016 @u-minor 2.0.0
Permalink
Failed to load latest commit information.
config
examples
src
test
.babelrc
.eslintrc
.gitignore
.travis.yml
README.md
logo.png
package.json 2.0.0 Nov 17, 2016

README.md

aglex

Aglex is a support tool for building serverless web applications using Amazon API Gateway, AWS Lambda and Express.

Build Status Build Status Coverage Status Dependency Status bitHound Code

No more new frameworks for Lambda + API Gateway!

Express is the most famous web framework for Node.js. Now you can use the same way to develop your API Gateway-Lambda web app.

UPDATE: now 2.x uses aws-serverless-express and new config yaml.

Installation

Global install

$ npm install aglex -g

or install and add to current package.

$ npm install aglex --save-dev

Features

Aglex is not a web framework, just a small CLI tool which provides following features.

  • Generate a small lambda handler code
  • Create, update lambda function
  • Add execute-api permission to the function
  • Create, update and deploy API

Quick start

  1. Start your app with express-generator.

    $ npm install express-generator -g
    $ express myapp
    $ cd myapp && npm install
  2. Modify routes/users.js to respond JSON data.

    @@ -3,7 +3,7 @@
    
    /* GET users listing. */
    router.get('/', function(req, res, next) {
    -  res.send('respond with a resource');
    +  res.json({message: 'respond with a resource'});
    });
    
    module.exports = router;
  3. Generate config yaml

    $ aglex generate config > aglex.yml

    Edit it to match your environment.

    @@ -18,14 +18,14 @@
       Runtime: nodejs4.3
       MemorySize: 128
       Timeout: 60
    -  FunctionName: YOUR_LAMBDA_FUNCTION_NAME
    -  Description: YOUR_LAMBDA_DESCRIPTION
    -  RoleName: YOUR_LAMBDA_EXECUTION_ROLE # Role ARN will generate from RoleName automatically
    +  FunctionName: myapp
    +  Description: myapp
    +  RoleName: lambda-myapp # Role ARN will generate from RoleName automatically
    
    ## API Gateway configuration
    apiGateway:
     swagger: 2.0
     info:
    -    title: YOUR_API_NAME
    -    description: YOUR_API_DESCRIPTION
    +    title: myapp
    +    description: myapp
       basePath: /prod
       schemes:
         - https
  4. Generate lambda handler code and install aws-serverless-express

    $ aglex generate lambda-handler > lambda.js
    $ npm install -S aws-serverless-express
  5. Create lambda zip

    $ zip -r lambda.zip app.js lambda.js routes views node_modules

    Use Gulp/Grunt if you want to do more tasks.

  6. Create/update your lambda function

    $ aglex --config aglex.yml lambda update --zip lambda.zip

    Create IAM Role for Lambda function lambda-myapp before execution.

  7. Add execute permission to your lambda function (first time only)

    $ aglex --config aglex.yml lambda add-permission
  8. Create/update API

    $ aglex --config aglex.yml apigateway update
  9. Create stage and deploy API

    $ aglex --config aglex.yml apigateway deploy --stage dev

For more information, please see wiki docs.

See Also