Enough structure to get our Lambda handlers in the air.
Airfoil is curated middleware stack that abstracts away common infrastructure needed for Lambda handler functions.
Add this line to your application's Gemfile:
gem 'airfoil'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install airfoil
You can instantiate a new handler with an Airfoil stack like so:
require_relative "config/environment"
STACK = Airfoil.create_stack do |b|
# Custom middleware and handlers go here
b.use Airfoil::Middleware::FunctionName, DbReset, "db-reset"
b.use Airfoil::Middleware::FunctionName, UpdateUpcomingRenewals, "update-upcoming-renewals"
end
def handler(event:, context:)
STACK.call({event: event, context: context})
end
Airfoil also includes a stack of middleware that you can add to or customize to suit your specific needs. Your own middleware can inherit from the base class and implement their own behavior like so:
class MyResolverMiddleware < Airfoil::Middleware::Base
def call(env)
ApplicationResolver.handle(env[:event], env[:context])
end
end
Existing middleware include:
FunctionName
- dispatch any calls made to a specific Lambda function (by name) to a specified handler classLogEvent
- log AWS events in a pretty formatSetRequestId
- set theAWS_REQUEST_ID
environment variable for your function code
There are additional middleware available as separate gems that provide specific functionality. They must be explicitly added to your middleware stack in create_stack
.
Add the airfoil-sentry
gem to your Gemfile.This provides three middlewares:
SentryCatcher
- catch exceptions and report them to Sentry, including context:
b.use Airfoil::Middleware::SentryCatcher
SentryMonitoring
- instrument your function code for Sentry's performance monitoring
b.use Airfoil::Middleware::SentryMonitoring
Add the airfoil-datadog
gem to your Gemfile. This provides a single middleware:
Datadog
- wire up the Datadog Lambda SDK and report traces to it
b.use Airfoil::Middleware::Datadog
Add the airfoil-activerecord
gem to your Gemfile. This provides a single middleware:
DatabaseConnection
- Check a connection in/out and enable the query cache per handler
b.use Airfoil::Middleware::DatabaseConnection
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and the created tag, and push the .gem
file to rubygems.org.