SlideShare a Scribd company logo
1 of 21
Rob Linton
 Jasondb – a cloud based,                                                    CTO & Founder
 scalable NoSQL database                                                     www.jasondb.com
 for social and mobile
 applications.                                                               Phone:    [AUS] + 61 418 510 155
                                                                             Email:     robl@jasondb.com




                                                                                   2
                    Migrating from Heroku to
                        Amazon AWS using
                             CloudFormation

In guide number one we looked at how we migrated Amazon EBS backed AMI’s
between AWS Regions using the tools that already exist on a standard Unix AMI.
(Available on slideshare.net at http://www.slideshare.net/pleasebiteme/presentation-
migrating-aws-ebs-backed-amis-between-regions-9465619)


In this guide we look at migrating a Ruby on Rails application to Amazon AWS.
This guide, while focussed on Ruby on Rails, can be used as a generic introduction on
setting up any application in the Amazon AWS stack.
This guide was presented at the Australian AWS Users Group in Melbourne on the
26thOctober, 2011.


A brief summary of Heroku
Heroku is commonly referred to as a Platform as a Service (PaaS) provider, in that they
offer more than just infrastructure services. Heroku offer a turnkey solution for hosting,
originally, Ruby on Rails (RoR) applications, although they now offer other languages
such as Node.js, Clojure, Java, Python and Scala.
Heroku’s success lies in the fact that as a Ruby on Rails developer, you could focus on
your application and leave everything else such as the hosting and scaling up to someone
else. Having done a substantial amount of development over the years (although not in
RoR), I can attest to the attraction of any services that eases the deployment of your
application.
Why migrate from Heroku?
There may be a number of reasons why you may want to migrate from Heroku. While
Heroku is great in the way it takes the load of managing the deployment and scaling away
from you, there are always compromises.
In this case Heroku, while reducing the complexity, also reduces the flexibility.
There are just some things that you cannot do in Heroku. Also as your application starts
to gain momentum, it is usually cheaper to host your application on AWS as the number
of users increase.


The usual steps for deploying to Heroku
The usual steps for deploying to Heroku are as follows:



Install the required software

    1.   Install Ruby on Rails
    2.   Install Git
    3.   Create an Heroku account
    4.   Install the Heroku Gem

    $ gem install heroku


Create your hello world application:

$ rails hello
$ cd hello
$ rails generate controller hello
Open the file config/routes.rb. Almost at the bottom (line #57) is this line:
# match ':controller(/:action(/:id(.:format)))'
Remove the # in front so the line looks like:
match ':controller(/:action(/:id(.:format)))'
Create a file named index.html.erb in app/views/hello containing the text ‘Hello world’.
Start the server.
2
$ rails server


Use Git to manage your project:

$ cd PATH/TO/MY_APP
$ gitinit Initialized empty Git repository in .git/
$ git add .
$ git commit -m "new app"


Create a ssh key pair:

$ cd ~/.ssh
$ mkdirkey_backup
$ cpid_rsa* key_backup
$ rmid_rsa*
$ ssh-keygen -t rsa -C "your_email@youremail.com"



Open the id_rsa.pub file with a text editor and cut & paste into your account settings on
the Heroku web site.

Configure Git

$ gitconfig --global user.name "FirstnameLastname"
$ gitconfig --global user.email "your_email@youremail.com"




Create your Heroku application

$ heroku create


Upload your application to Heroku

$ git push heroku master



                                                                                            3
Set up your application database

$ heroku rake db:migrate




Setting up the Amazon AWS Environment
Before we begin, let’s make sure we have the pre-requisites in place.
Make sure you have created an AWS account and have enabled access to the following
products:
    1. Elastic Compute Cloud (EC2)
    2. Relational Database Service (RDS)
    3. Elastic Load Balancing (ELB)
    4. CloudWatch
    5. CloudFormation
    6. Simple Notification Service (SNS)



    Also before you start make sure you have created a key/pair and download the
    private key to a safe place on your local computer.



Architecture overview
Here is asimple overview of the architecture for the rails application on AWS.




4
Overview architecture of the rails application
As you can see from the diagram above, the layout is relatively simple.
The load balancer will have two rails servers, which in turn will use aRelational
Database Instance (RDS) to store its data.


Step by step
Now let’s put the pieces in place.
To create the application stack we are going to use AWS CloudFormation.
CloudFormation is a great way to speed up the creation of commonly used application
stacks such as Ruby on Rails applications, Wordpress sites and even Drupal CMS sites.




                                                                                        5
Create a new stack
Click on the Create New Stack button, this will pop up the Create Stack dialog.




                               Create stack dialog
Give your application a name (Hello World) and select the sample template of Rails Hello
World Application (SSH enabled).
At the bottom of the dialog, expand the Show Advanced Options. This exposes some
extra options that you can select such as setting a time out on the creation or adding a
Simple Notification Service (SNS) topic.
6
For this example we will be adding a SNS topic that notifications can be sent to.
This next dialog looks pretty daunting, but is effect just asking for some standard bits of
information such as user names and passwords.




                              Create stack options
I recommend that you change the rails database password, the rails database user and the
operator email address.

    Make sure you scroll down and get the last option to enter a key pair name, as
    this is hidden at the bottom of the dialog.

Enter the key pair name you created earlier.
Once you have entered these pieces of information click on Continue.
The final dialog shows a summary of the parameters that will be used to create the Ruby
on Rails stack.



                                                                                              7
Create stack summary screen
This is the last point where you can cancel the create stack. By clicking on the Create
Stack button, amazon will go ahead and create an Auto Scaled sample Ruby application,
backed by an Amazon RDS instance.

    Note the Notification section at the bottom, at this point the SNS notification will
    have already have been created and you should have received an email similar to
    the one below.




8
SNS notification
Clicking on the link should display the following message.




                                     Confirmed
During the Ruby on Rails stack creation, the following dialog will be displayed.




                                                                                   9
Creating stack
During the creation process you will receive a number of email notifications via the SNS
service.




                               Email notifications
After your rails stack has been completed, the status will change to
CREATE_COMPLETE.




10
Resources created
Selecting the Resources tab will show you all of the resources that the CloudFormation
stack created for you. Because it is important that you understand what actually
happened, I’ll take you through each of the resources created.
Here is an overview diagram of what was created above:




                                                                                         11
CloudFormation stack after creation

EC2SecurityGroup
This is the AWS security Group used to restrict access to your rails hosts. For AWS,
security groups work on individual servers, so for example, A single EC2 instance
created as part of the CloudFormation stack can only be accessed via port 8888, or port
22 (ssh), even if the source of the access was a second EC2 instance in the same group.

ElasticLoadBalancer
The ELB accepts traffic in on port 80 and redirects it out on port 8888 to each of the
running rails servers. Note how it changes the port number to ensure that each of the rails
servers are not accessible on port 80.
12
Note however, that if you knew the direct address of one of the EC2 instances,
    this does not prevent you from connecting to the instance directly by using the
    following syntax in your browser.
    http://ec2-107-20-81-60.compute-1.amazonaws.com:8888/



DBSecurityGroup
The database security group restricts access to the RDS instance by only allowing EC2
instances that are members of a specific EC2 security group to connect. In this case only
members of the Rails security group can connect to RDS.

SampleDatabase
This is the RDS MySQL instance that was created for you. By default a db.m1.small
instance was created.
Also by default a Multi AZ RDS deployment was done. Selecting a Multi AZ
deployment allows a hidden replica to be created in a different availability zone, allowing
for fail-over of your RDS instance if one availability zone goes down.

AlarmTopic
This is the Simple Notification Service (SNS) that was created as part of the stack
creation. As part of the creation process I received 22 notifications in the space of around
30 minutes, so I would recommend that you create a mail rule to move these off to their
own folder in your mail program.

TooManyUnhealthHostsAlarm
You can see the details for this alarm by clicking on it in the CloudWatch tab.




                                                                                          13
Alarm details
As you can see from the highlighted section above, this alarm will trigger if the number
of unhealthy hosts > 0 for 1 minute.
The action for this alarm is to send a notification to the SNS service that we set up earlier.

RequestLatencyAlarmHigh
This is the second alarm. This alarm will trigger if the latency is greater than 1 second
from the ELB to a Rails instance for longer than 1 minute. If this alarm triggers a SNS
notification will be sent.

LaunchConfig
This is a component of the Auto Scaling. The launch configuration defines the type of
instances that will be started as well as what AMI to launch. This has been taken care of
for you so you will not need to edit this unless you would like to upgrade to a larger
instance type or if you would like to use a ‘Golden Image AMI’(We see later on how to
use Golden Images)

WebServerGroup
The Web Server Group defines which availability zones to start any new instances in as
well as the maximum and minimum instance numbers. The default configuration for the
14
web server group that was set up is a minimum of 1 with a maximum of 3. Unfortunately
this is not visible in the Web GUI, other than by reading the template. The following
section of the template shows the WebServerGroup details.
   "WebServerGroup": {
      "Properties": {
        "LoadBalancerNames": [
          {
            "Ref": "ElasticLoadBalancer"
          }
        ],
"MinSize": "1",
        "LaunchConfigurationName": {
          "Ref": "LaunchConfig"
        },
        "AvailabilityZones": [
          {
            "Fn::Join": [
              "",
              [
                {
                   "Ref": "AWS::Region"
                },
                "a"
              ]
            ]
          }
        ],
"MaxSize": "3"
      }


CPUAlarmHigh
This is the third alarm and will send a notification to SNS if the average CPU of any
instance in the WebServerGroup is great than 10% for more than one minute.


Overview of what was implemented by the stack
    So the overview of what was implemented by the stack in simple English is as
    follows:
        The stack consists of an Elastic Load Balancer (ELB) which accepts
        connections on port 80 and distributes them to the WebServerGroup on port
        8888.
        The WebServerGroup is an Auto Scaling Group defined as having a
        minimum of 1 server and a maximum of 3.




                                                                                        15
The Auto Scaling Group however does not automatically respond to alarms as no
     Auto Scaling Policies have been put in place by the stack. So to scale the group
     up and down you will need to do this manually.

         The EC2 instances in the WebServerGroup are protected by a Security
         Group restricting access to port 8888 and port 22 (ssh) from any source
         IP.The database instance created was a MySQL instance with Multi AZ fail-
         over enabled. Also by default the backup retention period has been set to one
         day.
         The servers in the WebServerGroup all have Ruby on Rails installed and
         already running, however, your application will not already be installed on
         any of them.



Configuring your application
Now that you have configured the infrastructure for your Ruby on Rails stack, we need to
be able to do two more things.
     Install our application.
     Scale up and scale down our Rails servers.



Installing your application
One of the interesting dilemmas when using products like CloudFormation is the one of
how to install your application on new EC2 instances that are created in response to
scaling events.
There are a number of ways to configure and scale your applications in your new stack
and there is a great article that should be used as a guide (although quite a long read).
https://s3.amazonaws.com/cloudformation-
examples/BoostrappingApplicationsWithAWSCloudFormation.pdf
In reality AWS doesn’t provide the tools required to complete the last mile, however the
easiest way is to create a ‘Golden Image’ AMI which is used by CloudFormation when
starting new instances.

     A Golden Image is a master AMI which already has your application installed
     and configured on it.


16
There is a trick to this, and the main one is enabling ssh access to your default Rails EC2
instance as part of the stack install. (which is why we chose this option at the beginning
of this guide) The steps are actually pretty straight forward.

Configure your rails instance
1. Using scp, copy your rails application to the new rails EC2 instance using the
   same private key you specified when starting it up.
   (If you don’t know where to copy it to, copy it to ~/my-rails-app initially)
2. Log into the new rails EC2 instance using the private/public key pair you
   specified when configuring the stack using ssh.
3. Stop the rails server.
4. Move the existing directory ~/hwrails to ~/hwrails.orig
5. Rename your new application directory to ~/hwrails
6. As part of the install you will need to edit the database.yaml file to configure
   access to the new RDS instance that was created for you.
7. Restart the rails server.


Create an Image
Once you have configured your server with your application, and tested it, you will need
to create an AMI Image from it. This is quite straight forward, just locate the instance in
the EC2 window, right click and select Create Image (EBS AMI).
This will create a new AMI for you to use as the new base AMI in the CloudFormation
template.

Edit the CloudFormation Template
Once the new AMI has been created, cut and paste the template file to a local file on your
computer. Open it up in Notepad or Textedit and edit the following section:
     "AWSRegionArch2AMI" : {
         "us-east-1" : { "32" : "ami-d411e2bd", "64" : "ami-da11e2b3" },
         "us-west-1" : { "32" : "ami-e7c797a2", "64" : "ami-e5c797a0" },
         "eu-west-1" : { "32" : "ami-17c2f663", "64" : "ami-13c2f667" },
         "ap-southeast-1" : { "32" : "ami-1af28c48", "64" : "ami-1ef28c4c"},
         "ap-northeast-1" : { "32" : "ami-b403a8b5", "64" : "ami-b803a8b9" }
     }
Replace the highlighted bit in yellow with the name of your new AMI. The yellow piece
represents a 32 bit instance running in us-east-1. (The default)
                                                                                          17
Update the CloudFormation Stack
Once you have your new template ready to go, you will need to edit the existing
CloudFormation stack.
To do this highlight the CloudFormation and click on the Update Stack in the toolbar, the
following dialog will be presented.




                                   Update stack
Select the Upload a Template File option and upload the edited template.
Then just click Continue through all of the next dialogs and accept the answers that you
provided previously.
You may not notice any changes at this point, and in fact there are no changes. The
easiest way to see if your changes work is to terminate your existing EC2 instance!
Don’t panic though, because it is part of an Auto Scaling Group, AWS will automatically
restart a new instance based on your new AMI.

     There is a bug in the current CloudFormation where it does not update the
     Launch Config to the new AMI unless the instance type is changed in the
     configuration screen.



18
So you will need to upload the template file twice. The first time change the
    instance type to m1.large, then the second time change it back to m1.small.

Give AWS a few minutes to detect that the group is below its minimum threshold, then
look at the new instance in the EC2 tab. Take a look at the AMI-ID and confirm that it is
indeed the new AMI that you added to the template file.

    Another way to do this would have been to install the Auto Scaling command
    line tools and use the following commands to edit the Launch Config:
    as-delete-launch-config

    as-create-launch-config



Adding more servers to the Autoscaling Group
Now that we have installed our application, it would be nice to be able to add more
servers to our Auto Scaling Group if the number of users connecting increases.
Unfortunately there is currently no way to do this from the Web GUI, the only way to
modify the autoscaling group is to either use the command line tools or modify the
existing template.
For this example I’m going to modify the template using the same process that I used in
the previous section and increase the minimum number of servers in my Auto Scaling
Group to two.

Edit the template file
Find the WebServerGroup section in the template file and edit the highlighted section.
   "WebServerGroup": {
      "Properties": {
        "LoadBalancerNames": [
          {
            "Ref": "ElasticLoadBalancer"
          }
        ],
"MinSize": "1",
        "LaunchConfigurationName": {
          "Ref": "LaunchConfig"
        },
        "AvailabilityZones": [
          {
            "Fn::Join": [
              "",
              [
                {
                  "Ref": "AWS::Region"
                                                                                          19
},
                       "a"
                   ]
               ]
          }
        ],
"MaxSize": "3"
      }
Change the MinSize from 1 to 2 and once again update the stack with the new template
as in the previous example.

     This time the changes will take affect without needing to change any other
     parameters.

Take another look at the EC2 instance tab and you will see that the changes have worked
almost straight away. There should now be two instances of your rails application
running.
It has automagically been added to the Elastic Load Balancer, the correct security groups
and will start taking traffic almost straight away. (As soon as the ELB puts it in service,
which by default is around 20 seconds)


That’s it!


For a step by step guide on implementing automatic Auto Scaling based on CPU load,
please take a look at chapter 9 of my book:
Amazon Web Services: Migrating your .NET Enterprise Application.
http://www.amazon.com/Amazon-Web-Services-Enterprise-Application/dp/1849681945




Summary
In this guide we looked at how to migrate a Heroku Ruby on Rails application to AWS.
We looked at setting up an application stack using CloudFormation and how to install
and configure your stack after it creation.




20
21

More Related Content

What's hot

Cloud-native .NET-Microservices mit Kubernetes @BASTAcon
Cloud-native .NET-Microservices mit Kubernetes @BASTAconCloud-native .NET-Microservices mit Kubernetes @BASTAcon
Cloud-native .NET-Microservices mit Kubernetes @BASTAconMario-Leander Reimer
 
Install oracle siebel on windows 2008 r2
Install oracle siebel on windows 2008 r2Install oracle siebel on windows 2008 r2
Install oracle siebel on windows 2008 r2Osama Mustafa
 
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...Geir Høydalsvik
 
How to build a Citrix infrastructure on AWS
How to build a Citrix infrastructure on AWSHow to build a Citrix infrastructure on AWS
How to build a Citrix infrastructure on AWSDenis Gundarev
 
Ansible with oci
Ansible with ociAnsible with oci
Ansible with ociDonghuKIM2
 
Cloud stack vs openstack vs eucalyptus
Cloud stack vs openstack vs eucalyptusCloud stack vs openstack vs eucalyptus
Cloud stack vs openstack vs eucalyptusAshok Kumar
 
Troubleshooting Strategies for CloudStack Installations by Kirk Kosinski
Troubleshooting Strategies for CloudStack Installations by Kirk Kosinski Troubleshooting Strategies for CloudStack Installations by Kirk Kosinski
Troubleshooting Strategies for CloudStack Installations by Kirk Kosinski buildacloud
 
Cloud orchestration major tools comparision
Cloud orchestration major tools comparisionCloud orchestration major tools comparision
Cloud orchestration major tools comparisionRavi Kiran
 
MySQL Replication Performance in the Cloud
MySQL Replication Performance in the CloudMySQL Replication Performance in the Cloud
MySQL Replication Performance in the CloudVitor Oliveira
 
How to create a secured cloudera cluster
How to create a secured cloudera clusterHow to create a secured cloudera cluster
How to create a secured cloudera clusterTiago Simões
 
DEVNET-1119 UCS PowerTool Secrets - Tips and Tricks
DEVNET-1119	UCS PowerTool Secrets - Tips and TricksDEVNET-1119	UCS PowerTool Secrets - Tips and Tricks
DEVNET-1119 UCS PowerTool Secrets - Tips and TricksCisco DevNet
 
Weblogic 101 for dba
Weblogic  101 for dbaWeblogic  101 for dba
Weblogic 101 for dbaOsama Mustafa
 
How to configure amazon ec2 load balancer
How to configure amazon ec2 load balancerHow to configure amazon ec2 load balancer
How to configure amazon ec2 load balancerVCP Muthukrishna
 
Global Azure Bootcamp 2017 - Why I love S2D for MSSQL on Azure
Global Azure Bootcamp 2017 - Why I love S2D for MSSQL on AzureGlobal Azure Bootcamp 2017 - Why I love S2D for MSSQL on Azure
Global Azure Bootcamp 2017 - Why I love S2D for MSSQL on AzureKarim Vaes
 
Cloudera cluster setup and configuration
Cloudera cluster setup and configurationCloudera cluster setup and configuration
Cloudera cluster setup and configurationSudheer Kondla
 
MySQL Group Replication - Ready For Production? (2018-04)
MySQL Group Replication - Ready For Production? (2018-04)MySQL Group Replication - Ready For Production? (2018-04)
MySQL Group Replication - Ready For Production? (2018-04)Kenny Gryp
 

What's hot (20)

Cloud-native .NET-Microservices mit Kubernetes @BASTAcon
Cloud-native .NET-Microservices mit Kubernetes @BASTAconCloud-native .NET-Microservices mit Kubernetes @BASTAcon
Cloud-native .NET-Microservices mit Kubernetes @BASTAcon
 
Install oracle siebel on windows 2008 r2
Install oracle siebel on windows 2008 r2Install oracle siebel on windows 2008 r2
Install oracle siebel on windows 2008 r2
 
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
 
How to build a Citrix infrastructure on AWS
How to build a Citrix infrastructure on AWSHow to build a Citrix infrastructure on AWS
How to build a Citrix infrastructure on AWS
 
12c on RHEL7
12c on RHEL712c on RHEL7
12c on RHEL7
 
Ansible with oci
Ansible with ociAnsible with oci
Ansible with oci
 
Cloud stack vs openstack vs eucalyptus
Cloud stack vs openstack vs eucalyptusCloud stack vs openstack vs eucalyptus
Cloud stack vs openstack vs eucalyptus
 
Troubleshooting Strategies for CloudStack Installations by Kirk Kosinski
Troubleshooting Strategies for CloudStack Installations by Kirk Kosinski Troubleshooting Strategies for CloudStack Installations by Kirk Kosinski
Troubleshooting Strategies for CloudStack Installations by Kirk Kosinski
 
Cloud orchestration major tools comparision
Cloud orchestration major tools comparisionCloud orchestration major tools comparision
Cloud orchestration major tools comparision
 
MySQL Replication Performance in the Cloud
MySQL Replication Performance in the CloudMySQL Replication Performance in the Cloud
MySQL Replication Performance in the Cloud
 
How to create a secured cloudera cluster
How to create a secured cloudera clusterHow to create a secured cloudera cluster
How to create a secured cloudera cluster
 
Oam install & config
Oam install & configOam install & config
Oam install & config
 
Pixels_Camp
Pixels_CampPixels_Camp
Pixels_Camp
 
DEVNET-1119 UCS PowerTool Secrets - Tips and Tricks
DEVNET-1119	UCS PowerTool Secrets - Tips and TricksDEVNET-1119	UCS PowerTool Secrets - Tips and Tricks
DEVNET-1119 UCS PowerTool Secrets - Tips and Tricks
 
OID Install and Config
OID Install and ConfigOID Install and Config
OID Install and Config
 
Weblogic 101 for dba
Weblogic  101 for dbaWeblogic  101 for dba
Weblogic 101 for dba
 
How to configure amazon ec2 load balancer
How to configure amazon ec2 load balancerHow to configure amazon ec2 load balancer
How to configure amazon ec2 load balancer
 
Global Azure Bootcamp 2017 - Why I love S2D for MSSQL on Azure
Global Azure Bootcamp 2017 - Why I love S2D for MSSQL on AzureGlobal Azure Bootcamp 2017 - Why I love S2D for MSSQL on Azure
Global Azure Bootcamp 2017 - Why I love S2D for MSSQL on Azure
 
Cloudera cluster setup and configuration
Cloudera cluster setup and configurationCloudera cluster setup and configuration
Cloudera cluster setup and configuration
 
MySQL Group Replication - Ready For Production? (2018-04)
MySQL Group Replication - Ready For Production? (2018-04)MySQL Group Replication - Ready For Production? (2018-04)
MySQL Group Replication - Ready For Production? (2018-04)
 

Viewers also liked

Creating a Comprehensive Social Media App Using Ionic and Phone Gap
Creating a Comprehensive Social Media App Using Ionic and Phone GapCreating a Comprehensive Social Media App Using Ionic and Phone Gap
Creating a Comprehensive Social Media App Using Ionic and Phone GapFITC
 
Alex robles and devon cotell
Alex robles and devon cotellAlex robles and devon cotell
Alex robles and devon cotellalexcrobles
 
Estamos en la etapa en que debemos disfrutar
Estamos en la etapa en que debemos disfrutarEstamos en la etapa en que debemos disfrutar
Estamos en la etapa en que debemos disfrutaranbeltran
 
Nodejs Intro - Part2 Introduction to Web Applications
Nodejs Intro - Part2 Introduction to Web ApplicationsNodejs Intro - Part2 Introduction to Web Applications
Nodejs Intro - Part2 Introduction to Web ApplicationsBudh Ram Gurung
 
Business Intelligence
Business IntelligenceBusiness Intelligence
Business Intelligencelukic83
 
4. Общая экономика 2017. Деньги, или обращение товаров. /General Economics 20...
4. Общая экономика 2017. Деньги, или обращение товаров. /General Economics 20...4. Общая экономика 2017. Деньги, или обращение товаров. /General Economics 20...
4. Общая экономика 2017. Деньги, или обращение товаров. /General Economics 20...Moscow State University
 
Peace laws
Peace lawsPeace laws
Peace lawssnash23
 
Introduction to Netention
Introduction to NetentionIntroduction to Netention
Introduction to NetentionHelene Finidori
 
презентация паркета
презентация паркетапрезентация паркета
презентация паркетаAndreykireenkov
 
صوموا تصحوا
صوموا تصحواصوموا تصحوا
صوموا تصحواMonir Lotfy
 
You Want to Work at a Start Up?
You Want to Work at a Start Up?You Want to Work at a Start Up?
You Want to Work at a Start Up?Jordan Ridge LLC
 

Viewers also liked (20)

From Heroku to Amazon AWS
From Heroku to Amazon AWSFrom Heroku to Amazon AWS
From Heroku to Amazon AWS
 
Creating a Comprehensive Social Media App Using Ionic and Phone Gap
Creating a Comprehensive Social Media App Using Ionic and Phone GapCreating a Comprehensive Social Media App Using Ionic and Phone Gap
Creating a Comprehensive Social Media App Using Ionic and Phone Gap
 
Alex robles and devon cotell
Alex robles and devon cotellAlex robles and devon cotell
Alex robles and devon cotell
 
Estamos en la etapa en que debemos disfrutar
Estamos en la etapa en que debemos disfrutarEstamos en la etapa en que debemos disfrutar
Estamos en la etapa en que debemos disfrutar
 
Nodejs Intro - Part2 Introduction to Web Applications
Nodejs Intro - Part2 Introduction to Web ApplicationsNodejs Intro - Part2 Introduction to Web Applications
Nodejs Intro - Part2 Introduction to Web Applications
 
Locks of love
Locks of loveLocks of love
Locks of love
 
Business Intelligence
Business IntelligenceBusiness Intelligence
Business Intelligence
 
4. Общая экономика 2017. Деньги, или обращение товаров. /General Economics 20...
4. Общая экономика 2017. Деньги, или обращение товаров. /General Economics 20...4. Общая экономика 2017. Деньги, или обращение товаров. /General Economics 20...
4. Общая экономика 2017. Деньги, или обращение товаров. /General Economics 20...
 
Peace laws
Peace lawsPeace laws
Peace laws
 
Spc
SpcSpc
Spc
 
2011 CMA Compensation Survey
2011 CMA Compensation Survey2011 CMA Compensation Survey
2011 CMA Compensation Survey
 
Introduction to Netention
Introduction to NetentionIntroduction to Netention
Introduction to Netention
 
Trabajo del examen
Trabajo del examenTrabajo del examen
Trabajo del examen
 
презентация паркета
презентация паркетапрезентация паркета
презентация паркета
 
صوموا تصحوا
صوموا تصحواصوموا تصحوا
صوموا تصحوا
 
Spectaculaire fotos
Spectaculaire fotosSpectaculaire fotos
Spectaculaire fotos
 
Jaipur media
Jaipur mediaJaipur media
Jaipur media
 
Algypug case study
Algypug case studyAlgypug case study
Algypug case study
 
You Want to Work at a Start Up?
You Want to Work at a Start Up?You Want to Work at a Start Up?
You Want to Work at a Start Up?
 
Slide fem 2d-20131029_6
Slide fem 2d-20131029_6Slide fem 2d-20131029_6
Slide fem 2d-20131029_6
 

Similar to Guide - Migrating from Heroku to AWS using CloudFormation

The Future is Now: Leveraging the Cloud with Ruby
The Future is Now: Leveraging the Cloud with RubyThe Future is Now: Leveraging the Cloud with Ruby
The Future is Now: Leveraging the Cloud with RubyRobert Dempsey
 
Programming Infrastructure with AWS CDK
Programming Infrastructure with AWS CDKProgramming Infrastructure with AWS CDK
Programming Infrastructure with AWS CDKDonnie Prakoso
 
Scaling drupal horizontally and in cloud
Scaling drupal horizontally and in cloudScaling drupal horizontally and in cloud
Scaling drupal horizontally and in cloudVladimir Ilic
 
Aws interview questions and answers
Aws interview questions and answersAws interview questions and answers
Aws interview questions and answerskavinilavuG
 
Application Deployment on AWS - Startup Talks June 2015
Application Deployment on AWS - Startup Talks June 2015Application Deployment on AWS - Startup Talks June 2015
Application Deployment on AWS - Startup Talks June 2015Amazon Web Services
 
Architecting Cloud Apps
Architecting Cloud AppsArchitecting Cloud Apps
Architecting Cloud Appsjineshvaria
 
Viridians on Rails
Viridians on RailsViridians on Rails
Viridians on RailsViridians
 
McrUmbMeetup 22 May 14: Umbraco and Amazon
McrUmbMeetup 22 May 14: Umbraco and AmazonMcrUmbMeetup 22 May 14: Umbraco and Amazon
McrUmbMeetup 22 May 14: Umbraco and AmazonDan Lister
 
AWS Interview Questions and Answers -CREDO SYSTEMZ.pdf
AWS Interview Questions and Answers -CREDO SYSTEMZ.pdfAWS Interview Questions and Answers -CREDO SYSTEMZ.pdf
AWS Interview Questions and Answers -CREDO SYSTEMZ.pdfnishajeni1
 
NWCloud Cloud Track - Best Practices for Architecting in the Cloud
NWCloud Cloud Track - Best Practices for Architecting in the CloudNWCloud Cloud Track - Best Practices for Architecting in the Cloud
NWCloud Cloud Track - Best Practices for Architecting in the Cloudnwcloud
 
AWS CodeDeploy
AWS CodeDeploy AWS CodeDeploy
AWS CodeDeploy Ratan Das
 
Current state of affairs cloud computing
Current state of affairs   cloud computingCurrent state of affairs   cloud computing
Current state of affairs cloud computingChirag Jog
 
A Step By Step Guide To Put DB2 On Amazon Cloud
A Step By Step Guide To Put DB2 On Amazon CloudA Step By Step Guide To Put DB2 On Amazon Cloud
A Step By Step Guide To Put DB2 On Amazon CloudDeepak Rao
 
Cloud State of the Union for Java Developers
Cloud State of the Union for Java DevelopersCloud State of the Union for Java Developers
Cloud State of the Union for Java DevelopersBurr Sutter
 
Why we chose mongodb for guardian.co.uk
Why we chose mongodb for guardian.co.ukWhy we chose mongodb for guardian.co.uk
Why we chose mongodb for guardian.co.ukGraham Tackley
 
Rails
RailsRails
RailsSHC
 
What is AWS and What can you do with it | by Kunal Yadav | Noteworthy - The J...
What is AWS and What can you do with it | by Kunal Yadav | Noteworthy - The J...What is AWS and What can you do with it | by Kunal Yadav | Noteworthy - The J...
What is AWS and What can you do with it | by Kunal Yadav | Noteworthy - The J...AmitKuraria2
 

Similar to Guide - Migrating from Heroku to AWS using CloudFormation (20)

The Future is Now: Leveraging the Cloud with Ruby
The Future is Now: Leveraging the Cloud with RubyThe Future is Now: Leveraging the Cloud with Ruby
The Future is Now: Leveraging the Cloud with Ruby
 
Programming Infrastructure with AWS CDK
Programming Infrastructure with AWS CDKProgramming Infrastructure with AWS CDK
Programming Infrastructure with AWS CDK
 
Scaling drupal horizontally and in cloud
Scaling drupal horizontally and in cloudScaling drupal horizontally and in cloud
Scaling drupal horizontally and in cloud
 
Ruby On Rails Starter Kit
Ruby On Rails Starter KitRuby On Rails Starter Kit
Ruby On Rails Starter Kit
 
Aws interview questions and answers
Aws interview questions and answersAws interview questions and answers
Aws interview questions and answers
 
Application Deployment on AWS - Startup Talks June 2015
Application Deployment on AWS - Startup Talks June 2015Application Deployment on AWS - Startup Talks June 2015
Application Deployment on AWS - Startup Talks June 2015
 
ragi_tutorial_v1
ragi_tutorial_v1ragi_tutorial_v1
ragi_tutorial_v1
 
ragi_tutorial_v1
ragi_tutorial_v1ragi_tutorial_v1
ragi_tutorial_v1
 
Architecting Cloud Apps
Architecting Cloud AppsArchitecting Cloud Apps
Architecting Cloud Apps
 
Viridians on Rails
Viridians on RailsViridians on Rails
Viridians on Rails
 
McrUmbMeetup 22 May 14: Umbraco and Amazon
McrUmbMeetup 22 May 14: Umbraco and AmazonMcrUmbMeetup 22 May 14: Umbraco and Amazon
McrUmbMeetup 22 May 14: Umbraco and Amazon
 
AWS Interview Questions and Answers -CREDO SYSTEMZ.pdf
AWS Interview Questions and Answers -CREDO SYSTEMZ.pdfAWS Interview Questions and Answers -CREDO SYSTEMZ.pdf
AWS Interview Questions and Answers -CREDO SYSTEMZ.pdf
 
NWCloud Cloud Track - Best Practices for Architecting in the Cloud
NWCloud Cloud Track - Best Practices for Architecting in the CloudNWCloud Cloud Track - Best Practices for Architecting in the Cloud
NWCloud Cloud Track - Best Practices for Architecting in the Cloud
 
AWS CodeDeploy
AWS CodeDeploy AWS CodeDeploy
AWS CodeDeploy
 
Current state of affairs cloud computing
Current state of affairs   cloud computingCurrent state of affairs   cloud computing
Current state of affairs cloud computing
 
A Step By Step Guide To Put DB2 On Amazon Cloud
A Step By Step Guide To Put DB2 On Amazon CloudA Step By Step Guide To Put DB2 On Amazon Cloud
A Step By Step Guide To Put DB2 On Amazon Cloud
 
Cloud State of the Union for Java Developers
Cloud State of the Union for Java DevelopersCloud State of the Union for Java Developers
Cloud State of the Union for Java Developers
 
Why we chose mongodb for guardian.co.uk
Why we chose mongodb for guardian.co.ukWhy we chose mongodb for guardian.co.uk
Why we chose mongodb for guardian.co.uk
 
Rails
RailsRails
Rails
 
What is AWS and What can you do with it | by Kunal Yadav | Noteworthy - The J...
What is AWS and What can you do with it | by Kunal Yadav | Noteworthy - The J...What is AWS and What can you do with it | by Kunal Yadav | Noteworthy - The J...
What is AWS and What can you do with it | by Kunal Yadav | Noteworthy - The J...
 

Recently uploaded

Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 

Recently uploaded (20)

Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 

Guide - Migrating from Heroku to AWS using CloudFormation

  • 1. Rob Linton Jasondb – a cloud based, CTO & Founder scalable NoSQL database www.jasondb.com for social and mobile applications. Phone: [AUS] + 61 418 510 155 Email: robl@jasondb.com 2 Migrating from Heroku to Amazon AWS using CloudFormation In guide number one we looked at how we migrated Amazon EBS backed AMI’s between AWS Regions using the tools that already exist on a standard Unix AMI. (Available on slideshare.net at http://www.slideshare.net/pleasebiteme/presentation- migrating-aws-ebs-backed-amis-between-regions-9465619) In this guide we look at migrating a Ruby on Rails application to Amazon AWS. This guide, while focussed on Ruby on Rails, can be used as a generic introduction on setting up any application in the Amazon AWS stack. This guide was presented at the Australian AWS Users Group in Melbourne on the 26thOctober, 2011. A brief summary of Heroku Heroku is commonly referred to as a Platform as a Service (PaaS) provider, in that they offer more than just infrastructure services. Heroku offer a turnkey solution for hosting, originally, Ruby on Rails (RoR) applications, although they now offer other languages such as Node.js, Clojure, Java, Python and Scala. Heroku’s success lies in the fact that as a Ruby on Rails developer, you could focus on your application and leave everything else such as the hosting and scaling up to someone else. Having done a substantial amount of development over the years (although not in RoR), I can attest to the attraction of any services that eases the deployment of your application.
  • 2. Why migrate from Heroku? There may be a number of reasons why you may want to migrate from Heroku. While Heroku is great in the way it takes the load of managing the deployment and scaling away from you, there are always compromises. In this case Heroku, while reducing the complexity, also reduces the flexibility. There are just some things that you cannot do in Heroku. Also as your application starts to gain momentum, it is usually cheaper to host your application on AWS as the number of users increase. The usual steps for deploying to Heroku The usual steps for deploying to Heroku are as follows: Install the required software 1. Install Ruby on Rails 2. Install Git 3. Create an Heroku account 4. Install the Heroku Gem $ gem install heroku Create your hello world application: $ rails hello $ cd hello $ rails generate controller hello Open the file config/routes.rb. Almost at the bottom (line #57) is this line: # match ':controller(/:action(/:id(.:format)))' Remove the # in front so the line looks like: match ':controller(/:action(/:id(.:format)))' Create a file named index.html.erb in app/views/hello containing the text ‘Hello world’. Start the server. 2
  • 3. $ rails server Use Git to manage your project: $ cd PATH/TO/MY_APP $ gitinit Initialized empty Git repository in .git/ $ git add . $ git commit -m "new app" Create a ssh key pair: $ cd ~/.ssh $ mkdirkey_backup $ cpid_rsa* key_backup $ rmid_rsa* $ ssh-keygen -t rsa -C "your_email@youremail.com" Open the id_rsa.pub file with a text editor and cut & paste into your account settings on the Heroku web site. Configure Git $ gitconfig --global user.name "FirstnameLastname" $ gitconfig --global user.email "your_email@youremail.com" Create your Heroku application $ heroku create Upload your application to Heroku $ git push heroku master 3
  • 4. Set up your application database $ heroku rake db:migrate Setting up the Amazon AWS Environment Before we begin, let’s make sure we have the pre-requisites in place. Make sure you have created an AWS account and have enabled access to the following products: 1. Elastic Compute Cloud (EC2) 2. Relational Database Service (RDS) 3. Elastic Load Balancing (ELB) 4. CloudWatch 5. CloudFormation 6. Simple Notification Service (SNS) Also before you start make sure you have created a key/pair and download the private key to a safe place on your local computer. Architecture overview Here is asimple overview of the architecture for the rails application on AWS. 4
  • 5. Overview architecture of the rails application As you can see from the diagram above, the layout is relatively simple. The load balancer will have two rails servers, which in turn will use aRelational Database Instance (RDS) to store its data. Step by step Now let’s put the pieces in place. To create the application stack we are going to use AWS CloudFormation. CloudFormation is a great way to speed up the creation of commonly used application stacks such as Ruby on Rails applications, Wordpress sites and even Drupal CMS sites. 5
  • 6. Create a new stack Click on the Create New Stack button, this will pop up the Create Stack dialog. Create stack dialog Give your application a name (Hello World) and select the sample template of Rails Hello World Application (SSH enabled). At the bottom of the dialog, expand the Show Advanced Options. This exposes some extra options that you can select such as setting a time out on the creation or adding a Simple Notification Service (SNS) topic. 6
  • 7. For this example we will be adding a SNS topic that notifications can be sent to. This next dialog looks pretty daunting, but is effect just asking for some standard bits of information such as user names and passwords. Create stack options I recommend that you change the rails database password, the rails database user and the operator email address. Make sure you scroll down and get the last option to enter a key pair name, as this is hidden at the bottom of the dialog. Enter the key pair name you created earlier. Once you have entered these pieces of information click on Continue. The final dialog shows a summary of the parameters that will be used to create the Ruby on Rails stack. 7
  • 8. Create stack summary screen This is the last point where you can cancel the create stack. By clicking on the Create Stack button, amazon will go ahead and create an Auto Scaled sample Ruby application, backed by an Amazon RDS instance. Note the Notification section at the bottom, at this point the SNS notification will have already have been created and you should have received an email similar to the one below. 8
  • 9. SNS notification Clicking on the link should display the following message. Confirmed During the Ruby on Rails stack creation, the following dialog will be displayed. 9
  • 10. Creating stack During the creation process you will receive a number of email notifications via the SNS service. Email notifications After your rails stack has been completed, the status will change to CREATE_COMPLETE. 10
  • 11. Resources created Selecting the Resources tab will show you all of the resources that the CloudFormation stack created for you. Because it is important that you understand what actually happened, I’ll take you through each of the resources created. Here is an overview diagram of what was created above: 11
  • 12. CloudFormation stack after creation EC2SecurityGroup This is the AWS security Group used to restrict access to your rails hosts. For AWS, security groups work on individual servers, so for example, A single EC2 instance created as part of the CloudFormation stack can only be accessed via port 8888, or port 22 (ssh), even if the source of the access was a second EC2 instance in the same group. ElasticLoadBalancer The ELB accepts traffic in on port 80 and redirects it out on port 8888 to each of the running rails servers. Note how it changes the port number to ensure that each of the rails servers are not accessible on port 80. 12
  • 13. Note however, that if you knew the direct address of one of the EC2 instances, this does not prevent you from connecting to the instance directly by using the following syntax in your browser. http://ec2-107-20-81-60.compute-1.amazonaws.com:8888/ DBSecurityGroup The database security group restricts access to the RDS instance by only allowing EC2 instances that are members of a specific EC2 security group to connect. In this case only members of the Rails security group can connect to RDS. SampleDatabase This is the RDS MySQL instance that was created for you. By default a db.m1.small instance was created. Also by default a Multi AZ RDS deployment was done. Selecting a Multi AZ deployment allows a hidden replica to be created in a different availability zone, allowing for fail-over of your RDS instance if one availability zone goes down. AlarmTopic This is the Simple Notification Service (SNS) that was created as part of the stack creation. As part of the creation process I received 22 notifications in the space of around 30 minutes, so I would recommend that you create a mail rule to move these off to their own folder in your mail program. TooManyUnhealthHostsAlarm You can see the details for this alarm by clicking on it in the CloudWatch tab. 13
  • 14. Alarm details As you can see from the highlighted section above, this alarm will trigger if the number of unhealthy hosts > 0 for 1 minute. The action for this alarm is to send a notification to the SNS service that we set up earlier. RequestLatencyAlarmHigh This is the second alarm. This alarm will trigger if the latency is greater than 1 second from the ELB to a Rails instance for longer than 1 minute. If this alarm triggers a SNS notification will be sent. LaunchConfig This is a component of the Auto Scaling. The launch configuration defines the type of instances that will be started as well as what AMI to launch. This has been taken care of for you so you will not need to edit this unless you would like to upgrade to a larger instance type or if you would like to use a ‘Golden Image AMI’(We see later on how to use Golden Images) WebServerGroup The Web Server Group defines which availability zones to start any new instances in as well as the maximum and minimum instance numbers. The default configuration for the 14
  • 15. web server group that was set up is a minimum of 1 with a maximum of 3. Unfortunately this is not visible in the Web GUI, other than by reading the template. The following section of the template shows the WebServerGroup details. "WebServerGroup": { "Properties": { "LoadBalancerNames": [ { "Ref": "ElasticLoadBalancer" } ], "MinSize": "1", "LaunchConfigurationName": { "Ref": "LaunchConfig" }, "AvailabilityZones": [ { "Fn::Join": [ "", [ { "Ref": "AWS::Region" }, "a" ] ] } ], "MaxSize": "3" } CPUAlarmHigh This is the third alarm and will send a notification to SNS if the average CPU of any instance in the WebServerGroup is great than 10% for more than one minute. Overview of what was implemented by the stack So the overview of what was implemented by the stack in simple English is as follows: The stack consists of an Elastic Load Balancer (ELB) which accepts connections on port 80 and distributes them to the WebServerGroup on port 8888. The WebServerGroup is an Auto Scaling Group defined as having a minimum of 1 server and a maximum of 3. 15
  • 16. The Auto Scaling Group however does not automatically respond to alarms as no Auto Scaling Policies have been put in place by the stack. So to scale the group up and down you will need to do this manually. The EC2 instances in the WebServerGroup are protected by a Security Group restricting access to port 8888 and port 22 (ssh) from any source IP.The database instance created was a MySQL instance with Multi AZ fail- over enabled. Also by default the backup retention period has been set to one day. The servers in the WebServerGroup all have Ruby on Rails installed and already running, however, your application will not already be installed on any of them. Configuring your application Now that you have configured the infrastructure for your Ruby on Rails stack, we need to be able to do two more things. Install our application. Scale up and scale down our Rails servers. Installing your application One of the interesting dilemmas when using products like CloudFormation is the one of how to install your application on new EC2 instances that are created in response to scaling events. There are a number of ways to configure and scale your applications in your new stack and there is a great article that should be used as a guide (although quite a long read). https://s3.amazonaws.com/cloudformation- examples/BoostrappingApplicationsWithAWSCloudFormation.pdf In reality AWS doesn’t provide the tools required to complete the last mile, however the easiest way is to create a ‘Golden Image’ AMI which is used by CloudFormation when starting new instances. A Golden Image is a master AMI which already has your application installed and configured on it. 16
  • 17. There is a trick to this, and the main one is enabling ssh access to your default Rails EC2 instance as part of the stack install. (which is why we chose this option at the beginning of this guide) The steps are actually pretty straight forward. Configure your rails instance 1. Using scp, copy your rails application to the new rails EC2 instance using the same private key you specified when starting it up. (If you don’t know where to copy it to, copy it to ~/my-rails-app initially) 2. Log into the new rails EC2 instance using the private/public key pair you specified when configuring the stack using ssh. 3. Stop the rails server. 4. Move the existing directory ~/hwrails to ~/hwrails.orig 5. Rename your new application directory to ~/hwrails 6. As part of the install you will need to edit the database.yaml file to configure access to the new RDS instance that was created for you. 7. Restart the rails server. Create an Image Once you have configured your server with your application, and tested it, you will need to create an AMI Image from it. This is quite straight forward, just locate the instance in the EC2 window, right click and select Create Image (EBS AMI). This will create a new AMI for you to use as the new base AMI in the CloudFormation template. Edit the CloudFormation Template Once the new AMI has been created, cut and paste the template file to a local file on your computer. Open it up in Notepad or Textedit and edit the following section: "AWSRegionArch2AMI" : { "us-east-1" : { "32" : "ami-d411e2bd", "64" : "ami-da11e2b3" }, "us-west-1" : { "32" : "ami-e7c797a2", "64" : "ami-e5c797a0" }, "eu-west-1" : { "32" : "ami-17c2f663", "64" : "ami-13c2f667" }, "ap-southeast-1" : { "32" : "ami-1af28c48", "64" : "ami-1ef28c4c"}, "ap-northeast-1" : { "32" : "ami-b403a8b5", "64" : "ami-b803a8b9" } } Replace the highlighted bit in yellow with the name of your new AMI. The yellow piece represents a 32 bit instance running in us-east-1. (The default) 17
  • 18. Update the CloudFormation Stack Once you have your new template ready to go, you will need to edit the existing CloudFormation stack. To do this highlight the CloudFormation and click on the Update Stack in the toolbar, the following dialog will be presented. Update stack Select the Upload a Template File option and upload the edited template. Then just click Continue through all of the next dialogs and accept the answers that you provided previously. You may not notice any changes at this point, and in fact there are no changes. The easiest way to see if your changes work is to terminate your existing EC2 instance! Don’t panic though, because it is part of an Auto Scaling Group, AWS will automatically restart a new instance based on your new AMI. There is a bug in the current CloudFormation where it does not update the Launch Config to the new AMI unless the instance type is changed in the configuration screen. 18
  • 19. So you will need to upload the template file twice. The first time change the instance type to m1.large, then the second time change it back to m1.small. Give AWS a few minutes to detect that the group is below its minimum threshold, then look at the new instance in the EC2 tab. Take a look at the AMI-ID and confirm that it is indeed the new AMI that you added to the template file. Another way to do this would have been to install the Auto Scaling command line tools and use the following commands to edit the Launch Config: as-delete-launch-config as-create-launch-config Adding more servers to the Autoscaling Group Now that we have installed our application, it would be nice to be able to add more servers to our Auto Scaling Group if the number of users connecting increases. Unfortunately there is currently no way to do this from the Web GUI, the only way to modify the autoscaling group is to either use the command line tools or modify the existing template. For this example I’m going to modify the template using the same process that I used in the previous section and increase the minimum number of servers in my Auto Scaling Group to two. Edit the template file Find the WebServerGroup section in the template file and edit the highlighted section. "WebServerGroup": { "Properties": { "LoadBalancerNames": [ { "Ref": "ElasticLoadBalancer" } ], "MinSize": "1", "LaunchConfigurationName": { "Ref": "LaunchConfig" }, "AvailabilityZones": [ { "Fn::Join": [ "", [ { "Ref": "AWS::Region" 19
  • 20. }, "a" ] ] } ], "MaxSize": "3" } Change the MinSize from 1 to 2 and once again update the stack with the new template as in the previous example. This time the changes will take affect without needing to change any other parameters. Take another look at the EC2 instance tab and you will see that the changes have worked almost straight away. There should now be two instances of your rails application running. It has automagically been added to the Elastic Load Balancer, the correct security groups and will start taking traffic almost straight away. (As soon as the ELB puts it in service, which by default is around 20 seconds) That’s it! For a step by step guide on implementing automatic Auto Scaling based on CPU load, please take a look at chapter 9 of my book: Amazon Web Services: Migrating your .NET Enterprise Application. http://www.amazon.com/Amazon-Web-Services-Enterprise-Application/dp/1849681945 Summary In this guide we looked at how to migrate a Heroku Ruby on Rails application to AWS. We looked at setting up an application stack using CloudFormation and how to install and configure your stack after it creation. 20
  • 21. 21