Wednesday, 11 September 2013

ios dynamodb not registering tables properly

ios dynamodb not registering tables properly

I downloaded the user preferences example (for Xcode) from the amazon
site. I inserted my keys in the code as requested. Then run the app. It is
supposed to create a table called TestUserPrefence. It seems to do this
correctly in the app, because the app works fine after creating the table
and inserting the data; however, when you go to the AWS console for
dynamoDB, the table has not been created. Also, when I quit the app and
run it again, the table is gone and I have to re-create it.
So how do I add tables in objective c that stick around and that are
visible to the aws console?
Here is the code that is supposed to create the tables (copied from the
example).
#define TEST_TABLE_NAME @"TestUserPreference"
#define TEST_TABLE_HASH_KEY @"userNo"
+(void)createTable
{
DynamoDBCreateTableRequest *createTableRequest =
[[DynamoDBCreateTableRequest new] autorelease];
DynamoDBProvisionedThroughput *provisionedThroughput =
[[DynamoDBProvisionedThroughput new] autorelease];
provisionedThroughput.readCapacityUnits = [NSNumber numberWithInt:10];
provisionedThroughput.writeCapacityUnits = [NSNumber numberWithInt:5];
DynamoDBKeySchemaElement *keySchemaElement = [[[DynamoDBKeySchemaElement
alloc] initWithAttributeName:TEST_TABLE_HASH_KEY
andKeyType:@"HASH"]
autorelease];
DynamoDBAttributeDefinition *attributeDefinition =
[[DynamoDBAttributeDefinition new] autorelease];
attributeDefinition.attributeName = TEST_TABLE_HASH_KEY;
attributeDefinition.attributeType = @"N";
createTableRequest.tableName = TEST_TABLE_NAME;
createTableRequest.provisionedThroughput = provisionedThroughput;
[createTableRequest addKeySchema:keySchemaElement];
[createTableRequest addAttributeDefinition:attributeDefinition];
DynamoDBCreateTableResponse *response = [[AmazonClientManager ddb]
createTable:createTableRequest];
if(response.error != nil)
{
[AmazonClientManager wipeCredentialsOnAuthError:response.error];
NSLog(@"Error: %@", response.error);
}
}
More info: I found out that the table was getting created on a different
server (North Virginia for some reason) than the one I was looking at on
the console (defaulted to Oregon). Apparently you have to create the table
in the console on the server your app is going to use; however, there
doesn't seem to be a way to set this.

No comments:

Post a Comment