0

I am trying to setup alternatorDB to develop a DynamoDB based application, but I'm getting this error while trying to establish a connection: I've provided the code, error and the pom.xml of the project below. Alternator is running as a standalone service.

I'm using the depracated Amazon SDK because the Alternator DB Client doesn't seem to accept objects from the new SDK com.amazonaws.services.dynamodbv2

By the way, I'm completely new to Amazon and Maven. Please do point out if the description provided in inadequate or unspecific. Thanks!

Source Code:

this.client = new AlternatorDBClient();

    // Create a table with a primary key named 'name', which holds a string

    ProvisionedThroughput thorughput = new ProvisionedThroughput().withReadCapacityUnits(10L).withWriteCapacityUnits(5L);
    KeySchemaElement schemaElement = new KeySchemaElement().withAttributeName("Name").withAttributeType("String");

    CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(TOPIC_TABLE).withProvisionedThroughput(thorughput);
    client.createTable(createTableRequest);

Error:

Exception in thread "main" AmazonServiceException: Status Code: 400, AWS Service: AmazonDynamoDB, AWS Request ID: null, AWS Error Code: AmazonServiceException, AWS Error Message: [java.lang.Error: property value is null.]
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.michelboudreau.alternator.AlternatorDBClient.invoke(AlternatorDBClient.java:212)
at com.michelboudreau.alternator.AlternatorDBClient.createTable(AlternatorDBClient.java:137)
at Main.run(Main.java:35)
at Main.main(Main.java:23)

And here's the pom.xml from the project:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.project</groupId>
<artifactId>AlternatorTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>AlternatorTest</name>

<dependencies>
    <dependency>
        <groupId>com.michelboudreau</groupId>
        <artifactId>alternator</artifactId>
        <version>0.5.0</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk</artifactId>
        <version>1.4.4.2</version>
    </dependency>
</dependencies>
<repositories>
    <repository>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <releases>
            <enabled>true</enabled>
        </releases>
        <id>sonatype-nexus</id>
        <url>https://oss.sonatype.org/content/groups/public</url>
    </repository>
</repositories>

J_A_X
  • 12,857
  • 1
  • 25
  • 31
EternallyCurious
  • 2,345
  • 7
  • 47
  • 78

2 Answers2

1

There are two bugs in the code -

  1. String scalar type is denoted by just the character S
  2. The key schema element is not included in the table definition.

Here is the fixed code -

    ProvisionedThroughput thorughput = new ProvisionedThroughput().withReadCapacityUnits(10L).withWriteCapacityUnits(5L);
    KeySchemaElement schemaElement = new KeySchemaElement().withAttributeName("Name").withAttributeType(ScalarAttributeType.S);

    CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(TOPIC_TABLE).withProvisionedThroughput(thorughput).withKeySchema(new KeySchema(schemaElement));
    client.createTable(createTableRequest);
abhin
  • 26
  • 2
1

Instead you can run Amazon DynamoDB locally and simulate your work in hassle-free manner

http://aws.typepad.com/aws/2013/09/dynamodb-local-for-desktop-development.html

deepakmodak
  • 1,329
  • 13
  • 16