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:
- Amazon Simple Storage Service (storage)
- Amazon SimpleDB (database)
- Amazon Simple Notification Service (notification)
- Amazon Simple Queue Service (messages)
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
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.
OK, now we are ready to start our project.
- Start Xcode.
- Choose: Create a new Xcode project.
- Choose: Split View-base Application.
- Give name to your project.
- 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.
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.