brain.rbinstance_missing
First of all, Amazon AWS rocks. it’s a great, stable and not so expensive way to get your application up and running, but also ready for any disaster to come (Someone said Digg effect?).
Getting your application on to Amazon EC2 is not as complicated as you think, managing and controlling your instances may require a professional system administrator, but i would recommend that anyway (except if you go and host your application on EngineYard than you are worry-free, but you’ll pay.. ohh you’ll pay for that sense of security).
There is no real need to setup your EC2 instances in day 1, you can wait until the application is mature enough to be deployed onto a production infrastructure. Amazon EC2 costs per usage, so, it will cost you to have your application up and running on EC2, keep that in mind (although the prices are a joke).
Once your application is ready to be deployed to EC2, you’ll need an image.
Image, in EC2 terms, is a reference to an OS + all required installations and configuration needed to run your application.
The best all-round image to use with rails is Pawl Dowman’s Rails on EC2 bundle (or here). EC2onRails is great. Unfortunately, if you�ve never used EC2 before, you probably won�t be able to �Deploy a Ruby on Rails app on EC2 in Five Minutes� as the documentation claims, so this document will try to fill in the gaps for someone who has never worked with EC2.
note: it’s never too early to sit down and read Amazon’s documentations, they are not that bad
First thing is first, your development machine, the one from which you will be deploying to EC2 should undoubtably hold:
Once you are set with these issues, you’ll need to sign up for the Amazon EC2 service, do that right here.
Now, sign up for the S3 service.
Because although your image (later: ‘instance’) includes storage, images/instances can be brought down, up, dropped and even deleted, that will ultimately, kill your data.
S3 is Amazon�s �Simple Storage Service�. S3 is a super-inexpensive service to store files into �buckets in the cloud�. S3 will be used for database backups of your Rails Application.
Sign up for S3 here.
After signing up, you will need to collect four pieces of information from your AWS account by visiting the Access Identifiers page.
double check it! it’s very very very very important.
The EC2 command-line tools are a Java-based set of tools that allow you to create and manage machine instances on EC2.
Download it here and extract the zip file, remember where you put it, i always keep it in my home folder as a hidden folder named .ec2 (/Users/eizesus/.ec2/ on OSX).
Run these commands:
export EC2_PRIVATE_KEY=/Users/eizesus/.ec2/pk-5xxxxxxxx7.pem
export EC2_CERT=/Users/eizesus/.ec2/cert-5xxxxxxxxxxxxx7.pem
export EC2_HOME=/Applications/java/ec2-api-tools-1.3-24159
export PATH=$EC2_HOME/bin:$PATH
I suggest adding these lines to your startup profile, whatever it maybe on your OS. (OSX, it’s in /etc/profile).
After you do that, reload your session (closing the console/command line and opening it again should do).
Run this at the command line:
ec2-add-keypair my-secret-code
my-secret-code can and should be anything that you like, try to pick something that makes sense for your setup (remember that i will keep on writing my-secret-code, use your phrase instead).
Save the output from that into a file named id_rsa-my-secert-code on your SSH library (OS dependent) and paste everything between (and including) the ��BEGIN RSA PRIVATE KEY�� and ��END RSA PRIVATE KEY�� lines into it. Confirm that the file contents looks exactly like this, then save the file into the file.
~/.ssh/id_rsa-my-secret-code
chmod 600 ~/.ssh/id_rsa-my-secret-code
An Amazon Machine Image (AMI) is a named configuration of an EC2 image.
The current AMI id�s for EC2onRails are:
Start up an instance of the 32-bit EC2onRails image:
ec2-run-instances ami-c9bc58a0 -k my-secret-code
INSTANCE i-XXXXXXXX ami-c9bc58a0 pending my-secret-code 0
pending my-secret-code part means that the image is pending for loading.
To check the status of the instance build type:
Replace the
ec2-describe-instances i-XXXXXXXX
i-XXXXXXXX above with the string that comes after INSTANCE in the second line of the results from the ec2-run-instances command.
ec2-xx-xxx-xxx-xx.compute-1.amazonaws.com
ec2-authorize default -p 22
should result in:
PERMISSION default ALLOWS tcp 22 22 FROM CIDR 0.0.0.0/0
ec2-authorize default -p 80should return something like:
PERMISSION default ALLOWS tcp 80 80 FROM CIDR 0.0.0.0/0
You should be able to ssh into the your new machine, replace ec2-xx-xxx-xxx-xx.compute-1.amazonaws.com in the next command with the cloud address you just got.
ssh -i ~/.ssh/id_rsa-ec2-rails-keypair root@ec2-xx-xxx-xxx-xx.compute-1.amazonaws.com
EC2 for Rails requires Capistrano::
sudo gem install capistrano -v 2.4.3
sudo gem install ec2onrails
The capfile can an be left as-downloaded.
config/s3.yml – This configuration is pretty simple, under the production section, put your AWS information that you noted above.
aws_access_key: (you got me when you signed up)
aws_secret_access_key: (me too)
bucket_base_name: production.yourname.com
config/deploy.rb – There are a lot of definitions to be made, read all the comments and setup the deploy process as your application requires.config/database.yml – For the production section, basically add any good password that you like and add hostname: db_primary. It should look something like:
production:
adapter: mysql
encoding: utf8
database: appname_production
username: user (not ROOT!)
password: password (no, no empty passwords)
hostname: db_primary
cap ec2onrails:get_public_key_from_server cap ec2onrails:server:set_roles
Configure the db and stuff:
cap ec2onrails:setup
And wooooohoooo, check your application url.
cap deploy:cold
| Variable | Value |
|---|---|
| GITHUB | |
| WWR | { :working_with_rails => 'http://www.workingwithrails.com/person/5844-elad-meidar' } |
| IRC | { 'irc.freenode.net' => [ '#rubyonrails', '#railsbridge', '#ruby', '#jquery' ]} |
| SKYPE | eladmeidar |
You're seeing this error because I think it is funny.