Nitin
Nitin

Reputation: 151

Error using Amazon DynamoDB in Android application (ResourceNotFoundException)

I'm trying to follow along this guide without much success. I have created the appropriate IAM role and attached the proper role policy to that role, and I have created a DyanmoDB table called "TaskShareGroups" with Primary Partition key "Group Name" (a String).

I have set up my class as follows:

@DynamoDBTable(tableName = "TaskShareGroups")
public class Group implements Parcelable {

String name;

public Group(String name) {
    this.name = name;
}

@Override
public String toString() {
    return name;
}

@DynamoDBHashKey(attributeName = "Group Name")
public String getName() {
    return name;
}

Here is my code trying to write a Group object to the database.

Runnable saveGroup = new Runnable() {
    public void run() {
        try {
            mapper.save(g);
        } catch (Exception e) {
            Log.e(TAG, e.getMessage());
        }
    }
};
CognitoCachingCredentialsProvider credentials =
               new CognitoCachingCredentialsProvider(
                       getApplicationContext(),
                       identity_pool_ID,                    
                       Regions.US_EAST_2);


ddbClient = new AmazonDynamoDBClient(credentials);
mapper = new DynamoDBMapper(ddbClient);
g = new Group(gName);

Thread mythread = new Thread(saveGroup);
mythread.start();

The error I get when I run this:

Requested resource not found (Service: AmazonDynamoDB; Status Code: 400; Error Code: ResourceNotFoundException; Request ID: NPBOR9KLFA7T5RLQOID7F7T3KNVV4KQNSO5AEMVJF66Q9ASUAAJG)

I am not quite sure what is going on. I'm not entirely sure I set up my unauthenticated role correctly; my exception seems to indicate that it's having trouble finding the correct table but I can clearly see the table through the console.

Android Studio is also telling me that the constructor I am using for my DynamoDBMapper is depreciated; however this is the approach suggested by the guide above. Could this be the issue?

Let me know if there is any other pertinent information I should add to this document.

Upvotes: 0

Views: 114

Answers (1)

Rohan Dubal
Rohan Dubal

Reputation: 847

You should set your region correctly using the setRegion API on the AmazonDynamoDBClient client. The following is the link to the API reference: http://docs.aws.amazon.com/AWSAndroidSDK/latest/javadoc/com/amazonaws/services/dynamodbv2/AmazonDynamoDB.html#setRegion-com.amazonaws.regions.Region-

Make sure you set the region correctly to where your table is.

Thanks, Rohan

Upvotes: 1

Related Questions