Skip to content

Instantly share code, notes, and snippets.

@sherl0cks
Created April 14, 2020 15:24
Show Gist options
  • Save sherl0cks/2ea9f7b114986ffebce7b0935e202207 to your computer and use it in GitHub Desktop.
Save sherl0cks/2ea9f7b114986ffebce7b0935e202207 to your computer and use it in GitHub Desktop.
AWS SDK Support in Quarkus
import com.amazonaws.xray.interceptors.TracingInterceptor
import org.eclipse.microprofile.config.inject.ConfigProperty
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration
import software.amazon.awssdk.http.SdkHttpClient
import software.amazon.awssdk.http.apache.ApacheHttpClient
import software.amazon.awssdk.http.async.SdkAsyncHttpClient
import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient
import software.amazon.awssdk.regions.Region
import software.amazon.awssdk.services.dynamodb.DynamoDbClient
import software.amazon.awssdk.services.s3.S3AsyncClient
import software.amazon.awssdk.services.s3.S3Client
import software.amazon.awssdk.services.sns.SnsClient
import javax.enterprise.context.ApplicationScoped
import javax.enterprise.inject.Produces
import javax.inject.Named
@ApplicationScoped
class CdiConfig {
@ApplicationScoped
@Produces
fun apacheClient(): SdkHttpClient = ApacheHttpClient.builder().build()
@ApplicationScoped
@Produces
fun nettyClient(): SdkAsyncHttpClient = NettyNioAsyncHttpClient.builder().build()
@ApplicationScoped
@Produces
fun snsClient(
@ConfigProperty(name = "aws.region", defaultValue = "us-west-2") awsRegion: String,
sdkHttpClient: SdkHttpClient
): SnsClient = SnsClient.builder()
.region(Region.of(awsRegion))
.httpClient(sdkHttpClient)
.overrideConfiguration(
ClientOverrideConfiguration.builder()
.addExecutionInterceptor(TracingInterceptor())
.build()
)
.build()
@ApplicationScoped
@Produces
fun s3Client(
@ConfigProperty(name = "aws.region", defaultValue = "us-west-2") awsRegion: String,
sdkHttpClient: SdkHttpClient
): S3Client = S3Client.builder()
.region(Region.of(awsRegion))
.httpClient(sdkHttpClient)
.overrideConfiguration(
ClientOverrideConfiguration.builder()
.addExecutionInterceptor(TracingInterceptor())
.build()
)
.build()
@ApplicationScoped
@Produces
fun s3AsyncClient(
@ConfigProperty(name = "aws.region", defaultValue = "us-west-2") awsRegion: String,
sdkAsyncHttpClient: SdkAsyncHttpClient
): S3AsyncClient = S3AsyncClient.builder()
.region(Region.of(awsRegion))
.httpClient(sdkAsyncHttpClient)
.overrideConfiguration(
ClientOverrideConfiguration.builder()
.addExecutionInterceptor(TracingInterceptor())
.build()
)
.build()
@ApplicationScoped
@Produces
fun dynamoDbClient(
@ConfigProperty(name = "aws.region", defaultValue = "us-west-2") awsRegion: String,
sdkHttpClient: SdkHttpClient
): DynamoDbClient = DynamoDbClient.builder()
.region(Region.of(awsRegion))
.httpClient(sdkHttpClient)
.overrideConfiguration(
ClientOverrideConfiguration.builder()
.addExecutionInterceptor(TracingInterceptor())
.build()
)
.build()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment