The AWS iOS SDK allows writing Swift code to work with DynamoDB and other AWS services.
AWS mobile hub auto-generates a lot of setup code & files for you - specifically you get the file
awsconfiguration.json
and some model files to use with the AWS Object Mapper.
This works well ... until you want to use the very powerful low-level DynamoDB API for a few calls and nothing works.
The AWSSignInManager
and AWSDynamoDBObjectMapper
are high level classes meant to make
using the AWS api's a lot easier. And they do, but when you want to use the low-level calls in DynamoDB
functionality for all its power, then you are blocked by these classes.
In particular its really not clear how to get a credentials provider so that you can set
up your DynamoDB()
low-level calls. Also error messages when you get stuff wrong are completely obscure.
Use the AWS mobile hub to configure your services and make them simple to start off with. Download the MySampleApp
code and get it working first before you try to integrate with your app.
The MySampleApp
code and the SDK uses Swift 3, which seamlessly interoperates with Swift 4 in iOS11 and Xcode 9. But this can mean if you have Swift 4 you don't notice the version mis-match.
Have to put @objcMembers
in front of auto-generated classes as Swift 4 has turned off exposing these members by default. The error is an obscure one about sending empty fields. When AWS fixes this issue in the SDK you can probably remove this work-around. Until then each time your refresh your model classes you'll have to re-instate this hack.
@objcMembers
class RuleDetails: AWSDynamoDBObjectModel, AWSDynamoDBModeling {
var _hashKey: String?
var _rangeKey: String?
var _content: String?
var _lastUse: NSNumber?
var _tags: Set<String>?
var _useCount: NSNumber?
/// other auto-generated AWS Mobile Hub Boilerplate
}
See the getAWSConfig()
function above. The code in the GitHub doco for AWS will work but you have to
hard code information in your source files which was already included in the awsconfiguration.json
file.
Getting information in and out of the API is horrible. See my code in the DBUtils class for putting info in to a low-level post using some attribute helper functions that throw on failure.
Each and every time you change something on your AWS Mobile Hub, re-download the MySampleApp
code generated for you by the AWS Mobile Hub, and copy across the awsconfiguration.json
file from that. Its much more nicely formatted and also if there's issues you can at least know your Sample App should be working off the same configuration.