Ruby on rails application on AWS deployment -1

What if a new framework could be deployed with Heroku-like ease without giving up the versatility and cost-savings you get from a more general-purpose platform such as AWS? Using Elastic Beanstalk — an AWS operation, is possible.

In this article, I’m going to walk you through setting up a rails application and running it on AWS using Elastic beanstalk as the compute base and RDS (Relational Database Service)-the Postgres service in particular-as the data storage.

Set up an app with a few routes for Rails 6, and run it locally.

· Creating an account at AWS.

· Using the free-tier tools, set up and deploy an app to Elastic beanstalk.

What is Elastic beanstalk & RDS?

First, let ‘s talk about Amazon’s EC2 product, to get a better understanding of what Elastic beanstalk is and the problem it solves. Ruby on rails certification training helps you to learn more effectively.

EC2 stands for Elastic Cloud Computing 2. This service helps you to have VPCs, which are essentially just machines, running whatever operating system you want (e.g., Ubuntu). Your device will then reside within this machine and use its resources to perform its tasks, such as the file system and the RAM. Ultimately, the device would run close to how it operates on the local computer, using Amazon’s network only in a system owned by Amazon and available over the internet.

Imagine now a user named Alice, who supported an instance on EC2. Alice shall do as follows:

· Develop a security group that allows requests to be made to her device.

· Have a load balancer set up.

· SSH in the say, configure the secrets of its app and setting, etc.

While this gives you complete control over your computer and what and how it is running, sometimes you want to focus on the app and not on the infrastructure. Here comes Elastic beanstalk.

Elastic beanstalk offers a CLI that makes all of this easier to do and can automate much of it, such as building load balancers and security groups. While the underlying infrastructure is still EC2, a layer of abstraction is applied to it, with a visual dashboard that allows you to set up environment variables, databases, and auto-scaling, and to access logs and perform certain functions in a very simple way.

What are Rails?

A lot of software can be used to get and run a web rails application. Typically the library or system that you end up using is determined more by the language it is programmed in.

If your language of choice happens to be Ruby, Rails (officially called Ruby on Rails) is a common framework you may choose to use.

Building a modern web rails application.

To something as complex as Airbnb and Github, some of the items you can create with rails include something as basic as a personal blog. I ‘m sure these two companies are familiar to you, and yes, they ‘re running on Rails!

Although this article provides examples of how to deploy a Rails app to AWS, most of the key principles remain the same regardless of the language and framework used, including Python / Django or PHP / Laravel.

Installing rails application

Notice that the represented commands would operate out of the box on a UNIX / Linux based system. If you are on Windows, start using Linux and/or Microsoft Windows Terminal as a Windows Subsystem.

Rubies -v

All 2.5.0 and above are ready to go. If not, get the latest version here. I have already installed version 2.6.5.

If your Ruby installation looks okay, go ahead and install the Rails.

Installing rails in gem

Confirm your version of Rails once that command runs:

Create Postgres database for rails application

For this tutorial we will use Postgres DB as our data storage facility. Here’s a great guide to installing this on any device.

Add and Run Our Code for rails application

We ‘re going to build a simple API to store movie data, such as name, release year and genre. For example purposes the API will only have 2 endpoints, GET & POST.

Create a new Rails application with the command to:

RAILS — api — database = postgresql

If the above command is running successfully, make sure that the directory is updated to the project folder generated before executing the next commands.

To generate our model, we can then run the following command:

Rails generate model Movie name: string year: string genre

Now let’s create the database and execute migrations:

· Rails db: Installation

· Rails db: wander

If these two commands are efficient you should be able to see a new migration with code similar to the following in the db / migrate folder:

Class CreateMovies::Migration[6.0] < ActiveRecord:

Move to defect

Creating table: movies do the

String: name: name

T.integer:

String to: genre

T.Timbres

Ending

Ending

Ending

Then we will go ahead and add the logic code for our API endpoints to the controller:

Rails g Api / Movie Controller

Add the following code to the app / controllers / movies controller.rb file, then:

Class Api::Rails applicationController < MoviesController

# GET /Film

Showing defaults

@movies = film.all

Xml renderer: @movies

Ending

# Update / Message

Initial Setup

@movie = film.new(film params)

Where @movie.save

Render json: @Film

Many

Error render: {error: ‘Failed to add film record’}, status: 400

Ending

Ending

Private residence

Def film params

Params.require(:movie).permit(:name,:year,:genre) Permit

Ending

Ending

Let’s get the routes set. This code enters config / routes.rb.

If you want to Gain In-depth Knowledge on Ruby on Rails, please go through this link ruby on rails certification