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:

gem 'honeybadger'

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.

It may help to use a Ruby version manager (something like asdf or rvm) to ensure you are building against your selected lambda Ruby runtime. You can view a list of lambda runtime versions here.

You can configure Honeybadger in your lambda by adding your API key via the HONEYBADGER_API_KEY environment variable.

Capturing Exceptions

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 the 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 level Exception if you would like, however I would refer to Starr’s blog post on the topic before you decide on that.