Migrate "DynamoDBAutoGeneratedKey" to DynamoDbEnhancedClient

0

I am using AWS version 2 and using DynamoDbEnhancedClient for dynamodb operations. I want to have a primary key which should be auto-generated. I see that in previous version of DynamoDB, we have the option of using DynamoDBAutoGeneratedKey annotation for this. But I am not able to find way to configure a auto-generated key with AWS version 2 (DynamoDbEnhancedClient )

Can somebody guide me please.

Thanks,

Satish

Satish
질문됨 2년 전998회 조회
2개 답변
1

This functionality is not yet available for Enhanced Client. I would suggest adding a feature request on the repo: https://github.com/aws/aws-sdk-java-v2/tree/master/services-custom/dynamodb-enhanced

profile pictureAWS
전문가
답변함 2년 전
0

To achieve this in DynamoDbEnhancedClient first we need to activate the extension while creating the DynamoDbEnhancedClient bean. Please find the attached code for your reference

Step 1 :-

public DynamoDbClient getDynamoDbClientForEC2() {
        return DynamoDbClient.builder()
                .region(Region.of(awsRegion))
                .credentialsProvider(InstanceProfileCredentialsProvider.create())
                .endpointOverride(URI.create(awsDynamoDBEndPoint))
                .build();
    }
 @Bean
 @ConditionalOnProperty(prefix = "aws", name = "access.secured", havingValue = "enabled")
    public DynamoDbEnhancedClient getDynamoDbEnhancedClientForEC2() {
        return DynamoDbEnhancedClient.builder()
                .dynamoDbClient(getDynamoDbClientForEC2())
                .extensions(AutoGeneratedTimestampRecordExtension.create(), AutoGeneratedUuidExtension.create())
                .build();
    }

Step 2 :- Finally, you can tell DynamoDbEnhancedClient to autogenerate the key for you in the entity class,

@DynamoDbBean
public class MyEntity {
private String myPartionKey;

 @DynamoDbPartitionKey
 @DynamoDbAutoGeneratedUuid 
    public String getMyPartionKey() {
        return myPartionKey;
    }
}
답변함 4달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠