尝试连接交流发电机(Simo for DynamoDB)

时间:2013-05-27 12:14:07

标签: java amazon-dynamodb alternator

我正在尝试设置alternatorDB来开发基于DynamoDB的应用程序,但是在尝试建立连接时我遇到了这个错误:我已经提供了下面项目的代码,错误和pom.xml。 Alternator作为独立服务运行。

我正在使用depracated Amazon SDK,因为Alternator DB Client似乎不接受新SDK中的对象com.amazonaws.services.dynamodbv2

顺便说一下,我对Amazon和Maven完全不熟悉。如果提供的描述不充分或不明确,请指出。谢谢!

源代码:

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);

错误:

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)

这是项目中的pom.xml:

<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>

2 个答案:

答案 0 :(得分:1)

代码中有两个错误 -

  1. 字符串标量类型仅由字符S
  2. 表示
  3. 表格定义中不包含密钥架构元素。
  4. 这是固定代码 -

        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);
    

答案 1 :(得分:1)

相反,您可以在本地运行Amazon DynamoDB并以轻松的方式模拟您的工作

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