2015-12-14 53 views
0

我正在使用Maven启动DynamoDb的本地副本进行测试。
对于那些有兴趣,我已经复制了这里的说明 https://thecarlhall.wordpress.com/2015/11/14/integration-testing-with-dynamodb-locally/(我已经将它们添加到这个问题的最后)。当使用通过maven运行本地版本的dynamodb时获取身份验证错误

我读过
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> 

回答

0

我终于跟踪下来。
我的代码有以下几点:

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

setRegion的无证效果是,它重置端点回亚马逊。通过交换这两个陈述(如下),我解决了这个问题。

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

我希望这可以帮助别人。