I need to access and write to DynamoDB from a Play Framework application. There are already a couple of questions regarding this topic (here, here and here; however all of them are at least 3 years old).
The answer for the question is usually to use a wrapper (AWScala by seratch) or a library dedicated for Play:
However the wrapper simply calls the sync versions of the SDK underneath the hood. And if possible I would like to be able to update the AWS SDK as soon as a new version comes out and not be dependent on the used Scala/Play library to be updated first. So the best alternative for me turns out to be the aws-scala-sdk wrapper generator by awslabs. The async wrapper uses for example the Future<PutItemResult> putItemAsync(PutItemRequest putItemRequest, AsyncHandler<PutItemRequest,PutItemResult> asyncHandler) method which still returns a Java Future, but it's also possible to use the callbacks of the AsyncHandler to drive the response of a Scala Future:
val promise = scala.concurrent.Promise[PutItemResult]
dynamoDBAsync(request, new com.amazonaws.handlers.AsyncHandler[PutItemRequest, PutItemResult]() {
override def onSuccess(request: PutItemRequest, result: PutItemResult) = promise.success(Ok)
override def onError(exception: Exception) = promise.failure(exception)
})
promise.future
Code like this is generated by the aws-scala-sdk generator. Is this approach safe to use with Play and the default ExecutionContext, or does it still suffer from the same problem of blocking a thread like calling Java's Future.get()?