aws-spi-akka-http

An alternative non-blocking async http engine for aws-sdk-java-v2 based on akka-http

License

License

Categories

Categories

AWS Container PaaS Providers Akka Microservices Reactive libraries
GroupId

GroupId

com.github.matsluni
ArtifactId

ArtifactId

aws-spi-akka-http_2.13
Last Version

Last Version

0.0.11
Release Date

Release Date

Type

Type

jar
Description

Description

aws-spi-akka-http
An alternative non-blocking async http engine for aws-sdk-java-v2 based on akka-http
Project URL

Project URL

https://github.com/matsluni/aws-spi-akka-http
Project Organization

Project Organization

Matthias Lüneberg
Source Code Management

Source Code Management

https://github.com/matsluni/aws-spi-akka-http.git

Download aws-spi-akka-http_2.13

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.matsluni/aws-spi-akka-http_2.13/ -->
<dependency>
    <groupId>com.github.matsluni</groupId>
    <artifactId>aws-spi-akka-http_2.13</artifactId>
    <version>0.0.11</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.matsluni/aws-spi-akka-http_2.13/
implementation 'com.github.matsluni:aws-spi-akka-http_2.13:0.0.11'
// https://jarcasting.com/artifacts/com.github.matsluni/aws-spi-akka-http_2.13/
implementation ("com.github.matsluni:aws-spi-akka-http_2.13:0.0.11")
'com.github.matsluni:aws-spi-akka-http_2.13:jar:0.0.11'
<dependency org="com.github.matsluni" name="aws-spi-akka-http_2.13" rev="0.0.11">
  <artifact name="aws-spi-akka-http_2.13" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.matsluni', module='aws-spi-akka-http_2.13', version='0.0.11')
)
libraryDependencies += "com.github.matsluni" % "aws-spi-akka-http_2.13" % "0.0.11"
[com.github.matsluni/aws-spi-akka-http_2.13 "0.0.11"]

Dependencies

compile (9)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.13.4
com.typesafe.akka : akka-stream_2.13 jar 2.5.31
com.typesafe.akka : akka-stream_2.13 jar 2.5.31
com.typesafe.akka : akka-http_2.13 jar 10.1.13
com.typesafe.akka : akka-http_2.13 jar 10.1.13
software.amazon.awssdk : http-client-spi jar 2.11.4
software.amazon.awssdk : http-client-spi jar 2.11.4
org.scala-lang.modules : scala-collection-compat_2.13 jar 2.3.1
org.scala-lang.modules : scala-collection-compat_2.13 jar 2.3.1

test (11)

Group / Artifact Type Version
software.amazon.awssdk : s3 jar 2.11.4
software.amazon.awssdk : dynamodb jar 2.11.4
software.amazon.awssdk : sqs jar 2.11.4
software.amazon.awssdk : sns jar 2.11.4
software.amazon.awssdk : kinesis jar 2.11.4
com.dimafeng : testcontainers-scala_2.13 jar 0.38.7
junit : junit jar 4.13.1
org.scala-lang.modules : scala-java8-compat_2.13 jar 0.9.1
org.scalatest : scalatest_2.13 jar 3.2.3
org.scalatestplus : scalatestplus-junit_2.13 jar 1.0.0-M2
ch.qos.logback : logback-classic jar 1.2.3

Project Modules

There are no modules declared in this project.

AWS Akka-Http SPI implementation

Build Status Maven Central License Join the chat at https://gitter.im/aws-spi-akka-http/community

This library implements the provided SPI for the asynchronous and non-blocking http calls in the new AWS Java SDK with Akka HTTP.

This is an alternative implementation to the built-in netty-based async http engine in the aws sdk. Use at your own risk.

Usage

Create a dependency to this library by adding the following to your build.sbt:

"com.github.matsluni" %% "aws-spi-akka-http" % "0.0.11"

or for Maven, the following to pom.xml:

<dependency>
    <groupId>com.github.matsluni</groupId>
    <artifactId>aws-spi-akka-http_2.12</artifactId>
    <version>0.0.11</version>
</dependency>

An example (in scala) from the test shows how to use akka-http as the underlying http provider instead of netty.

val akkaClient = new AkkaHttpAsyncHttpService().createAsyncHttpClientFactory().build()

val client = S3AsyncClient
              .builder()
              .credentialsProvider(ProfileCredentialsProvider.builder().build())
              .region(Region.EU_CENTRAL_1)
              .httpClient(akkaClient)
              .build()

val eventualResponse = client.listBuckets()

If you connect to an AWS service from inside a corporate network, it may be necessary to configure a proxy. This can be achieved in the following way:

val system = ActorSystem("aws-akka-http")

val proxyHost = "localhost"
val proxyPort = 8888

val httpsProxyTransport = ClientTransport.httpsProxy(InetSocketAddress.createUnresolved(proxyHost, proxyPort))

val settings = ConnectionPoolSettings(system)
  .withConnectionSettings(ClientConnectionSettings(system)
  .withTransport(httpsProxyTransport))

lazy val akkaHttpClient = 
  AkkaHttpClient
    .builder()
    .withActorSystem(system)
    .withConnectionPoolSettings(settings)
    .build()
    
val client = S3AsyncClient
	.builder()
	.credentialsProvider(ProfileCredentialsProvider.builder().build())
	.region(Region.EU_CENTRAL_1)
	.httpClient(akkaHttpClient)
	.build()
              
val eventualResponse = client.listBuckets()

When you use this library and a specific AWS service (e.g. S3, SQS, etc...) you may want to exclude the transitive Netty dependency netty-nio-client like this:

libraryDependencies ++= Seq(
  "software.amazon.awssdk" % "s3" % "2.11.4" exclude("software.amazon.awssdk", "netty-nio-client")
)

If you not exclude the transitive dependency like shown above you have to explicitly declare which httpClient to use in the service client instantiation. If no client is explicitly set and multiple implementations for the SdkAsyncHttpClient are found on the classpath, an exception like the following is thrown at runtime:

software.amazon.awssdk.core.exception.SdkClientException: Multiple HTTP implementations were found on the classpath. 
    To avoid non-deterministic loading implementations, please explicitly provide an HTTP client via the client builders, 
    set the software.amazon.awssdk.http.async.service.impl system property with the FQCN of the HTTP service to use as the 
    default, or remove all but one HTTP implementation from the classpath

To further reduce the classpath it is also optional possible to exclude "software.amazon.awssdk", "apache-client". This excludes an additional HttpClient, which comes as a transitive dependency with a AWS service.

There also exists an mini example project which shows the usage. This example uses gradle and also shows how to exclude the netty dependency.

Running the tests in this repo

In this repository there are unit tests and integration tests. The unit tests run against some local started aws services, which test some basic functionality and do not use real services from aws and cost no money.

But, there are also integration tests which require valid aws credentials to run and running these tests is not for free. If you are not careful it can cost you money on aws. Be warned.

The integration tests look for aws credentials as either an environment variable, a system property or a credential file. See the here and here in the aws documentation for details.

The tests can be run in sbt with:

test

To run the integration tests

it:test

License

This library is Open Source and available under the Apache 2 License.

Versions

Version
0.0.11
0.0.10
0.0.9
0.0.8
0.0.7