Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get by GSI with dynamodb-local #78

Open
onema opened this issue Aug 13, 2020 · 1 comment
Open

Unable to get by GSI with dynamodb-local #78

onema opened this issue Aug 13, 2020 · 1 comment

Comments

@onema
Copy link

onema commented Aug 13, 2020

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                                       
@jhmz333
Copy link

jhmz333 commented Feb 22, 2023

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants