Pragmatic Programmer Issues

Amazon Services for iOS and Android

Comments: 1

Every time we write an application which uses Amazon Web Services, we have to write our Web Services client with http connection processing and errors handling. Amazon gives us two SDKs to simplify this tasks:

Both SDKs comes with code samples, so we may start really quickly. Currently these services are supported:

I’m iPhone fan so I will show you an usage example by building simple application and deploying it on an iPad device.

Our first step is to download AWS SDK for iOS aws-ios-sdk-0.1.0.2.zip. Next we have to unpack zip file. Inside zip file we will find:

  • src directory with SDK sources.
  • samples directory with awsBrowser sample application.
  • Documentation directory with API documentation.
  • AWSiOSSDK.framework directory with ready to use AWS iOS SDK.
  • README.html file with description of zip content
  • NOTICE.txt – information about 3rd-party code (GTMLogger)
  • LICENSE.txt – Apache License version 2.0

Unfortunately latest version has errors in framework directory (instead of soft links we have files with link as a content). We have to change this:

-rwxr–r– 1 pedro staff 26 Jan 26 09:50 Resources
-rwxr–r– 1 pedro staff 24 Jan 26 09:50 Headers
-rwxr–r– 1 pedro staff 26 Jan 26 09:50 AWSiOSSDK
drwxr-xr-x 4 pedro staff 136 Feb 2 15:05 Versions

into this (There is one more in Version directory, it is called Current and should point to A directory):

drwxr-xr-x 5 pedro staff 170 Feb 2 14:41 Versions
lrwxr-xr-x 1 pedro staff 26 Feb 2 14:42 AWSiOSSDK -> Versions/Current/AWSiOSSDK
lrwxr-xr-x 1 pedro staff 24 Feb 2 14:42 Headers -> Versions/Current/Headers
lrwxr-xr-x 1 pedro staff 26 Feb 2 14:43 Resources -> Versions/Current/Resources

Library API

Actually AWS SDK supports Amazon S3, Amazon SimpleDB, Amazon SQS and Amazon SNS.

If you want to use other Amazon services you should subclass AmazonWebSerciceClient class and use invoke: method with AmazonServiceRequest parameter (the best way is to create subclass). The method will return AmazonServiceResponse (of course subclassing for easier access to specific information will be the best choice).

Every service has own client with specific methods for service (eg. S3 client has listBuckets: and SQS client has listQueues: method):

API is very intuitive and has very good documentation, so let us move forward to the example.

Example

OK, now we are ready to start our project.

  1. Start Xcode.
  2. Choose: Create a new Xcode project.
  3. Choose: Split View-base Application.
  4. Give name to your project.
  5. Attach AWSiOSSDK.framework to project.

RootViewController is UITableViewController, which is displayed in right master part of the split view. We will use it to show our Amazon S3 bucket list (listBuckets message). The main part will be used to display list of objects stored in bucket (listObjectsInBucket message) with additional information for current context, and that’s all.

Here you will find code: awsSimpleExample.

Summary

This library simplify integration iPhone and Android application with Amazon services. The latest iOS SDK API is described on this site docs.amazonwebservices.com/AWSiOSSDK/latest. I hope Amazon developers will add other services soon.


Categories

Tags

Comments

TrondTrond

Hi Sebastian. I am trying to use the awsiossdk framework, but I would like to compile it for use with a regular Max OSX application. I have removed all references to UIKit in the files but I was hoping you could have some suggestions for how to compile and link the framework to regular 32/64 bit mac app. Currently I get a linker error:”ld: warning: ignoring file …/AWSiOSSDK.framework/AWSiOSSDK, missing required architecture x86_64 in file”
Thank you! Cheers, Trond