<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>OnRails.org: Amazon RDS: Amazon Relational Database Service or MySQL in the Cloud for Ruby On Rails.</title>
    <link>http://onrails.org/articles/2009/10/29/amazon-rds-amazon-relational-database-service-or-mysql-in-the-cloud-for-ruby-on-rails</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Ruby On Rails and related matters.</description>
    <item>
      <title>Amazon RDS: Amazon Relational Database Service or MySQL in the Cloud for Ruby On Rails.</title>
      <description>&lt;p&gt;For watchthatsite.com (not public yet) I have an instance on &lt;span class="caps"&gt;EC2&lt;/span&gt; with Rails and MySQL but was looking for a more solid hosting solution for MySQL. And how fortunate, Amazon came out with the solution I need this week. Basically with two command line instructions you can start a new server with mysql configured, tuned, and secured. In this blog entry I will go through the steps that perform to move my sql database to Amazon &lt;span class="caps"&gt;RDS&lt;/span&gt;.&lt;/p&gt;


	&lt;p&gt;You can find more information on Amazon Relational Database Service (API Version 2009-10-16) &lt;a href="http://developer.amazonwebservices.com/connect/entry.jspa?externalID=2927&amp;#38;categoryID=290"&gt;here&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;Prerequisite: you need to &lt;a href="http://aws.amazon.com/"&gt;signup&lt;/a&gt; for an account on aws.amazon.com, it can be used for &lt;span class="caps"&gt;EC2&lt;/span&gt;, S3, SimpleDb and all the other services &lt;span class="caps"&gt;AWS&lt;/span&gt; provides.&lt;/p&gt;


&lt;h2&gt;1) Install the Command Line Toolkit&lt;/h2&gt;

	&lt;p&gt;First thing, go download the command line toolkit and read the &lt;span class="caps"&gt;README&lt;/span&gt;.TXT on how to install it. In short you unzip the files, I did put mine at /Developer/aws/RDSCli-1.0.001. Then you create a credential file which contains your &lt;span class="caps"&gt;AWS&lt;/span&gt; access key id and secret key. Then I configured my ~/.bash_profile as follows:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;export AWS_RDS_HOME=/Developer/aws/RDSCli-1.0.001
export AWS_CREDENTIAL_FILE=$AWS_RDS_HOME/credential-file-path.conf
export JAVA_HOME=/Library/Java/Home
export PATH=$AWS_RDS_HOME/bin:$PATH&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;to see that the command line toolkit is setup correctly type $rds&amp;#8212;help&lt;/p&gt;


	&lt;p&gt;You will need the command line tool to execute several commands described here after.&lt;/p&gt;


&lt;h2&gt;2) Create an Instance&lt;/h2&gt;

	&lt;p&gt;Let&amp;#8217;s create a MySQL Server instance. &lt;span class="caps"&gt;RDS&lt;/span&gt; offers the following 5 server instance classes:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;db.m1.small (1.7 GB of &lt;span class="caps"&gt;RAM&lt;/span&gt;, $0.11 per hour)&lt;/li&gt;
		&lt;li&gt;db.m1.large (7.5 GB of &lt;span class="caps"&gt;RAM&lt;/span&gt;, $0.44 per hour)&lt;/li&gt;
		&lt;li&gt;db.m1.xlarge (15 GB of &lt;span class="caps"&gt;RAM&lt;/span&gt;, $0.88 per hour)&lt;/li&gt;
		&lt;li&gt;db.m2.2xlarge (34 GB of &lt;span class="caps"&gt;RAM&lt;/span&gt;, $1.55 per hour)&lt;/li&gt;
		&lt;li&gt;db.m2.4xlarge (68 GB of &lt;span class="caps"&gt;RAM&lt;/span&gt;, $3.10 per hour)&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;I will choose a small instance which I will call dbserver1 with a database name db1 and allocate 5g of database space. I also set the master username as admin and password as secret.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;$ rds-create-db-instance --db-instance-identifier db1 --allocated-storage 5 --db-instance-class db.m1.small --engine MySQL5.1 --master-username admin --master-user-password secret --db-name db1 --headers&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;The output is the following:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;DBINSTANCE  DBInstanceId  Class        Engine    Storage  Master Username  Status    Backup Retention
DBINSTANCE  db1           db.m1.small  mysql5.1  5        admin            creating  1               
      SECGROUP  Name     Status
      SECGROUP  default  active
      PARAMGRP  Group Name        Apply Status
      PARAMGRP  default.mysql5.1  in-sync&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Now you have a server running and you are being billed $0.11 per hour, that&amp;#8217;s like $80 a month without bandwidth but with backup&amp;#8230;and it took only 2 minutes to get going. Can&amp;#8217;t beat that.&lt;/p&gt;


	&lt;p&gt;To see all the instances you have you can issue the&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;rds-describe-db-instances --headers&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2&gt;3) Grant Network Access&lt;/h2&gt;

	&lt;p&gt;So I will grant access from my notebook, assuming the ip address is 24.19.0.48 (you can also specify ranges i.e. 24.19.0.0/50). (Note that access was revoked by &lt;span class="caps"&gt;AWS&lt;/span&gt;, not sure why??)&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;rds-authorize-db-security-group-ingress default --cidr-ip 24.19.0.48 --headers&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;I also have an ec2 instance which I want to grant access to&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;rds-authorize-db-security-group-ingress default --ec2-security-group-name watchthatsite --ec2-security-group-owner-id 526541544691&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Note the ec2-security-group-owner-id is your Amazon &lt;span class="caps"&gt;AWS&lt;/span&gt; account number, you can find it for example on you account activity page. To see your security configuration issue the following command: rds-describe-db-security-groups default&amp;#8212;headers&lt;/p&gt;


&lt;h2&gt;4) Using the Database&lt;/h2&gt;

	&lt;p&gt;To use your database you first need to find out the endpoint address of your new server. So describe you instances:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;rds-describe-db-instances --headers command&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;DBINSTANCE  DBInstanceId  Created                   Class        Engine    Storage  Master Username  Status     Endpoint Address                              Port  AZ          Backup Retention
DBINSTANCE  db1           2009-10-28T22:53:31.666Z  db.m1.small  mysql5.1  5        admin            available  db1.cyhik6zpub5c.us-east-1.rds.amazonaws.com  3306  us-east-1b  1               
      SECGROUP  Name     Status
      SECGROUP  default  active
      PARAMGRP  Group Name        Apply Status
      PARAMGRP  default.mysql5.1  in-sync&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;You find out your endpoint address, for me db1.cyhik6zpub5c.us-east-1.rds.amazonaws.com&lt;/p&gt;


	&lt;p&gt;So now you can connect to your database:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;mysql -h db1.cyhik6zpub5c.us-east-1.rds.amazonaws.com -P 3306 -u admin -p db1&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Let&amp;#8217;s configure my Rails application to point to that database and run a migration:&lt;/p&gt;


	&lt;p&gt;So I change my config/database.yml to point to the above database&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;development:
    adapter: mysql
    host: db1.cyhik6zpub5c.us-east-1.rds.amazonaws.com
    reconnect: false
    database: db1
    username: admin
    password: secret&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt; rake db:migrate&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
Wow, seem to work.

	&lt;p&gt;Let connect to the mysql console and do a show tables;&lt;/p&gt;


&lt;pre&gt;
+-------------------+
| Tables_in_db1     |
+-------------------+
| schema_migrations | 
| users             | 
| watches           | 
+-------------------+
&lt;/pre&gt;

	&lt;p&gt;Yep, all there.&lt;/p&gt;


	&lt;p&gt;Now I still have to move my old production database to the new one, so let&amp;#8217;s dump the data from my old database:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;mysqldump watchthatsite_development -u admin &amp;gt; wts.sql&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;and reload that data in the new database:&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;mysql -h db1.cyhik6zpub5c.us-east-1.rds.amazonaws.com -P 3306 -u admin -p db1 &amp;lt; wts.sql&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Restarting my Rails server…That&amp;#8217;s all!&lt;/p&gt;


	&lt;p&gt;Enjoy,
Daniel.&lt;/p&gt;</description>
      <pubDate>Thu, 29 Oct 2009 03:02:27 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:28dc0a82-86c6-4152-9bad-b962c5fd819f</guid>
      <author>Daniel Wanja</author>
      <link>http://onrails.org/articles/2009/10/29/amazon-rds-amazon-relational-database-service-or-mysql-in-the-cloud-for-ruby-on-rails</link>
      <category>Ruby On Rails</category>
    </item>
    <item>
      <title>"Amazon RDS: Amazon Relational Database Service or MySQL in the Cloud for Ruby On Rails." by Daniel Wanja</title>
      <description>&lt;p&gt;I am still in development but it feels very responsive, but it&amp;#8217;s not under any considerable load. In the last 18 days there where 100&amp;#8217;000 updates and that&amp;#8217;s the load for one user. I will need to do some serious load testing before going live. Also I&amp;#8217;ve heard that RDS is 30% slower than EngineYard&amp;#8217;s offering.&lt;/p&gt;</description>
      <pubDate>Mon, 16 Nov 2009 16:12:08 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:e6aa0473-74bf-4732-95d1-5676c37db953</guid>
      <link>http://onrails.org/articles/2009/10/29/amazon-rds-amazon-relational-database-service-or-mysql-in-the-cloud-for-ruby-on-rails#comment-4880</link>
    </item>
    <item>
      <title>"Amazon RDS: Amazon Relational Database Service or MySQL in the Cloud for Ruby On Rails." by Aaron</title>
      <description>&lt;p&gt;Thanks for posting this. It&amp;#8217;s been 18 days since you moved to RDS. How has it worked out for you? I&amp;#8217;m interested in your perceived performance and stability of the system.&lt;/p&gt;</description>
      <pubDate>Mon, 16 Nov 2009 02:30:36 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:dfa758be-82de-4bc7-80ce-0e14b8b84faa</guid>
      <link>http://onrails.org/articles/2009/10/29/amazon-rds-amazon-relational-database-service-or-mysql-in-the-cloud-for-ruby-on-rails#comment-4876</link>
    </item>
  </channel>
</rss>
