Using Amazon SimpleDB
       with Rails

         Martin Rehfeld
      @ RUG-B 07-Feb-2008
Remember?
AWS Rails Scenario


                                }
 EC2                       S3
   Web                 Stat...
limited
                                                beta
    Amazon SimpleDB
•   Database web service advertised as

 ...
Amazon SimpleDB
      Common Terms
•   Domain:                                       SimpleDB
    storage container ~ tabl...
SimpleDB @
                                                                                 no code
                      ...
Amazon SimpleDB API
 •   Domain level
     •   CREATE, LIST, DELETE
 •   Item level
     •   GET, PUT, DELETE attributes w...
Almost
  RESTful
Mapping RESTful URLs
HTTP/REST                SimpleDB

GET

   /domain?query    QUERY

GET

   /domain/itemID   GET ATTRI...
Mapping RESTful URLs
Emulating multiple resources in one domain via _resource attribute
    HTTP/REST                     ...
A Bridge to Rails
           ActiveResource

                                        „Rails XML“

                        ...
AWS SDB Proxy Plugin I
• Install aws-sdb gem
  gem install aws-sdb


• Install aws_sdb_proxy plugin:
  script/plugin insta...
AWS SDB Proxy Plugin II
 • Create demo ActiveResource model
   class Post < ActiveResource::Base
     self.site = quot;htt...
Vision: Fully Virtualized
    Scalable Stack...
• Building blocks for AWS-only web app
  deployment:
 • Static assets/cont...
Q &A



!   Martin Rehfeld

    http://inside.glnetworks.de
    martin.rehfeld@glnetworks.de
Upcoming SlideShare
Loading in …5
×

Using Amazon SimpleDB with Ruby on Rails

14,691 views

Published on

The vision of eventually forming a truly scalable deployment architecture using Amazons EC2, S3, SQS and SimpleDB web services together, triggered a very vivid discussion at the Ruby Users Group Berlin (RUG-B).

The presention gives an introduction to Amazon SimpleDB focusing on how to connect it to Ruby on Rails via the ActiveResource framework and the <a href="http://agilewebdevelopment.com/plugins/aws_sdb_proxy">AWS SDB Proxy Server Plugin</a>.



Published in: Technology
1 Comment
18 Likes
Statistics
Notes
  • quiero dar de baja a esa cosa que sale como imejenes en mi blog como se hace no sale en ningun lado
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
14,691
On SlideShare
0
From Embeds
0
Number of Embeds
446
Actions
Shares
0
Downloads
258
Comments
1
Likes
18
Embeds 0
No embeds

No notes for slide

Using Amazon SimpleDB with Ruby on Rails

  1. Using Amazon SimpleDB with Rails Martin Rehfeld @ RUG-B 07-Feb-2008
  2. Remember? AWS Rails Scenario } EC2 S3 Web Static Server Content Application Server memcached, backgrounDRb, Code  ... SQL  HOW TO GET A PERSIS Database DB? TENT
  3. limited beta Amazon SimpleDB • Database web service advertised as • Simple, Flexible, Scalable, Fast, Reliable, Inexpensive • No RDBMS: no SQL, no joins, no schema, no referential integrity, no transactions • HTTP-Interface • Pay per use: • $0.14 per Machine Hour consumed • $0.10-0.18 per GB - data transfer • $1.50 per GB-month storage
  4. Amazon SimpleDB Common Terms • Domain: SimpleDB storage container ~ table • Item: my domain A attributes ~ table rows accessed by ID ~ primary key } items • Attribute: (multiple) values ~ table columns; every item may have a different set of up to 256 attributes my domain B • Value: ... each Attribute may have multiple Values, always varchar(1024)[]
  5. SimpleDB @ no code no code no code no code no code no code no code (amazon_sdb) rich API* simply working! *) defect release 0.6.5 when evaluated, but newer release available (not re-tested yet)
  6. Amazon SimpleDB API • Domain level • CREATE, LIST, DELETE • Item level • GET, PUT, DELETE attributes with values • QUERY* for unordered item IDs by attribute values within one domain *) lexicographical =, !=, <, > <=, >=, STARTS-WITH, AND, OR, NOT, INTERSECTION / UNION • Beware: Eventual Consistency Approach!
  7. Almost RESTful
  8. Mapping RESTful URLs HTTP/REST SimpleDB GET /domain?query QUERY GET /domain/itemID GET ATTRIBUTES POST /domain/itemID PUT ATTRIBUTES PUT /domain/itemID PUT ATTRIBUTES (replace) DELETE /domain/itemID DELETE ATTRIBUTES
  9. Mapping RESTful URLs Emulating multiple resources in one domain via _resource attribute HTTP/REST SimpleDB GET /domain/resource?query QUERY GET /domain/resource/itemID GET ATTRIBUTES POST /domain/resource/itemID PUT ATTRIBUTES PUT /domain/resource/itemID PUT ATTRIBUTES (replace) DELETE /domain/resource/itemID DELETE ATTRIBUTES
  10. A Bridge to Rails ActiveResource „Rails XML“ HTTP/REST ? AWS SDB Proxy Server* „AWS XML“ HTTP/SDB API SimpleDB *) http://inside.glnetworks.de/2008/01/20/bridging-rails-to-amazon-simpledb-using-activeresource/
  11. AWS SDB Proxy Plugin I • Install aws-sdb gem gem install aws-sdb • Install aws_sdb_proxy plugin: script/plugin install http://rug-b.rubyforge.org/svn/aws_sdb_proxy • Configure config/aws_sdb_proxy.yml development: aws_access_key_id: <your amazon aws key> aws_secret_access_key: <your amazon aws secret key> port: 8888 • Create new domain on Amazon SimpleDB rake aws_sdb:create_domain DOMAIN=ActiveResourceStore • Start AWS SDB Proxy rake aws_sdb:start_proxy_in_foreground
  12. AWS SDB Proxy Plugin II • Create demo ActiveResource model class Post < ActiveResource::Base self.site = quot;http://localhost:8888quot; self.prefix = quot;/ActiveResourceStore/quot; end • Testdrive in script/console >> p = Post.create(:title => 'My first SimpleDB post') => #<Post:0x198ceec @prefix_options={}, @attributes={...}> >> p.body = 'Content is king' => quot;Content is kingquot; >> p.save => true >> Post.find(:first, :params => { :title => 'My first SimpleDB post' }) => #<Post:0x18efef8 @prefix_options={}, @attributes={...}>
  13. Vision: Fully Virtualized Scalable Stack... • Building blocks for AWS-only web app deployment: • Static assets/content in S3 • As many app servers as needed on EC2 • Structured data persisted in SimpleDB • All client/server interactions via SQS Note: XmlHttpRequest cross-site restrictions must be examined
  14. Q &A ! Martin Rehfeld http://inside.glnetworks.de martin.rehfeld@glnetworks.de

×