DZone
Cloud Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Cloud Zone > Error Reporting for AWS Lambda

Error Reporting for AWS Lambda

Doing serverless? Everyone is, right? But do you know how to handle errors correctly? Find out how to configure AWS Lambda for less opaque error handling.

John-Daniel Trask user avatar by
John-Daniel Trask
·
Aug. 01, 16 · Cloud Zone · Opinion
Like (2)
Save
Tweet
2.98K Views

Join the DZone community and get the full member experience.

Join For Free

AWS Lambda is a serverless offering from Amazon Web Services to help teams build software without worrying about the underlying machine. Serverless hosting means you're paying just for what you use based on workload.

Not having to worry about the underlying server really is adopting "the cloud" as it was always meant to be: automatic scaling, paying for what you use, and minimizing costs.

However, it does mean also being a Cloud Native. What does that mean? It means you'll want to leverage other cloud products, such as Raygun, because you're not going to have a log directory on the machine. It means connecting services, rather than configuring servers. Overall, it makes managing your infrastructure a thing of the past.

Error Reporting For AWS Lambda Using Raygun

So you've decided to give AWS Lambda a test drive. Maybe you're building an API endpoint, but you want to ensure that you're recording any software errors so that you can fix problems as soon as they appear.

What Makes Raygun Great for AWS Lambda?

Firstly, because you don't have direct access to system resources, your only real option for storing error logs is to use a cloud provider. Raygun's cloud offering is used to track software errors directly with Lambda.

When something goes wrong with your code, Raygun will kick in and send the details to a hosted service. It will also notify you in real time to the fault so you can resolve the issue.

What About the Cost With AWS Lambda?

This is where a service like Raygun really shines. AWS Lambda charges on request count and compute time. The great thing about this is that when Raygun initializes, it is a single line of code that attaches to listen for unhandled errors. This means Raygun will have next to zero impact on the costs unless you're generating errors where Raygun has to collect information to send off.

Reporting Errors From AWS Lambda

Integrating Raygun is really easy. In this example, I'll use the Node support that it has (though Raygun does support most programming languages quite happily). I'm using the default Lambda boilerplate example, with Raygun reporting errors.


process.env.NODE_CONFIG_DIR = process.env["LAMBDA_TASK_ROOT"];

// Include Raygun (note that the library and dependencies has been added to the packages directory)
var raygun = require('raygun');

exports.handler = (event, context, callback) => {

    console.log('Starting');

    try
    {
      var a = 0;
      var b = a.DoSomeMagicThing();
      console.log('Should never reach this');
    }
    catch (e) {    
      console.log('Sending to Raygun');
      // Send the error to Raygun
      var raygunClient = new raygun.Client().init({ apiKey: 'YOUR_API_KEY_GOES_HERE' });
      raygunClient.send(e);
    }    

    callback(null, 'All done..');
};


That's a Wrap

Together, Amazon Lambda and Raygun can help give you a great serverless product offering. You can keep costs under control while not having to manage servers and infrastructure manually.

AWS AWS Lambda Amazon Web Services

Published at DZone with permission of John-Daniel Trask, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Deployment of Low-Latency Solutions in the Cloud
  • Types of UI Design Patterns Depending on Your Idea
  • Debugging Java Collections Framework Issues in Production
  • Maven Tutorial: Nice and Easy [Video]

Comments

Cloud Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo