spring-data-dynamodb
spring-data-dynamodb copied to clipboard
Unable to get by GSI with dynamodb-local
Expected Behavior
When using DynamoLocal for development a call to getByGsi
GSI HashKey returns a List of Items
Actual Behavior
After I moved from derjust/spring-data-dymanodb
to this one I get the following error:
com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException: Cannot do operations on a non-existent table (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ResourceNotFoundException
Steps to Reproduce the Problem
- The model has a composite key and GSI (hash key only)
- Repository with two methods one to find by (PK and SK) the second one to
getByGsi
(global secondary index) - Call using an instance of the repository using the
getByGsi
method
Specifications
- Spring Data DynamoDB Version:
5.2.5
- Spring Data Version:
2.3.2-RELEASE
- AWS SDK Version:
1.11.839
- Java Version:
java 11.0.6 2020-01-14 LTS
- Platform Details: Mac OSX 10.15.6
Starting dynamodb-local like this:
docker run -d -p 8000:8000 amazon/dynamodb-local -jar DynamoDBLocal.jar -inMemory -sharedDb
Hello,
Any information about this issue?, I have the same problem, below my details:
Versions:
- Spring Cloud: 2022.0.1
- Spring Data DynamoDB: 5.2.5
- Java: 17.0.5 2022-10-18 LTS
User.java
@Data
@DynamoDBTable(tableName = "user")
public class User {
@DynamoDBHashKey(attributeName = "Id")
@DynamoDBAutoGeneratedKey
private String id;
@DynamoDBAttribute
@DynamoDBIndexHashKey(globalSecondaryIndexName = "username-index")
private String username;
...
UserRepository.java
@EnableScan
public interface UserRepository extends CrudRepository<User, String> {
Optional<User> findByUsername(String username);
}
DynamoDBConfig.java
@Configuration
@EnableDynamoDBRepositories(basePackageClasses = UserRepository.class)
public class DynamoDBConfig {
private final String env = System.getenv(GenericConstants.ENV_KEY);
@Bean
public AmazonDynamoDB amazonDynamoDB() {
return AmazonDynamoDBClientBuilder.standard().build();
}
@Bean
public DynamoDBMapperConfig.TableNameOverride tableNameOverride() {
return DynamoDBMapperConfig.TableNameOverride.withTableNamePrefix(
GenericConstants.DYNAMODB_TABLENAME_PREFIX + env + "-");
}
@Bean
@Primary
public DynamoDBMapperConfig dynamoDBMapperConfig() {
return DynamoDBMapperConfig.builder().withTableNameOverride(tableNameOverride()).build();
}
@Bean
@Primary
public DynamoDBMapper dynamoDBMapper() {
return new DynamoDBMapper(amazonDynamoDB(), dynamoDBMapperConfig());
}
}
The error is:
com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException: Requested resource not found (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ResourceNotFoundException; Request ID: 6OF2GOG6ADVLP8JA2D3A8H0B8VVV4KQNSO5AEMVJF66Q9ASUAAJG; Proxy: null)