Debugging Jets on Lambda / Production (Timeouts)


#1

I have been trying to figure out what is going on with the timeout on production as my local jets project runs fine. Here is the scenario:

  1. Setup a new project
jets new temp-project --mode api --database postgres
  1. add gem 'pg' to the Gemfile
  2. Update the .env.production with DB_HOST, DB_USER and DB_PASS for serverless db on aws
  3. Configure proper vpc_config variables in application.rb for a private subnet with NAT gateway
  4. Create a home index and update the route
class HomeController < ApplicationController
  def index
    database = 'disconnected'

    begin
      ActiveRecord::Base.establish_connection
      puts ActiveRecord::Base.connection
      database = 'connected' if ActiveRecord::Base.connected?
    rescue
    end

    { database: database }
  end
end
  1. Invoke the function directly or via the api gateway to see that it doesn’t resolve, but it times out (even with a 60 sec timeout).
  2. Create a standalone function
# functions/connection_test.rb
require 'json'
require 'pg'

def lambda_handler(event:, context:)
  puts "event: #{JSON.dump(event)}"
  puts "connecting"

  conn = PG::Connection.open(
    :host => ENV['DB_HOST'],
    :user => ENV['DB_USER'],
    :password => ENV['DB_PASS'],
  )
  res  = conn.exec('SELECT 1 AS a, 2 AS b, NULL AS c')

  puts res.to_json
end

This results in a proper connection and response when invoked. So I think this means its not a security group or a VPC issue, but rather something to do with a gemset or mismatch or some other funky thing. Nothing is written to the CloudWatch logs, just the start and timeout of the function.

I have a VPC with 3 public and 3 private subnets. The privates have the NAT and the public have the IG. The functions are in a SG and the RDS is in an SG and the RDS allows strict permissions to the function SG.

Any thoughts what could be happening here? It’s just a barebones application at this point. If I run jets server it runs just fine. I am running Ruby 2.5.5 maybe I should be on Jets’ 2.5.3 ? Can’t imagine that would be the issue with a minor update…


#2

For posterity and help others. According to @albanda , this turned out to be a VPC setup issue.