Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can not mapping entity when using AWS DynamoDB

I am begin with dynamoDB. I using annotion mapping enity follow :

@DynamoDBTable(tableName = "ProductCatalogz")
public static class Book {
    private int id;+
    private String title;+
    private String ISBN;+
    private Set<String> bookAuthors;+

    // private DimensionType dimensionType;

    @DynamoDBHashKey(attributeName = "Id")
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @DynamoDBAttribute(attributeName = "Title")
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @DynamoDBAttribute(attributeName = "ISBN")
    public String getISBN() {
        return ISBN;
    }

    public void setISBN(String ISBN) {
        this.ISBN = ISBN;
    }
}

and

public static void main(String[] args) throws IOException {
    AWSCredentials credentials = new PropertiesCredentials(
     Tester2.class.getResourceAsStream("/AwsCredentials.properties"));

     client = new AmazonDynamoDBClient(credentials);
     Region usWest2 = Region.getRegion(Regions.US_EAST_1);
     client.setRegion(usWest2);

     Book book = new Book();
     book.setId(1);
     book.setTitle("Book 502");
     book.setISBN("5555555555555");
     book.setBookAuthors(new HashSet<String>(Arrays.asList("Author1",
         "Author2")));
     // book.setDimensions(dimType);

     DynamoDBMapper mapper = new DynamoDBMapper(client);
     mapper.save(book);
}

But when I run this error :

Exception in thread "main" ResourceNotFoundException: Status Code: 400, AWS Service: AmazonDynamoDBv2, AWS Request ID: NSG3K0BQOBCPNQONE8, AWS Error Code: ResourceNotFoundException, AWS Error Message: Requested resource not found
at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:644)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:338)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:190)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.invoke(AmazonDynamoDBClient.java:1245)
at com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient.updateItem(AmazonDynamoDBClient.java:1026)
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.save(DynamoDBMapper.java:636)
at com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.save(DynamoDBMapper.java:483)
at test.Tester2.main(Tester2.java:47)

please help me

like image 578
nguyenthienphuc Avatar asked Jun 07 '13 03:06

nguyenthienphuc


2 Answers

The message Requested resource not found means that Dynamo DB table is not found. You should create it first through AWS console, API, or CLI.

like image 151
yegor256 Avatar answered Oct 06 '22 01:10

yegor256


Ensure that you have set the endpoint on the client

BasicAWSCredentials b = new BasicAWSCredentials("Access Key ID","Secret Access Key");           
AmazonDynamoDBClient client = new AmazonDynamoDBClient(b);
client.setEndpoint("dynamodb.ap-northeast-1.amazonaws.com");    

Refer http://docs.aws.amazon.com/general/latest/gr/rande.html#ddb_region for the complete list of End Points for DynamoDB

like image 22
Sagar Mhatre Avatar answered Oct 05 '22 23:10

Sagar Mhatre