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:
- Setup a new project
jets new temp-project --mode api --database postgres
- add
gem 'pg'
to the Gemfile - Update the
.env.production
with DB_HOST, DB_USER and DB_PASS for serverless db on aws - Configure proper
vpc_config
variables inapplication.rb
for a private subnet with NAT gateway - 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
- 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).
- 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…