aglex
v2.0.0
Published
API Gateway + Lambda + Express development tool
Downloads
16
Maintainers
Readme
Aglex is a support tool for building serverless web applications using Amazon API Gateway, AWS Lambda and Express.
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
- Start your app with express-generator.
$ npm install express-generator -g
$ express myapp
$ cd myapp && npm install
- 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;
- 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
- Generate lambda handler code and install aws-serverless-express
$ aglex generate lambda-handler > lambda.js
$ npm install -S aws-serverless-express
- 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.
- Create/update your lambda function
$ aglex --config aglex.yml lambda update --zip lambda.zip
Create IAM Role for Lambda function
lambda-myapp
before execution.
- Add execute permission to your lambda function (first time only)
$ aglex --config aglex.yml lambda add-permission
- Create/update API
$ aglex --config aglex.yml apigateway update
- Create stage and deploy API
$ aglex --config aglex.yml apigateway deploy --stage dev
For more information, please see wiki docs.
See Also
- aws-serverless-express is developed by AWS to make it easy to run Express apps on Lambda.