AWS Akka-Http SPI implementation
This is a prototypical implementation to explore an alternative to netty as the build-in http engine in the aws sdk.
This library is not production ready and early alpha. Use at your own risk. Also, the underlying SPI is subject to change.
Create a dependency to this library by adding the following to your
"com.github.matsluni" %% "aws-spi-akka-http" % "0.0.8"
or for Maven, the following to
<dependency> <groupId>com.github.matsluni</groupId> <artifactId>aws-spi-akka-http_2.12</artifactId> <version>0.0.8</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.5.60" 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 tests can be run in
To run the integration tests
This library is Open Source and available under the Apache 2 License.