Ruby on rails application on AWS deployment -2

Snehacynixit
6 min readAug 31, 2020

Rails application routes.draw rails do

# See https:/guides.rubyonrails.org/routing.html for information about the DSL available within this package.

Nameplace: api does

resource: movies

Ending

Ending

You can perform a sanity check at this point using the command of rail routes to verify that everything is working properly. Output will contain something similar to the following: Routes

Lets add some seed data to db / seeds.rb before running our server:

# This file will contain all the record creation required to seed the default values for the database.

# The data can then be loaded with the Rails command db: seed (or generated with db: setup alongside the database. Ruby training helps you to learn more effectively.

Films = Movie.create]

{ Name: ‘Star Wars’ (1977), genre: ‘SCI-FI’},

{ Name: ‘Ring Lord,’ year: 2001, genre: ‘Fantasy’

])

To add the data to the Database run the following command:

Db: Seed rails

Now you can execute the API with the command:

Rams s

If you are navigating to http:/127.0.0.1:3000 / api / movies you should see our data on seeds:

“ID”: 1, “Edge”

“Appellation”: “Star Wars,”

“Year” for: 1977,

“Genre”: “FI-SCI,”

‘Created at’: ‘2020–01–01T10:04:56.100Z’,

“Actualized at”: “2020–01–01T10:04:56.100Z”

},

}

]

Build AWS Account for rails application

Go to this website for example.

If you have no account yet, or have not signed into one from your browser, you should see a similar page:

AWS Start Page for rails application

Go ahead and click the orange Creating an AWS Account button at the top-right corner (or sign in to your console if you have an account). You will be dropped right into the console once you have filled in the signup form (make sure to pick Account Type as Personal when you fill in your address. Ruby on Rails online course from industrial experts.

Do not forget to have your email address checked!

If things look confusing, don’t worry. When you know where you want to go, the UI is quite simple to navigate. Develop IAM Consumer

The next thing we need to do is install an IAM user. This will give us access to the API keys that we can use to access SSH and our services from outside of AWS.

It’s also a good idea to have a separate IAM user with access only to the resources that the user needs, rather than using the default admin credentials for protection.

Look for IAM on the home page, and switch to the IAM home page. Tap on Users on the IAM homepage, under IAM Resources: 0.

IAM Resources for rails application

Then click Add Account.

You should fill in the username of your choosing and then pick the Program Access. Programmatic Access checkbox

Select Add existing policies directly on the next page, and then check for AdministratorAccess. Administrator Access using the search box

Attach a name tag on the next tab, so you can later identify your user from the IAM credentials list: tags Finally , click on Build User on the Review page.

Using your credentials open the CSV file on the next page.

We are going to need them for the final part.

Once you have the file named credentials.csv, you can open it to see the values in it in any spreadsheet app or editor.

Most of the time, we are interested in access key ID and secret access key. The last thing you need to do is go to your Home folder and build a.aws folder.

Put a file called config inside this folder. Note that the name of the folder begins with a.

And that file doesn’t have an extension. The full path should be about /Users / your-user/.aws / config. If the.aws folder and config file can not be established, you can skip it for now. The important thing is to have the CSV file on hand for later use, with your credentials. Place these in the config file:

[Eb-cli profile]] Area = Us Eastern-1

aws access key id = your key-access-ide

aws secret access key = secret-access key for your-aws

When signing in, you can find your AWS region at the top right corner of the AWS account page.

Create DB on RDS for rails application

We’ll now go ahead and create the Postgres Server that will connect with our app. Similar to IAM, you can search for RDS and navigate to it using the search box on the homepage.

Click on Create database.rds on RDS homepage

On the next page, select Standard Create; then select PostgreSQL.DB Create under Engine Options

Select Free tier under Templates when you start scrolling, and let the DB instance identifier be movie-api under Settings. As postgres, you can leave the Master username but go ahead and add a password. DB Parameters

Skip the DB instance scale, Volume, and Disponibility & Durability parts. Select Additional Networking Configuration under Networking, and set Yes and VPC Protection Group Publicly accessible to Build New. Connecting.

Continue and skip authentication over Database. Be sure to add the Initial database name under Additional configuration; movie api db will do so. Save everything else once installed, and click Create Database at the bottom of the page.

Finally, back on the RDS dashboard, click in the right column on the default group under VPC Protection Groups:

Select Inbound and change the rules at the bottom of the next page to look as follows: Inbound rules

Also, make sure the rules of the Outbound Regulations look the following:

Build Elastic Beanstalk App for rails application

Navigate to the elastic beanstalk homepage, and press New Rails application Construct. Elastic beehive

If required fill in the new rails application form.

Then you’d see a message page No environments currently exist for that rails application. Now make more. Now press Build One.

Next, choose Web Server Env environment from env.

In the next part, change the name of the Environment into production-env. Leave the Property empty. Then, under Base Configuration, select Preconfigured board, and choose Ruby from dropdown. You can leave Rails application code on Sample rails application; then go ahead and choose Build environment. So be careful setup this will take some time. Basis

You will see a page like this after you have done so: Production Env

Find the supporting URL after the system ‘s Name. Click on it to view the default Ruby framework on elasticbeanstalk. Your API will run, very fast, on the same domain.

Ready to deploy the rails Application

We need to configure our web server first for the rails application to be ready for deployment.

Since Rails ships Puma, a production-ready web server, as their default server, the config file can be edited directly at config / puma.rb.

Edit your script, just to look like:

MAX Thread count = MAX THREADS RAILS {5}

Min thread count = ENV.fetch(“MIN THREADS RAILS)

Min threads count, full threads count

# Specifies the ‘channel’ on which Puma can listen to received requests; the default is 3000.

#

Net ENV.fetch(“PORT) “{3000}

# Determines the ‘environment’ for Puma to run inside.

#

{‘Development’} Env.fetch(‘RAILS ENV’)

# Specifies the pidfile that Puma will be using.

{‘tmp/pids/server.pid’} ENV.fetch(‘PIDFILE’)

# Defines the Clustered Workers number to boot from.

# Processes on forked web servers are the staff. Where threads and resources are used together,

# The expertise of the rails application shall be max ‘threads’ * ‘staff.’

# Workers does not function on Windows or JRuby (both don’t support Windows).

# Tests).

#

Staff ENV.fetch(‘WEB CONCURRENCY) ‘{2} # < — -Uncomment on this portion

# Take ‘App to Preload! ‘Method when deciding the number of people working.

# This directive tells Puma to initially boot the program and load code first

# A submission must be made before forking. This will exploit Copy On Writing

# Workflow actions so that employees use less memory.

#

App preload! # < — — — Convey this section

# Allow the ‘Rails restart’ command to reset Puma.

Plugin: tmp reboot

Also, change the config / database.yml bottom by commenting on and using the current production configuration instead:

Manufacture::

Url: <% = ENV [‘DATABASE URL’]% >…

Finally, go to your AWS Elasticbeanstalk console, pick the production-env environment and then go to Config.

Click Change for Program portion on the Configuration overview screen:

Configuration Summary for rails application

Then add DATABASE URL and RAILS ENV, and press ‘Apply’

Note that your Database URL is constructed from the RDS dashboard using the Endpoint you noted earlier. It’s in postgresql:/postgres format: YOURPASSWORD@ENDPOINT:5432 / movie api db; If you don’t remember the password you’ve chosen, you can change it at the RDS dashboard Adjust section of your DB.

Conclusion

I hope you reach to a conclusion about Ruby on rails deployment. You can learn more through Ruby on rails online training.

--

--