1
1
package com .launchdarkly .client .dynamodb ;
2
2
3
- import com .amazonaws .ClientConfiguration ;
4
- import com .amazonaws .auth .AWSCredentialsProvider ;
5
- import com .amazonaws .client .builder .AwsClientBuilder ;
6
- import com .amazonaws .regions .Regions ;
7
- import com .amazonaws .services .dynamodbv2 .AmazonDynamoDB ;
8
- import com .amazonaws .services .dynamodbv2 .AmazonDynamoDBClient ;
9
- import com .amazonaws .services .dynamodbv2 .AmazonDynamoDBClientBuilder ;
10
3
import com .launchdarkly .client .FeatureStore ;
11
4
import com .launchdarkly .client .FeatureStoreCacheConfig ;
12
5
import com .launchdarkly .client .FeatureStoreFactory ;
15
8
16
9
import java .net .URI ;
17
10
11
+ import software .amazon .awssdk .auth .credentials .AwsCredentialsProvider ;
12
+ import software .amazon .awssdk .core .client .config .ClientOverrideConfiguration ;
13
+ import software .amazon .awssdk .regions .Region ;
14
+ import software .amazon .awssdk .services .dynamodb .DynamoDbClient ;
15
+ import software .amazon .awssdk .services .dynamodb .DynamoDbClientBuilder ;
16
+
18
17
/**
19
18
* Builder/factory class for the DynamoDB feature store.
20
19
* <p>
25
24
* The AWS SDK provides many configuration options for a DynamoDB client. This class has
26
25
* corresponding methods for some of the most commonly used ones. If you need more sophisticated
27
26
* control over the DynamoDB client, you can construct one of your own and pass it in with the
28
- * {@link #existingClient(AmazonDynamoDB )} method.
27
+ * {@link #existingClient(DynamoDbClient )} method.
29
28
*/
30
29
public class DynamoDbFeatureStoreBuilder implements FeatureStoreFactory {
31
30
private final String tableName ;
32
31
33
32
private String prefix ;
34
- private AmazonDynamoDB existingClient ;
35
- private AmazonDynamoDBClientBuilder clientBuilder ;
33
+ private DynamoDbClient existingClient ;
34
+ private DynamoDbClientBuilder clientBuilder ;
36
35
37
36
private FeatureStoreCacheConfig caching = FeatureStoreCacheConfig .DEFAULT ;
38
37
39
38
DynamoDbFeatureStoreBuilder (String tableName ) {
40
39
this .tableName = tableName ;
41
- clientBuilder = AmazonDynamoDBClient .builder ();
40
+ clientBuilder = DynamoDbClient .builder ();
42
41
}
43
42
44
43
@ Override
45
44
public FeatureStore createFeatureStore () {
46
- AmazonDynamoDB client = (existingClient != null ) ? existingClient : clientBuilder .build ();
45
+ DynamoDbClient client = (existingClient != null ) ? existingClient : clientBuilder .build ();
47
46
DynamoDbFeatureStoreCore core = new DynamoDbFeatureStoreCore (client , tableName , prefix );
48
47
CachingStoreWrapper wrapper = CachingStoreWrapper .builder (core ).caching (caching ).build ();
49
48
return wrapper ;
@@ -55,8 +54,8 @@ public FeatureStore createFeatureStore() {
55
54
* @param config an AWS client configuration object
56
55
* @return the builder
57
56
*/
58
- public DynamoDbFeatureStoreBuilder clientConfiguration ( ClientConfiguration config ) {
59
- clientBuilder .setClientConfiguration (config );
57
+ public DynamoDbFeatureStoreBuilder clientOverrideConfiguration ( ClientOverrideConfiguration config ) {
58
+ clientBuilder .overrideConfiguration (config );
60
59
return this ;
61
60
}
62
61
@@ -67,49 +66,36 @@ public DynamoDbFeatureStoreBuilder clientConfiguration(ClientConfiguration confi
67
66
* @param credentialsProvider a source of credentials
68
67
* @return the builder
69
68
*/
70
- public DynamoDbFeatureStoreBuilder credentials (AWSCredentialsProvider credentialsProvider ) {
71
- clientBuilder .setCredentials (credentialsProvider );
69
+ public DynamoDbFeatureStoreBuilder credentials (AwsCredentialsProvider credentialsProvider ) {
70
+ clientBuilder .credentialsProvider (credentialsProvider );
72
71
return this ;
73
72
}
74
73
75
74
/**
76
- * Sets the service endpoint and AWS region to use. Normally, you will not use this, as AWS
77
- * determines the service endpoint based on your region. However, you can set it explicitly if
78
- * you are running your own DynamoDB instance.
75
+ * Sets the service endpoint to use. Normally, you will not use this, as AWS determines the
76
+ * service endpoint based on your region. However, you can set it explicitly if you are
77
+ * running your own DynamoDB instance.
79
78
*
80
79
* @param endpointUri the custom endpoint URI
81
- * @param region the AWS region name
82
80
* @return the builder
83
81
*/
84
- public DynamoDbFeatureStoreBuilder endpointAndRegion (URI endpointUri , String region ) {
85
- clientBuilder .setEndpointConfiguration ( new AwsClientBuilder . EndpointConfiguration ( endpointUri . toString (), region ) );
82
+ public DynamoDbFeatureStoreBuilder endpoint (URI endpointUri ) {
83
+ clientBuilder .endpointOverride ( endpointUri );
86
84
return this ;
87
85
}
88
86
89
87
/**
90
88
* Sets the AWS region to use. If you do not set this, AWS will attempt to determine it from
91
89
* environment variables and/or local configuration files.
92
90
*
93
- * @param region the AWS region name
91
+ * @param region the AWS region
94
92
* @return the builder
95
93
*/
96
- public DynamoDbFeatureStoreBuilder region (String region ) {
97
- clientBuilder .setRegion (region );
94
+ public DynamoDbFeatureStoreBuilder region (Region region ) {
95
+ clientBuilder .region (region );
98
96
return this ;
99
97
}
100
98
101
- /**
102
- * Sets the AWS region to use. If you do not set this, AWS will attempt to determine it from
103
- * environment variables and/or local configuration files.
104
- *
105
- * @param region the AWS region enum
106
- * @return the builder
107
- */
108
- public DynamoDbFeatureStoreBuilder region (Regions region ) {
109
- clientBuilder .withRegion (region );
110
- return this ;
111
- }
112
-
113
99
/**
114
100
* Sets an optional namespace prefix for all keys stored in DynamoDB. Use this if you are sharing
115
101
* the same database table between multiple clients that are for different LaunchDarkly
@@ -131,15 +117,15 @@ public DynamoDbFeatureStoreBuilder prefix(String prefix) {
131
117
* @param existingClient an existing DynamoDB client instance
132
118
* @return the builder
133
119
*/
134
- public DynamoDbFeatureStoreBuilder existingClient (AmazonDynamoDB existingClient ) {
120
+ public DynamoDbFeatureStoreBuilder existingClient (DynamoDbClient existingClient ) {
135
121
this .existingClient = existingClient ;
136
122
return this ;
137
123
}
138
124
139
125
/**
140
126
* Specifies whether local caching should be enabled and if so, sets the cache properties. Local
141
127
* caching is enabled by default; see {@link FeatureStoreCacheConfig#DEFAULT}. To disable it, pass
142
- * {@link FeatureStoreCaching #disabled()} to this method.
128
+ * {@link FeatureStoreCacheConfig #disabled()} to this method.
143
129
*
144
130
* @param caching a {@link FeatureStoreCacheConfig} object specifying caching parameters
145
131
* @return the builder
0 commit comments