aws-sdk-java-v2
aws-sdk-java-v2 copied to clipboard
dynamodb: Ability to override the table name
Describe the feature
Currently, it seems there are no features to override the DynamoDB table name, like an equivalent to the V1 SDK's DynamoDBMapperConfig.Builder#withTableNameOverride() and DynamoDBMapperConfig.TableNameOverride.withTableNamePrefix() .
This feature is useful to configure the DynamoDBs' table names dynamically. I'd like to use the equivalent function on V2 SDK as well.
Is your Feature Request related to a problem?
This is one of the blockers to upgrade the SDK to v2 from v1 for us.
Proposed Solution
No response
Describe alternatives you've considered
No response
Acknowledge
- [ ] I may be able to implement this feature request
AWS Java SDK version used
2.17.102
JDK version used
openjdk version "11.0.11" 2021-04-20 LTS OpenJDK Runtime Environment Corretto-11.0.11.9.1 (build 11.0.11+9-LTS) OpenJDK 64-Bit Server VM Corretto-11.0.11.9.1 (build 11.0.11+9-LTS, mixed mode)
Operating System and version
Ubuntu 20.04
Thank you for reaching out @moznion, marking as a feature request.
Hi, I need this feature too. How is the progress of this feature request? Is this planned to come in some release in the future?
Hi, I'm currently migrating the SDK from v1 to v2 and just noticed that this feature is missing. This could be a blocker.
I am migrating the SDK from v1 to v2 and this could be blocker.
same. this feature is a blocker for us.
Follow this doc, I could custom the table name as below sample code:
Create a CustomDynamoDbTableNameResolver:
import io.awspring.cloud.dynamodb.DynamoDbTableNameResolver;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Value;
import java.util.Map;
public class CustomDynamoDbTableNameResolver implements DynamoDbTableNameResolver {
@Value("${tables.table1}")
private String table1;
@Value("${tables.table2}")
private String table2;
@NotNull
@Override
public <T> String resolve(@NotNull Class<T> clazz) {
return classTableNameMap().get(clazz);
}
private Map<Class<?>, String> classTableNameMap() {
return Map.of(Table1.class, table1, Table2.class, table2);
}
}
Then declare a bean of type DynamoDbTableSchemaResolver by using CustomDynamoDbTableNameResolver:
@Bean
public DynamoDbTableNameResolver dynamoDbTableNameResolver() {
return new CustomDynamoDbTableNameResolver();
}
Hope this helps!