Dynamic specification of index name on @DynamoDbSecondaryPartitionKey annotation
- Dominant language
- Java
- Stars
- 2.6k
- Forks
- 1k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 51
Description
### Describe the feature
Provide the ability to dynamically specify the name of the index when using the @DynamoDbSecondaryPartitionKey which today only allows for static definition of the index name.
### Use Case
I need to be able to dynamically provide the name of the index in a Spring Boot application since our index names have an environment name component to them. Currently the @DynamoDbSecondaryPartitionKey annotation requires a static name of the index so this is not possible.
### Proposed Solution
Establish a new DynamoDbSecondaryIndexNameProvider interface and update the annotation to accept a static name or any implementing class of DynamoDbSecondaryIndexNameProvider so the name can be determined at runtime.
**Domain Object**
```
@DyanmoDbBean
public class DomainObject {
@DynamoDbPartitionKey
@DynamoDbAttribute("key")
private String key;
@DynamoDbAttribute("secondary_index_key")
@DynamoDbSecondaryPartitionKey(indexNames = "secondary_index_gsi")
private String secondaryIndexKey;
}
```
**Interface for index name provider**
Default implementation acts as a passthrough which provides current behavior of annotation
```
public interface IndexNameResolver {
default String getIndexName(String indexStaticName) {
return indexStaticName;
}
}
```
**User defined implementation**
```
@Service
public class DynamicIndexNameResolverImpl implements IndexNameResolver {
@Autowired
private Environment environment;
@Override
public String getIndexName(final String indexStaticName) {
/*
* user defined logic for deriving the actual index name from the static value provided in the annotation
* essentially treating the value as a lookup key instead of the actual name.
*/
}
}
```
**User defined Spring bean configuration**
```
@Bean
public DynamoDbEnhancedClient dynamoDbEnhancedClient(final DynamoDbClient dynamoDbClient, final IndexNameResolver indexNameResolver) {
return DynamoDbEnhancedClient.builder()
.dynamoDbClient(dynamoDbClient)
.indexNameResolver(indexNameResolver) // Enhanced client would be modified to accept the custom resolver implementation
.build();
}
```
### Other Information
_No response_
### Acknowledgements
- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
### AWS Java SDK version used
2.31.77
### JDK version used
21
### Operating System and version
macOS Sequoia 15.5
Contributor guide
Research direction
Start by tracing how @DynamoDbSecondaryPartitionKey indexNames are consumed by the Enhanced Client and where DynamoDbEnhancedClient builder configuration is defined. Evaluate the proposed provider interface and its interaction with annotation metadata and client construction. Done means callers can supply a resolver that derives runtime index names while existing static-name behavior remains supported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, java
- Domain
- database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100