通过maven运行本地版本的dynamodb时出现身份验证错误

时间:2015-12-14 19:46:26

标签: java maven amazon-dynamodb

我正在使用Maven启动DynamoDb的本地副本进行测试 对于那些感兴趣的人,我在这里复制了说明 https://thecarlhall.wordpress.com/2015/11/14/integration-testing-with-dynamodb-locally/(我已将它们添加到此问题的末尾)。

问题是,当我尝试创建访问本地版Dynamo的客户端时,出现错误:

AmazonServiceException: The request signature we calculated does not match the signature you provided

我读过的所有内容都表明在使用本地dynamoDb时不会检查这个秘密,所以我怀疑无论出于何种原因,我正在访问我的真正的dynamodb。谁能看到我做错了什么?

AWSCredentials credentials = new BasicAWSCredentials(myAccessKey, "localTest");
AmazonDynamoDBClient client = new AmazonDynamoDBClient(credentials);

client.setEndpoint(dynamo.endpoint);
client.setRegion(Region.getRegion(Regions.EU_WEST_1));

顺便说一句,setRegion也是如此。我应该可以将它设置为“本地”,但除非我设置一个真实的区域,否则它会失败。

我在IntelliJ中运行我的测试,maven设置如下:

<plugin>
    <groupId>com.googlecode.maven-download-plugin</groupId>
    <artifactId>download-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <id>install-dynamodb_local</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>wget</goal>
            </goals>
            <configuration>
                <url>http://dynamodb-local.s3-website-${aws.s3.region}.amazonaws.com/dynamodb_local_latest.zip</url>
                <unpack>true</unpack>
                <outputDirectory>${project.build.directory}/dynamodb</outputDirectory>
            </configuration>
        </execution>
    </executions> 
</plugin> 
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.9.1</version>
    <executions>
        <execution>
            <goals>
                <goal>reserve-network-port</goal>
            </goals>
            <phase>initialize</phase>
            <configuration>
                <portNames>
                    <portName>dynamodblocal.port</portName>
                </portNames>
            </configuration>
        </execution>
    </executions> 
</plugin> 
<plugin>
    <groupId>com.bazaarvoice.maven.plugins</groupId>
    <artifactId>process-exec-maven-plugin</artifactId>
    <version>0.7</version>
    <executions>
        <execution>
            <id>dynamodb_local</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>start</goal>
            </goals>
            <configuration>
                <name>dynamodb_local</name>
                <waitAfterLaunch>1</waitAfterLaunch>
                <arguments>
                    <argument>java</argument>
                    <argument>-Djava.library.path=dynamodb/DynamoDBLocal_lib</argument>
                    <argument>-jar</argument>
                    <argument>dynamodb/DynamoDBLocal.jar</argument>
                    <argument>-port</argument>
                    <argument>${dynamodblocal.port}</argument>
                    <argument>-sharedDb</argument>
                    <argument>-inMemory</argument>
                </arguments>
            </configuration>
        </execution>
    </executions> 
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins </groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19</version>
    <configuration>
        <systemPropertyVariables>
            <dynamo.endpoint>http://localhost:${dynamodblocal.port}</dynamo.endpoint>
        </systemPropertyVariables>
    </configuration> 
</plugin>

1 个答案:

答案 0 :(得分:0)

我终于跟踪了这一点 我的代码有以下内容:

client.setEndpoint(dynamo.endpoint);
client.setRegion(Region.getRegion(Regions.EU_WEST_1));

setRegion的未记录效果是它将endPoint重置为亚马逊。通过交换这两个语句(如下所示),我解决了这个问题。

client.setRegion(Region.getRegion(Regions.EU_WEST_1));
client.setEndpoint(dynamo.endpoint);

我希望这有助于某人。