Skip to content

Commit

Permalink
fix: deprecated aws dynamodb sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
Roiocam committed Jun 16, 2024
1 parent cc84559 commit 69640f9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package org.apache.pekko.persistence.dynamodb.journal

import com.amazonaws.AmazonWebServiceRequest
import com.amazonaws.handlers.AsyncHandler
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBAsyncClient
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBAsync
import com.amazonaws.services.dynamodbv2.model._
import org.apache.pekko
import pekko.actor.{ ActorRef, Scheduler }
Expand All @@ -25,9 +25,8 @@ import pekko.persistence.dynamodb.{ DynamoDBConfig, Item }
import pekko.util.ccompat.JavaConverters._

import java.util.{ concurrent => juc }

import scala.concurrent.{ ExecutionContext, Future, Promise }
import scala.concurrent.duration._
import scala.concurrent.{ ExecutionContext, Future, Promise }

case class LatencyReport(nanos: Long, retries: Int)
private class RetryStateHolder(var retries: Int = 10, var backoff: FiniteDuration = 1.millis)
Expand All @@ -36,7 +35,7 @@ trait DynamoDBHelper {

implicit val ec: ExecutionContext
val scheduler: Scheduler
val dynamoDB: AmazonDynamoDBAsyncClient
val dynamoDB: AmazonDynamoDBAsync
val log: LoggingAdapter
val settings: DynamoDBConfig
import settings._
Expand Down
27 changes: 18 additions & 9 deletions src/main/scala/org/apache/pekko/persistence/dynamodb/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@

package org.apache.pekko.persistence

import java.nio.ByteBuffer
import java.util.concurrent.Executors
import com.amazonaws.auth.{ AWSStaticCredentialsProvider, BasicAWSCredentials }
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration
import com.amazonaws.regions.Regions
import com.amazonaws.services.dynamodbv2.model.{ AttributeValue, AttributeValueUpdate }
import com.amazonaws.services.dynamodbv2.{ AmazonDynamoDBAsync, AmazonDynamoDBAsyncClientBuilder }
import org.apache.pekko.actor.{ ActorSystem, Scheduler }
import org.apache.pekko.dispatch.ExecutionContexts
import org.apache.pekko.event.{ Logging, LoggingAdapter }
import org.apache.pekko.persistence.dynamodb.journal.DynamoDBHelper
import com.amazonaws.auth.BasicAWSCredentials
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBAsyncClient
import com.amazonaws.services.dynamodbv2.model.{ AttributeValue, AttributeValueUpdate }

import java.nio.ByteBuffer
import java.util.concurrent.Executors
import java.util.{ Map => JMap }
import scala.collection.generic.CanBuildFrom
import scala.concurrent.{ ExecutionContext, Future, Promise }
Expand Down Expand Up @@ -69,16 +71,23 @@ package object dynamodb {
val conns = settings.client.config.getMaxConnections
val executor = Executors.newFixedThreadPool(conns)
val creds = new BasicAWSCredentials(settings.AwsKey, settings.AwsSecret)
new AmazonDynamoDBAsyncClient(creds, settings.client.config, executor)
AmazonDynamoDBAsyncClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(creds))
.withClientConfiguration(settings.client.config)
.withExecutorFactory(() => executor)
.withEndpointConfiguration(new EndpointConfiguration(settings.Endpoint, Regions.DEFAULT_REGION.name()))
.build()
} else {
new AmazonDynamoDBAsyncClient(settings.client.config)
AmazonDynamoDBAsyncClientBuilder.standard()
.withClientConfiguration(settings.client.config)
.withEndpointConfiguration(new EndpointConfiguration(settings.Endpoint, Regions.DEFAULT_REGION.name()))
.build()
}
client.setEndpoint(settings.Endpoint)
val dispatcher = system.dispatchers.lookup(settings.ClientDispatcher)

class DynamoDBClient(
override val ec: ExecutionContext,
override val dynamoDB: AmazonDynamoDBAsyncClient,
override val dynamoDB: AmazonDynamoDBAsync,
override val settings: DynamoDBConfig,
override val scheduler: Scheduler,
override val log: LoggingAdapter)
Expand Down

0 comments on commit 69640f9

Please sign in to comment.