Tracking Ruby Errors on AWS Lambda
Typical installation time: 1 minute
Hi there! You’ve found Honeybadger’s guide to Ruby Exception and error tracking on AWS Lambda and Serverless. Once installed, Honeybadger will report exceptions wherever they may happen.
If you’re new to Honeybadger, read our Getting Started guide to become familiar with our Ruby gem. For a refresher on working with exceptions in Ruby, check out the Honeybadger guide to Ruby exceptions.
On this page:
The first step is to add the honeybadger gem to your Gemfile:
Tell bundler to install:
$ bundle install --deployment --without development,test
Depending on your deployment method, vendoring might be required to ensure your dependencies are included. We think the serverless framework is a cool way to manage your lambda functions.
You can configure Honeybadger in your lambda by adding your API key via the
HONEYBADGER_API_KEY environment variable.
Our client does not provide an automatic way to handle uncaught lambda
exceptions. Fortunately, reporting errors is simple within the handler. We
recommend that you use an implicit rescue block. You can then pass the error to
Honeybadger.notify method. It’s up to you to determine what to do with the
error after notifying. You may want to respond with a 500 or you can re-raise
(so the handler can rerun if you have retries enabled).
Here is a simplified version:
require 'honeybadger' def handler(event:, context:) # Your logic rescue StandardError => e Honeybadger.notify(e) raise e end
Notice that we are rescuing all
StandardError exceptions. You can rescue lower
Exception if you would like, however I would refer to Starr’s blog
on the topic before you decide on that.