Skip to content

Rookout/lambda-node-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quickstart for Node + Rookout on AWS Lambda

A sample application for using Node + Rookout on AWS Lambda

Before following this guide we recommend reading the basic Node + Rookout guide

Rookout Integration Explained

There are 3 simple steps to integrate Rookout into your existing Node application:

  1. Add the npm dependency rookout

  2. Wrap your lambda function with rookout.wrap()

  3. Set the Rook's configuration as environment variables in the Lambda configuration

Running on Lambda

For this example we are using Amazon's Node.js Function for an API with Lambda Proxy Integration hello world function

  1. 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 zip

      IMPORTANT: 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 or npm 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

  2. Set the Rook's agent configuration as environment variables in the Lambda configuration, fill the Environment Variables for :

    • ROOKOUT_TOKEN : Your Organization Token
    • ROOKOUT_ROOK_TAGS : lambda

    More information can be found in our documentation

  3. Go to app.rookout.com and start debugging !

Rookout Integration Process

We have added Rookout to the original project by:

  1. Installing rookout dependency : npm install --save rookout and adding it in the entry file const rookout = require('rookout/lambda');

  2. Wrapping your function with the Lambda wrapper as such :
    const rookout = require('rookout/lambda');

exports.handler = rookout.wrap((event, context, callback) => {
    ....
    ....
    ....
    callback(null, response);
});
  1. Set Lambda environment ROOKOUT_TOKEN in order to connect

About

Demo serverless function using AWS Lambda & NodeJS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published