2

I am using serverless framework to create one of my ruby service as serverless.

My current infrastructure is using 'Ruby on rails' framework.

Now i need to configure the database in serverless.yml file. So Any help regarding to this will be appreciated.

Chitra
  • 1,294
  • 2
  • 13
  • 28

2 Answers2

3

For now serverless framework doesn't support Heroku Postgres Database to be configured

If you want to connect to Heroku Postgres Database from lambda the solution is described here https://mattwelke.com/2019/01/06/free-tier-managed-sql-with-aws-lambda-and-heroku-postgres.html

The example is here

Also you can try to use Amazon Aurora Serverless with PostgreSQL (right now it is in a preview) And you will be able to set up Amazon Aurora Serverless configuration in serverless.yml in the resources section

iokhotnikov
  • 176
  • 1
  • 8
  • i have gone through with these links but i am not finding any solution for ruby. My application is already running on heroku so i can't go on any other DB service. – Chitra Feb 20 '19 at 09:27
  • 2
    @Chitra I'm the author of that blog post connecting Lambda to Heroku Postgres. The techniques there should work fine for any programming language. You just need to set up a connection pool and make sure you include the webhook to keep the credentials up to date. Since making that post I've also discovered the managed PostgreSQL service Elephant SQL. They're actually easier to use with Lambda since they don't automatically rotate credentials. If you end up taking a stab at making a Ruby Lambda app check out this tutorial for Ruby (https://serverless.com/blog/api-ruby-serverless-framework/). – Matt Welke Mar 09 '19 at 18:27
  • @Welkie, I truly appreciate your work around connecting Lambda to Heroku Postgres. Thanks for the blog which you have created. During my db connection setup I was having trouble regarding installation of native extension of 'pg' gem in AWS lambda environment. That has been resolved now. – Chitra Mar 11 '19 at 03:25
  • 1
    Glad you got it sorted out! I recommend making a blog post about putting that together because you'd be surprised how hard it can be to find answers to the problems we encounter when we mix services together like this. I for one would have no idea how to solve issues with Ruby gem extensions on Lambda. If you don't have your own blog right now, you could post that on Medium instead. – Matt Welke Mar 11 '19 at 17:26
0

Here I am posting the answer of my question.

I am using 'pg' and 'activerecord' gem.

by using this - ActiveRecord::Base.establish_connection(your_heroku_database_url) I am able to connect my heroku database.

Chitra
  • 1,294
  • 2
  • 13
  • 28