Integrating an App with Amazon Web Services Simple
Integrating an App with Amazon Web Services Simple. DB “A Matter of Choices” Presented by Mark Maslyn – mmaslyn@msn. com
Amazon Web Services Menu
Amazon Web Service Databases • RDB (Relational Database) • S 3 (Large Object Database) • Simple. DB (No. SQL Database)
Amazon Simple. DB • No. SQL Database – Non Relational • Distributed - Highly Scalable, Highly Reliable, Incremental Writes • Primarily for Database Reads • RESTful Calls Passing Credentials and Query • Very Low Cost – First 25 Hours Free Each Month.
Simple. DB Language Support
Whoa… Non – Relational ? ? ? From Wiki. Media Commons
No. SQL Databases • Use “Domains” Instead of “Tables” • Don’t Have Fixed Schemas – Easily Add or Remove Columns • Variable Number of Fields per Record (Row) • Each Record is a List of Name / Value Pairs • Everything is a String • Record Indexed By A Unique Item ID • Implements Most SQL Calls • Maintained By Amazon Web Services
Android to Amazon Database Model Data Request Data Response Android Phone Amazon Simple. DB Cloud For UI and Display For Database Heavy Lifting Each Does What It Does Best ! Images From HTC and Wiki. Media
Remote Database Example: Kooaba From www. kooaba. com
Kooaba Architecture From www. kooaba. com
My Application – Oil Well Information • • Location (Latitude / Longitude) Well Status Land Survey Boundaries Must Have the Ability to “Drill Down” for More Information
Drilling For Oil A B C D Amount of Data Generated Depends On How Deep the Well is Drilled
Example No. SQL Row For Geologic Formation Names and Depths Item Key Name 1 Value 1 Name 2 Value 2 Name 3 Value 3 “ 05 -10123”, “BLAINE”, “ 1464”, ”ATOKA”, ” 4744”, ”MORROW”, ” 4854”
Coding the Connection From Android Image From http: //www. vpnchoice. com/blog/wp-content/uploads/2011/06/android-vpn-300 x 187. jpg
Connecting to Amazon Simple. DB private static Amazon. Simple. DB sdb = null; public static Amazon. Simple. DB get. Instance() { if ( sdb == null ) { // pass in the authenication credentials sdb = new Amazon. Simple. DBClient( AWSDemo. credentials ); // set the node we want to use sdb. set. Endpoint("sdb. us-west-1. amazonaws. com"); } return sdb; }
Creating Simple. DB Domains From Android public void create. Domain(String domain. Name) { sdb. create. Domain(new Create. Domain. Request(domain. Name)); }
Inserting Records From Android // each row is keyed with a “replaceable” item id followed by // attributes i. e. name / value pairs // construct a list of items to be inserted List<Replaceable. Item> data. List = new Array. List<Replaceable. Item>(); // populate the list using the item id and the attribute name / value pairs data. List. add(new Replaceable. Item(“ 05 -123”). with. Attributes( new Replaceable. Attribute(DBFields. STATE, “CO”, true), new Replaceable. Attribute(DBFields. COUNTY, “Weld”, true), new Replaceable. Attribute(DBFields. DRILLING_DATE, “ 05 -11 -2011”, true)); // batch insert the list into the Simple. DB database sdb. batch. Put. Attributes(new Batch. Put. Attributes. Request(“my_domain”, data. List ));
Retrieving Data From Amazon // build your SQL select statement String select. Expression = "select * from " + domain + " where item. Name() = '“ 05 -123’”; // construct a select request Select. Request select. Request = new Select. Request(select. Expression); // retrieve a list of matching items (records) List<Item> item. List = sdb. select(select. Request). get. Items(); // loop through each record and extract the attributes from each item for (int i = 0; i < item. List. size(); i++) { Item item = (Item) item. List. get(i); Array. List<Attribute> attribute. List = (Array. List<Attribute>) item. get. Attributes(); }
Question: Since Android Devices Can Use the Internal SQLite Database… When I Would I Use the Internal Database and When Would I Use the Amazon Cloud Database ?
It Depends On… • Size of Your Database – Size Does Matter • APK Maximum of 30 MB – Cloud Unlimited • Whether the Data is Static or Subject to Change • Whether You Need an Internet Connection For Access • Whether You Require Authentication
My Choices: Local vs. Remote LOCAL REMOTE Android SQLite Database Amazon Simple. DB 100, 000 Colorado Wells Latitude Longitude Status Value Detailed Well Information 4 MB 54 Colorado Counties Land Survey Information 12 MB 21 MB
Locally Stored Data • Well Type / Location • Land Grid
Internet (Remotely) Accessed Data • Authentication as part of RESTful Model • Drill Down – Provide More Detailed Information • No Limit on Amount of Data Accessible
For Further Information Amazon Web Services For SDK’s, Tutorials, Case Studies and Sample Code : http: //aws. amazon. com Mark Maslyn: mmaslyn@msn. com
- Slides: 24