Jets Simple AWS Lambda Ruby Function

Tung Nguyen
BoltOps
Published in
2 min readOct 26, 2018

Jets supports writing simple AWS Lambda functions with Ruby. You define them in the app/functions folder. A function looks like this:

app/functions/simple.rb:

def lambda_handler(event:, context:)
puts "hello world"
end

The default handler is named lambda_handler. The lambda function shows up in the Lambda console like this:

You can run the function in the AWS Lambda console and see the results:

More than Simple Functions

Though simple functions are supported by Jets, aside from the ability to use Ruby they do not really add much value. Other classes like controllers and jobs add many conveniences and are more powerful to use. Here are a few quick examples:

Controllers

class PostsController < ApplicationController
def index
# renders Lambda Proxy structure compatiable with API Gateway
render json: {hello: "world", action: "index"}
end
end

Controllers are designed to handle web request and serve responses.

The public methods of a Controller class get deployed as separate AWS Lambda functions.

Jobs

class HardJob < ApplicationJob
rate "10 hours" # every 10 hours
def dig
puts "done digging"
{done: "digging"}
end
end

Jobs are designed to handle background jobs and can process work outside the web request cycle. The rate declaration creates a CloudWatch rule and schedules the function to run periodically.

Once again, the public methods of a Job class get deployed as separate AWS Lambda functions.

So you’d probably benefit more from writing Controllers and Jobs since they add so many conveniences over the simple function.

Thanks for reading this far. If you found this article useful, I’d really appreciate it if you share this article so others can find it too! Thanks 😁 Also follow me on Twitter.

Got questions? Check out BoltOps.

Originally published at https://blog.boltops.com on October 26, 2018.

--

--