spring-data-dynamodb icon indicating copy to clipboard operation
spring-data-dynamodb copied to clipboard

Unable to get by GSI with dynamodb-local

Open onema opened this issue 4 years ago • 1 comments

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

  1. The model has a composite key and GSI (hash key only)
  2. Repository with two methods one to find by (PK and SK) the second one to getByGsi (global secondary index)
  3. 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                                       

onema avatar Aug 13 '20 00:08 onema

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)

jhmz333 avatar Feb 22 '23 16:02 jhmz333