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:

Installation

The first step is to add the honeybadger gem to your Gemfile:

ruby
gem 'honeybadger'

Tell bundler to install:

bash
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

To automatically capture exceptions from your Lambda handler, register your handlers with the hb_wrap_handler method. Any unhandled exceptions raised within the specified methods will be automatically reported to Honeybadger.

ruby
require 'honeybadger' hb_wrap_handler :my_handler1, :my_handler2 def my_handler1(event:, context:) # ... end def my_handler2(event:, context:) # ... end

For class methods, you'll need to first extend our LambdaExtensions module:

ruby
class MyLambdaApp extend ::Honeybadger::Plugins::LambdaExtension hb_wrap_handler :my_handler def self.my_handler(event:, context:) # ... end end