2015-12-14 55 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); 

我希望這可以幫助別人。