I’ve been struggling with connecting to the AWS DynamoDB with my iOS app. I am frustrated with the lack of tutorials/documentation on the DynamoDB (I guess it is still fairly new). But I ahve been trying to follow Amazon’s User Preference Tutorial I am trying to just connect to the database and read something or write something but I am getting an exception thrown.
AmazonCredentials *creds;
creds = [creds initWithAccessKey:MY_ACCESS_KEY withSecretKey:MY_SECRET_KEY];
AmazonDynamoDBClient *ddb = [[AmazonDynamoDBClient alloc] initWithCredentials:creds];
DynamoDBGetItemRequest *request = [[DynamoDBGetItemRequest alloc]
initWithTableName:@"Users" andKey:[[DynamoDBKey alloc] initWithHashKeyElement:
[[DynamoDBAttributeValue alloc] initWithS:@"Chase"]]];
DynamoDBGetItemResponse *response = [ddb getItem:request]; //THROWING THE EXCEPTION HERE!
NSMutableDictionary *user = response.item;
NSLog(@"%@",user);
The output reads:
Terminating app due to uncaught exception ‘AmazonServiceException’, reason: ”
The only thing that I changed from what the tutorial has done is the way I set up my user credentials and the line that throws the exception, the tutorial has:
DynamoDBCreateTableResponse *response = [[AmazonClientManager ddb] getItem:request];
I couldn’t find any AmazonClientManager class anywhere, but the AmazonDynamoDBClient class seems to have the same method, so I am assuming that it should work (this could very well be the assumption that is breaking my code). I don’t know if Amazon still supports that class because I can’t find it in any documentation either.
Also, before I get yelled at, I know that I shouldn’t be handing out my own credentials in the app. I will change this later. I am just trying to get to a sanity state for now.
You need to change these lines
to this
Also, AmazonClientManager is not a part of the SDK. It’s a part of the sample app and returns an instance of AmazonDynamoDBClient. It’s included in the sample project.