You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have my dev and stage env in one AWS region and I am using the suffix _dev and _stage to tables.
Is there any way to add this suffix in runtime to @DynamoDBTable()?
Actual Behavior
I tried to override the value using TableNameResolver but the override method is not getting called. also, I tried with Spring expression to evaluate the expression but that is also not working.
Would appreciate any help. Thanks
The text was updated successfully, but these errors were encountered:
Hi You can achieve this by making a table name resolver
@Component
public class TableNameResolver extends DynamoDBMapperConfig.DefaultTableNameResolver {
private String env;
public TableNameResolver() {
}
public TableNameResolver(String envProfile) {
this.env = envProfile;
}
@Override
public String getTableName(Class<?> clazz, DynamoDBMapperConfig config) {
String stageName = env;
String rawTableName = super.getTableName(clazz, config);
return String.join("_", rawTableName, stageName);
}
}
in the class where you are creating dynamo db bean just pass env value (the env value can be saved at application yml for respective environments)
@Value("${env}")
private String env;
and create a dbmapper like this
@Bean
@Primary
public DynamoDBMapper dynamoDBMapper(AmazonDynamoDB amazonDynamoDB) {
return new DynamoDBMapper(amazonDynamoDB, new DynamoDBMapperConfig.Builder().withTableNameResolver(new TableNameResolver(env)).build());
}
and now for table entities just provide the base name for the table and it will automatically append the env at the end of the table name.
Expected Behavior
I have my dev and stage env in one AWS region and I am using the suffix
_dev and _stage
to tables.Is there any way to add this suffix in runtime to @DynamoDBTable()?
Actual Behavior
I tried to override the value using TableNameResolver but the override method is not getting called. also, I tried with Spring expression to evaluate the expression but that is also not working.
Would appreciate any help. Thanks
The text was updated successfully, but these errors were encountered: