aws-sdk-java-v2 icon indicating copy to clipboard operation
aws-sdk-java-v2 copied to clipboard

dynamodb: Ability to override the table name

Open moznion opened this issue 2 years ago • 2 comments

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

moznion avatar Dec 22 '21 05:12 moznion

Thank you for reaching out @moznion, marking as a feature request.

debora-ito avatar Jan 13 '22 22:01 debora-ito

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?

3Fish avatar Apr 13 '22 12:04 3Fish

Hi, I'm currently migrating the SDK from v1 to v2 and just noticed that this feature is missing. This could be a blocker.

pefischerhro avatar Mar 23 '23 08:03 pefischerhro

I am migrating the SDK from v1 to v2 and this could be blocker.

dmadroja avatar Apr 18 '23 06:04 dmadroja

same. this feature is a blocker for us.

wenzhang0220 avatar Aug 28 '23 06:08 wenzhang0220

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!

diep-it-dn avatar Aug 29 '23 03:08 diep-it-dn