My Shiny Weblog!

programming, photography and lifestyle

Using Amazon EC2 With Fog

So, my cloud deployment marathon week met me with Fog. It could be used for cross cloud service compatibility. I don’t care much about that, but simplicity is cool. Fog is a RubyGem and should be installed with:

1
gem install fog

Working with irb is fine. Two access keys are provided with Amazon AWS registration, they should be used here:

1
2
3
4
5
6
7
8
9
require 'rubygems'
require 'fog'

# create a connection
connection = Fog::Compute.new({
  :provider                 => 'AWS',
  :aws_secret_access_key    => YOUR_SECRET_ACCESS_KEY,
  :aws_access_key_id        => YOUR_SECRET_ACCESS_KEY_ID
})

The connection object allows EC2 API calls. Now a server object could be created, by providing SSH access keys:

1
server = connection.servers.bootstrap(:private_key_path => '~/.ssh/id_rsa', :public_key_path => '~/.ssh/id_rsa.pub', :username => 'ubuntu')

The server object is a working Ubuntu instance on Amazon EC2. It is a Micro instance, 64-bit CPU, 613 MB RAM, 8 GB partition on Amazon EBS and 15 GB bandwith. The AWS Free Usage Tier conditions should be available here. Sending SSH commands with the server object is easy:

1
server.ssh 'pwd'

Of course the server is also available with the standart SSH client, but a public IP is needed:

1
puts server.public_ip_address

The server instance is not removed or stopped with irb termination. All running instances could be destroyed using the connection object:

1
connection.servers.select {|server| server.ready? && server.destroy}

One server instance per user on Amazon EC2 could run free of charge for one year. As usual with cloud providers, that depends on its resource usage. The payment thresholds are reasonably high. Usage statistics are available here.

Reloaded

So I started using Octopress. My old blog used Jekyll and was in Bulgarian. The new one will be in English, because I want to improve my language skills. Some of the old content will be available soon. There are also some nice photos coming along.