SlideShare a Scribd company logo
1 of 14
Download to read offline
Using Amazon SimpleDB
       with Rails

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


                                }
 EC2                       S3
   Web                 Static
  Server              Content

Application
  Server

 memcached,
backgrounDRb,
                 Code
                                    
      ...



                  SQL
                                    
                                          HOW
                                                 TO
                                           GET A
                                        PERSIS
                Database                   DB?
                                               TENT
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
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)[]
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)
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!
Almost
  RESTful
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
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
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/
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
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={...}>
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
Q &A



!   Martin Rehfeld

    http://inside.glnetworks.de
    martin.rehfeld@glnetworks.de

More Related Content

Recently uploaded

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 

Recently uploaded (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

Featured

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 

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!
  • 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