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/
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
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 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
...
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
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
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.
――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