I tried Jets (ruby serverless)

What are Jets?

It is a framework that can run ruby ​​serverlessly and code Rails-like. Both RDB and DynamoDB are supported as DB. (This time combined with RDS) => RDB uses ActiveRecord as the OR mapper, so I really played it like Rails https://rubyonjets.com/

background

I'm used to Rails, but I keep getting charged for EC2 and Fargate. .. => Feeling that I want to reduce the amount of money as much as possible in personal development

Try lambda x ruby ​​with Serverless Framework => lambda and RDS are not compatible, but I don't understand Dynamo well ... (I want to study hard for personal development: muscle :)

I wonder if Rails can be run serverless for a little personal development. .. .. .. Nice to meet you in two articles at that time The "Lambda-RDS" pattern isn't scary anymore! ?? Failover will be faster! RDS Proxy has been previewed! #reinvent I tried using Jets to create a Rails-like serverless application in Ruby

As for the actual usage of Jets, it's more Rails-like than I imagined, so I didn't stumble so much & there was no problem with the official or above article, so please try it there: bow:

-- I have summarized the recent trends that I was interested in regarding serverless, so please also check it out. Recent serverless circumstances that I personally care about

A simple stumbling block

It did not support ruby ​​2.7. .. .. ruby is 2.5 series

At first I was trying to make it with 2.7, but it is not yet supported for 2.7 series and I need to change to 2.5 series ... Since it is also an issue, I want to support while watching the situation https://github.com/boltops-tools/jets/issues/444

Every time region is asked

Every time I hit the jets command, I'm asked for the region ... w I wondered if something would work fine if I put something in the default of AWS_PROFILE (I specified AWS_PROFILE every time) There may be some workaround, but I didn't understand at a glance

$ jets server
Traceback (most recent call last):
...

/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/aws-sdk-core-3.110.0/lib/aws-sdk-core/plugins/regional_endpoint.rb:42:in `block in <class:RegionalEndpoint>': Invalid `:region` option was provided. (Aws::Errors::InvalidRegionError)

* Not every service is available in every region.

* Never suffix region names with availability zones.
  Use "us-east-1", not "us-east-1a"

Known AWS regions include (not specific to this service):

af-south-1
ap-east-1
ap-northeast-1
...

Connect your VPC to lambda to access the RDS in your VPC

Solved by specifying subnet and security_group according to this formula https://rubyonjets.com/docs/considerations/vpc/

Jets.application.configure do
  config.function.vpc_config = {
    security_group_ids: %w[sg-1 sg-2],
    subnet_ids: %w[subnet-1 subnet-2],
  }
end

Migration cannot flow to RDS in VPC ...

I couldn't find a silver bullet for this ..... If it is a public RDS, it can be applied locally with JETS_ENV_REMOTE = 1 jets db: migrate As one method, a reference link introduced how to prepare an Application Job and execute it. However, if you do it in a production environment, there is a lambda timeout, so it may be better to set it as an ECS Fargate task. Either way, there seems to be difficulty in operation in production.

reference) https://community.rubyonjets.com/t/how-do-i-migrate-the-database/22

How do I set up RDS Proxy?

Conclusion. It seems unnecessary lol

On AWS Lambda, there’s something called the Lambda Execution Context. The Lambda Execution Context gets reused between lambda function runs. Jets establishes the DB connection within the Lambda Execution Context outside the handler. So DB connections get reused between subsequent lambda function runs. This prevents DB connections from ever-increasing. The AWS docs specifically point out to use the Lambda Execution Context for things like establishing DB connections.

Quote: https://rubyonjets.com/docs/database/activerecord/

It seems that lambda has a shared space between executions called Lambda Execution Context (I heard: see_no_evil :), It seems that by holding a connection in the Lambda Execution Context inside Jets, the connection is reused between executions.

Jurisdiction

――I thought it was too early to use it in production ――I hope it will be one of the big options for adopting ruby ​​on lambda in the future! ――Since there are still few documents and articles, it took a long time to stumble (especially around VPC, I had to remake it a little bit).

Recommended Posts

I tried Jets (ruby serverless)
I tried DI with Ruby
I tried a calendar problem in Ruby
I started Ruby
I tried Spring.
I tried tomcat
I tried youtubeDataApi.
I tried to build Ruby 3.0.0 from source
I tried FizzBuzz.
I tried JHipster 5.1
I made blackjack with Ruby (I tried using minitest)
[Ruby basics] I tried to learn modules (Chapter 1)
[I tried] Spring tutorial
I tried running Autoware
I tried using Gson
I tried QUARKUS immediately
I tried using TestNG
I tried Spring Batch
I tried using Galasa
I tried node-jt400 (Programs)
I tried node-jt400 (execute)
I tried node-jt400 (Transactions)
I tried installing Ruby on Rails related plugin with vim-plug
I tried node-jt400 (Environment construction)
I tried node-jt400 (SQL Update)
Personal memo Progate Ruby I (2)
I tried using azure cloud-init
I tried Spring State machine
I tried Drools (Java, InputStream)
I tried Rails beginner [Chapter 1]
I tried the Docker tutorial!
I tried using Apache Wicket
I tried the VueJS tutorial!
I tried to summarize the basic grammar of Ruby briefly
I tried node-jt400 (SQL query)
I tried to automate LibreOffice Calc with Ruby + PyCall.rb (Ubuntu 18.04)
I tried using Java REPL
I tried source code analysis
I tried the FizzBuzz problem
I tried node-jt400 (SQL stream)
I tried node-jt400 (IFS read)
I tried putting XcodeGen + SwiftPM
I tried Rails beginner [Chapter 2]
I tried UPSERT with PostgreSQL.
Personal memo Progate Ruby I (1)
I tried BIND with Docker
I tried to verify yum-cron
Ruby on Jets Verification (WSL)
I don't understand Ruby 3 Ractor
ruby exercise memo I (puts)
I tried metaprogramming in Java
I tried to solve the problem of "multi-stage selection" with Ruby
I tried to write code like a type declaration in Ruby
[Ruby] Tonight, I tried to summarize the loop processing [times, break ...]
I tried to reimplement Ruby Float (arg, exception: true) with builtin
I tried deploying a Docker container on Lambda with Serverless Framework
I tried to make Numeron which is not good in Ruby
I tried using anakia + Jing now
I tried Angular tutorial + SpringBoot + PostgreSQL
Ruby: I made a FizzBuzz program!
I tried to chew C # (indexer)