A sample application for using Node + Rookout on AWS Lambda
Before following this guide we recommend reading the basic Node + Rookout guide
There are 3 simple steps to integrate Rookout into your existing Node application:
-
Add the npm dependency
rookout
-
Wrap your lambda function with
rookout.wrap()
-
Set the Rook's configuration as environment variables in the Lambda configuration
For this example we are using Amazon's Node.js Function for an API with Lambda Proxy Integration hello world function
-
Uploading your function :
-
Zip Upload: In order to run your rookout wrapped function on Lambda, make sure the dependencies are downloaded and zip the folder (including node_modules).
zip -r rookout_lambda_example.zip .
Download ready-to-upload zipIMPORTANT: If you are building on a MacOS/Windows machine, npm will compile native binaries for this platform. AWS Lambda runs on Linux and thus needs the linux compiled binaries. The solution is doing
npm install
ornpm rebuild
on a Linux machine such as an EC2 instance and re-archive the zip for uploading to Lambda. -
aws-cli -> Create a new Lambda function (It may take a few minutes due to uploading a large file size) :
$ aws lambda create-function \ --region <REGION> \ --function-name rookout_lambda_example \ --zip-file fileb://rookout_lambda_example.zip \ --role <ROLE-ARN> \ --handler index.handler \ --runtime nodejs8.10 \ --environment Variables="{ROOKOUT_ROOK_TAGS=lambda,ROOKOUT_TOKEN=<org_token>}"
To create an API Gateway resource, refer to AWS Documentation or create it through the AWS Lambda Console. If you do not have access to aws-cli, you can do this from the AWS console and follow the Amazon Documentation
-
OR Using Cloud9 IDE integrated tools
-
-
Set the Rook's agent configuration as environment variables in the Lambda configuration, fill the Environment Variables for :
ROOKOUT_TOKEN
: Your Organization TokenROOKOUT_ROOK_TAGS
: lambda
More information can be found in our documentation
-
Go to app.rookout.com and start debugging !
We have added Rookout to the original project by:
-
Installing rookout dependency :
npm install --save rookout
and adding it in the entry fileconst rookout = require('rookout/lambda');
-
Wrapping your function with the Lambda wrapper as such :
const rookout = require('rookout/lambda');
exports.handler = rookout.wrap((event, context, callback) => {
....
....
....
callback(null, response);
});
- Set Lambda environment
ROOKOUT_TOKEN
in order to connect