Demonstration of Launching Ec2 instance. - SeshuVarma/websys GitHub Wiki

To launch the EC2 instance

  • Choose an Amazon Machine Image (AMI), now find the Amazon Linux 2 AMI at the top of the list, and click Select.

  • Choose Instance Type t2.micro, and the next step is to Configure Instance Details.

  • To Configure the Instance Details, please provide the below information:

  • Click Next and Add Storage. Launch Ec2 instance using default 8 GiB disk volume.

  • Choose Next and Add Tags.

  • Choose Next and Configure Security Group.

  • Choose Review and Launch.

  • Choose Launch.

  • Create the new key pair and then choose the Launch Instances.

  • Now we are going to connect to an instance using the EC2 Instance Connect Go to the location where your Key Pair is saved, then open the terminal and type the below command:

chmod 400 photosite-raildocker.pem

ssh -i "photosite-raildocker.pem" [email protected]

Until this point the above steps are common whether we are using Docker or without Docker to import the rails application into EC2

With Docker

  • To install Docker on the EC2 Instance, run the below commands in the terminal. sudo yum update -y

sudo yum install docker -y

sudo service docker start

  • Run the Docker image using command:

sudo docker run -it -p 80:3000 rojabalakrishnan/photosite-railapp

Without Docker

1.Build environment on the EC2, so type the below commands in ssh terminal sudo yum update

import our code from git into EC2:

sudo yum install git

2.Install a Javascript runtime. Here I am using node.js

sudo yum install nodejs npm --enablerepo=epel 3. Configure with ruby & ruby on rails import public key in order to install rvm:

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

install rvm through curl:

\curl -L https://get.rvm.io | bash -s stable

Update your terminal to use rvm shortcut command:

source ~/.rvm/scripts/rvm

Check requirements before update to the newest version of ruby:

rvm requirements

4.Next install ruby:

rvm install ruby

5.The newly installed ruby should be made as our default:

rvm use ruby --default

6.Next update ruby gems to the latest version:

rvm rubygems current

7.Next install rails

gem install rails

8.Import the code into EC2.

9.At this point run the code on EC2 using GitHub instead of docker Make sure that the code is pushed to the GitHub. Or, we can use the following code directly.https://github.com/rojabalakrishnan/PhotoSite.git

In EC2 ssh terminal, and clone the code from that git repo.

git clone https://github.com/rojabalakrishnan/PhotoSite.git

10.Then navigate to the cloned folder:

cd PhotoSite

11.And install additional bundles for the rails:

bundle install

At this point migrate all the data:

rake db:migrate

Type the command to run the server on a particular port:

rails s -p 3000 -b 0.0.0.0