[英]getting authentication errors when running a local version of dynamodb via maven
I'm using Maven to start a local copy of DynamoDb for testing. 我正在使用Maven启动DynamoDb的本地副本以进行测试。
For those that are interested, I've copied the instructions here https://thecarlhall.wordpress.com/2015/11/14/integration-testing-with-dynamodb-locally/ (and I've added them to the end of this question). 对于那些感兴趣的人,我已经在这里复制了说明https://thecarlhall.wordpress.com/2015/11/14/integration-testing-with-dynamodb-locally/ (并且我已经将它们添加到这个问题)。
The problem is, when I try and create a client that accesses the local version of Dynamo, I get an error: 问题是,当我尝试创建访问Dynamo本地版本的客户端时,出现错误:
AmazonServiceException: The request signature we calculated does not match the signature you provided
Everything that I've read says that the secret is not checked when using a local dynamoDb, so my suspicion is that, for whatever reason, i'm accessing my real dynamodb. 我读过的所有内容都说,使用本地dynamoDb时不会检查秘密,因此我怀疑由于某种原因,我正在访问我的真正的dynamodb。 Can anyone see what i'm doing wrong?
谁能看到我在做什么错?
AWSCredentials credentials = new BasicAWSCredentials(myAccessKey, "localTest");
AmazonDynamoDBClient client = new AmazonDynamoDBClient(credentials);
client.setEndpoint(dynamo.endpoint);
client.setRegion(Region.getRegion(Regions.EU_WEST_1));
Btw, the same is true for the setRegion. 顺便说一句,对于setRegion也是如此。 I should be able to set it to "local" but it's failing unless I set a real region.
我应该能够将其设置为“ local”,但是除非我设置了真实区域,否则它会失败。
I'm running my tests in IntelliJ, the maven setup is as follows: 我在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>
I finally tracked this down. 我终于找到了答案。
My code has the following: 我的代码具有以下内容:
client.setEndpoint(dynamo.endpoint);
client.setRegion(Region.getRegion(Regions.EU_WEST_1));
An undocumented effect of setRegion is that it resets the endPoint back to amazon. setRegion的未记录效果是它将endPoint重设回亚马逊。 By swapping these two statements around (as below), I resolved the problem.
通过围绕这两个语句进行交换(如下所示),我解决了该问题。
client.setRegion(Region.getRegion(Regions.EU_WEST_1));
client.setEndpoint(dynamo.endpoint);
I hope this helps someone. 我希望这可以帮助别人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.