michaellavelle / spring-data-dynamodb

Simplifies the development of creating an Amazon DynamoDB-based Java data access layer
https://derjust.github.io/spring-data-dynamodb/
Apache License 2.0
169 stars 284 forks source link

Pass in table name via context or environment variable #65

Closed ujjwal closed 4 years ago

ujjwal commented 9 years ago
@DynamoDBTable(tableName = "someTableName")

Is there a way to pass the tableName as a parameter?

derjust commented 8 years ago

Yes via AWS functionality itself:

@Configuration
@EnableDynamoDBRepositories(dynamoDBMapperConfigRef = "dynamoDBMapperConfig",
    basePackages = "com.acme.repository")
public class DynamoDBConfig {
    @Bean
    public DynamoDBMapperConfig dynamoDBMapperConfig() {
        DynamoDBMapperConfig.Builder builder = new DynamoDBMapperConfig.Builder();
        builder.setTableNameResolver(new YourCustomTableNameResolverHere());
        return builder.build();
    }
}

If you just wan to prefix table names (to separate environments), there are ready-to go classes:

builder.setTableOverride(
        com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapperConfig.TableNameOverride.withTableNamePrefix("dev"));
derjust commented 8 years ago

Please let us know if the provided answer helps your use case. Please use https://github.com/derjust/spring-data-dynamodb/issues/18 for followup comments.

As (privately) communicated with @michaellavelle, the project will continue under https://github.com/derjust/spring-data-dynamodb.

derjust commented 8 years ago

Check out https://github.com/derjust/spring-data-dynamodb/wiki/Alter-table-name-during-runtime

AliakseiMat commented 7 years ago

Not sure maybe it is the bug in AWS lib. I'm using "aws-java-sdk-bom" 1.11.175. The problem is when I use my own DynamoDBMapperConfig, then config.getTypeConverterFactory() is the null and internal error thrown.
I have added: builder.setTypeConverterFactory(DynamoDBMapperConfig.DEFAULT.getTypeConverterFactory());