3
votes

compared to Parse, AWS has a bit of learning curve :)

  • I created a table in dynamodb called "dynamotest"
  • IAM shows that I have the following role (policygen-Cognito_awst1Unauth_Role-201603071632) defined:

{ "Version": "2012-10-17", "Statement": [ { "Sid": "Stmt1457368244000", "Effect": "Allow", "Action": [ "dynamodb:*" ], "Resource": [ "arn:aws:dynamodb:eu-west-1:579313493028:table/dynamotest" ] } ] }

in the Xamarin app I have the following code:

// test access to Dynamo

        var client = new AmazonDynamoDBClient(credentials, RegionEndpoint.EUWest1);

        Table table = Table.LoadTable(client, "dynamotest");

        var book = new Document();
        book["Id"] = 101;
        book["Title"] = "Book 101 Title";
        book["ISBN"] = "11-11-11-11";
        book["Authors"] = new List<string> { "Author 1", "Author 2" };
        book["InStock"] = new DynamoDBBool(true);
        book["QuantityOnHand"] = new DynamoDBNull();


        table.PutItemAsync(book);

"credentials" are the Cognito credentials for unauthenticated useder created with the Cognito identity pool id. Cognito-Synching with those credentials works fine.

Running this code there is no data put in the table.I also tried using the object persistence model with the same result.

What step(s) am I missing? There is no error - if the data wasn't missing from the table I wouldn't even know that something was wrong.

So two questions: 1/ How do enable access to Dynamodb for the unauthenticated Cognito users. Do I need to create some arbitrary user and attach the role/policy??? Is there an issue with the Regionpoint (as I am in Europe)?

2/ How can I check for errors/problems using the AWS SDK for Xamarin??

Please help - thanks!!

1

1 Answers

1
votes

The general flow to use dynamodb with unauthenticated Cogntio identity is that you create an identity pool and modify the auto generated unauth policy to a new policy which allows access to your dynamodb table. You can then use Cogntio credentials for unauthenticated identity to perform operations against dynamodb.

If you could change your 'table.PutItemAsync(book) to 'await table.PutItemAsync(book)' and then wrap that code in a try/catch block, it will catch the service exceptions which you can then log and debug what's the actual error.

Here are some documentations specific to your use case to use DynamoDb with Cogntio

http://docs.aws.amazon.com/mobile/sdkforandroid/developerguide/dynamodb_om.html http://docs.aws.amazon.com/mobile/sdkforxamarin/developerguide/dynamodb-integration-docmodel.html