I am a software intern, and I'm working on Java back-end to query a dynamoDB table. We are currently in the process of changing to a new table format. The new table has a business key and a sort key, unlike previous which only used a business key. The following is the method to query the table:
public String getCommuterOptions(String crewID) throws JsonProcessingException {
String hashKey = crewID;
String rangeKey = "E";
CommuterOptionsRequest response = dynamoDBMapper.load(CommuterOptionsRequest.class, hashKey, rangeKey,
DynamoDBMapperConfig.TableNameOverride.withTableNameReplacement(applicationProperties.getProfileTableNm()).config());
return ServiceUtil.convertErrorObjectToJson(response, "Success");
}
Note, the range key for this query needs to be "E".
When I run the application, the following error results:
"Unable to unmarshall exception response with the unmarshallers provided (Service:
AmazonDynamoDBv2; Status Code: 400; Error Code: InvalidSignatureException; Request ID:
6LVEKJAFGBBPM3NB7U4LE60P13VV4KQNSO5AEMVJF66Q9ASUAAJG; Proxy: null)"
Has anyone seen this before? I have tried an alternative way of querying the table using .query() and get the same error. I have double checked things such as system time, and secret key and access key with no success. The old controller is very similarly designed, except for this method, and works perfectly. Any help would be much appreciated.
UPDATE: Dependencies:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<!-- marked the embedded servlet container as provided -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
<version>1.11.330</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180130</version>
</dependency>
<!--<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10</version>
</dependency>-->
</dependencies>
UPDATE 2: I updated the dependencies, and also got new access and secret keys. This along with a slight change to the DTO's annotations for hash and range key fixed the issues. Thank you all for the help.
CodePudding user response:
You are using the very old AWS SDK for Java V1, which is not best practice when using Java to query data from an Amazon DynamoDB table. (AmazonDynamoDBv2 is still part of V1)
The recommended way to query data is to use the AWS SDK for Java v2.
You can read about this SDK in the AWS Java V2 Developer Guide here: