Showing posts tagged with AWS SDK for Android

Amazon DynamoDB is a fast, highly scalable, highly available, cost-effective, non-relational database service. Amazon DynamoDB removes traditional scalability limitations on data storage while maintaining low latency and predictable performance. The sample mobile application described here demonstrates how to store user preferences in Amazon DynamoDB. Because more and more people are using multiple mobile devices, connecting these devices to the cloud, and storing user preferences in the cloud, enables developers to provide a more uniform cross-device experience for their users.

This article shows sample code for the Android platform. The complete sample code and project files are included in the AWS SDK for Android. Links to the SDK are available at the end of this article.

To use the sample app, you'll need to deploy a token vending machine (TVM). A TVM is a cloud-based application that manages AWS credentials for users of mobile applications. To deploy the TVM, you'll first need to obtain your own AWS credentials: an Access Key ID and Secret Key.

If you haven't already signed up for Amazon Web Services (AWS), you will need to do that first to get your AWS credentials. You can sign up for AWS here. After you sign up, you can retrieve your credentials at this page. The credentials will be used to set up the TVM to authenticate users of AWS mobile applications. Sample Java web applications are available here: Anonymous TVM and Identity TVM (this sample uses Anonymous TVM).

Overview

In Amazon DynamoDB, a database is a collection of tables. A table is a collection of items, and each item is a collection of attributes. For our app, we create a single table to store our list of users and their preferences. Each item in the table represents an individual user. Each item has multiple attributes, which include the user's name and their preferences. Each item also has a hash key—in this case, userNo—which is the primary key for the table.

The app demonstrates how to add and remove users, and modify and retrieve their preference data. The app also demonstrates how to create and delete Amazon DynamoDB tables.

Registering the Device with Token Vending Machine

In order to create an Amazon DynamoDB client, we must first register the mobile device with the token vending machine (TVM). For this sample, we use the Anonymous TVM to register the device. Then we store the UID and key returned by the TVM on the device.

Creating an Amazon DynamoDB Client

To make service requests to Amazon DynamoDB, you need to instantiate an Amazon DynamoDB client. The code below shows how to create an Amazon DynamoDB client for Android using the stored temporary credentials from the TVM.

Creating a User List (Table Creation)

Each user's preferences are stored as items in an Amazon DynamoDB table. The following code creates that table using the client we created above. Every Amazon DynamoDB table require a hash key. In this sample, we use userNo as the hash key for the table.

Checking the Status of the Table (Table Description)

Before we can move to the next step (creating users), we must wait until the status of the tables is ACTIVE. To retrieve the status of the table, we use a describe table request. This request returns information about the table such as the name of the table, item count, creation date and time, and its status.

Creating Users (Item Creation)

For each user, we'll create an item in the table. An item is a collection of attribute/value pairs. For each item, we'll have three attributes: userNo, firstName, and lastName. These are added to a put item request in order to create the item.

Listing Users (Table Scan)

We can retrieve a collection of users with a scan request. A scan request simply scans the table and returns the results in an undetermined order. Scan is an expensive operation and should be used with care to avoid disrupting your higher priority production traffic on the table. See the Amazon DynamoDB developer guide for more recommendations for safely using the Scan operation.

We’ve been sharing a lot of information about best practices for uploading your app(s) to the Amazon Appstore for Android, along with details on what the store will look like when we go live (which is soon).

Developer Carmen Delessio’s success story may offer inspiration on how to take advantage of these two resources and submit new apps to the Appstore. Delessio is an Android app developer who has leveraged Amazon SimpleDB and AWS SDK for Android to build some of his apps.

In September of 2010, Delessio heard about the Sprint 4G App Challenge and decided to enter his updated version of BFF Photo Pro. Two months later, Sprint sent him an award notification.

"At first, I literally did not believe it and began to check the info," Delessio said."I verified and was incredibly happy to learn that I was one of the five winners of $50,000."

His success has propelled him to continue developing new Android apps, with AWS providing a crucial backbone for his code. Along with BFF Photo Pro, Delessio has leveraged the AWS SDK and SimpleDB to build BFF Search, which allows users to easily search for people, topics, and events on Facebook. Both of his BFF apps will be available on the Amazon Appstore.

He's also used the AWS services to build NYC Parks, an app based on the XML datasets available to the public by the New York City Department of Parks and Recreation. While swearing he's not contest crazy, Delessio entered the app in the NYC BigApps 2.0, a competition that seeks to make New York "more transparent, accessible, and accountable."

"We are in a place right now where your work, and the recognition for your work, defines your opportunities more than any other time that I can remember. It's a real meritocracy," observed Delessio, who is currently working with a Major League Baseball (MLB) data set to build an app that allows users to search for all the MLB games they’ve attended and share their stats over their social network. "This plays into the strengths of AWS; you have a great opportunity to make great apps with low expense. Structured data fits into SimpleDB well, and the AWS SDK allows you to access it and build (your app) with integrity: I don't have to think very much how it works, it just works."