Class AwsModule

java.lang.Object
io.jooby.awssdkv1.AwsModule
All Implemented Interfaces:
Extension

public class AwsModule extends Object implements Extension
Aws module for aws-java-sdk 1.x. This module:

- Integrates AWS credentials within application properties. - Register AWS services as application services (so they can be used by require calls or DI). - Add graceful shutdown to AWS services.

Usage:


 {
     install(
         new AwsModule()
             .setup(credentials -> {
               return TransferManagerBuilder.standard()
                   .withS3Client(
                       AmazonS3ClientBuilder.standard()
                           .withRegion(Regions.US_EAST_1)
                           .withCredentials(credentials)
                           .build()
                   ).build();
             })
     );
 }
 

Previous example register AmazonS3Client and TransferManager services

NOTE: You need to add the required service dependency to your project.

Author:
edgar
  • Constructor Details

    • AwsModule

      public AwsModule()
  • Method Details

    • setup

      @NonNull public AwsModule setup(@NonNull Function<com.amazonaws.auth.AWSCredentialsProvider,Object> provider)
      Setup a new AWS service. Supported outputs are:

      - Single amazon service - Stream of amazon services - Collection of amazon services

      Each of the services returned by this function are added to the application service registry and shutdown at application shutdown time.

      Parameters:
      provider - Service provider/factory.
      Returns:
      AWS service.
    • install

      public void install(@NonNull Jooby application) throws Exception
      Specified by:
      install in interface Extension
      Throws:
      Exception
    • newCredentialsProvider

      @NonNull public static com.amazonaws.auth.AWSCredentialsProvider newCredentialsProvider(@NonNull com.typesafe.config.Config config)
      Creates a credentials provider, exactly like DefaultAWSCredentialsProviderChain appending the application properties provider.
      Parameters:
      config - Application properties.
      Returns:
      Credentials provider.