// Path: pipeline-application/src/main/java/com/smoketurner/pipeline/application/managed/AmazonS3ClientManager.java
// public class AmazonS3ClientManager implements Managed {
// 
//   private final AmazonS3Client client;
// 
//   /**
//    * Constructor
//    *
//    * @param s3 AmazonS3 to manage
//    */
//   public AmazonS3ClientManager(@Nonnull final AmazonS3 s3) {
//     this.client = (AmazonS3Client) Objects.requireNonNull(s3);
//   }
// 
//   @Override
//   public void start() throws Exception {
//     // nothing to start
//   }
// 
//   @Override
//   public void stop() throws Exception {
//     client.shutdown();
//   }
// }
// 
// Path: pipeline-application/src/main/java/com/smoketurner/pipeline/application/managed/AmazonSQSClientManager.java
// public class AmazonSQSClientManager implements Managed {
// 
//   private final AmazonSQSClient client;
// 
//   /**
//    * Constructor
//    *
//    * @param sqs AmazonSQS to manage
//    */
//   public AmazonSQSClientManager(@Nonnull final AmazonSQS sqs) {
//     this.client = (AmazonSQSClient) Objects.requireNonNull(sqs);
//   }
// 
//   @Override
//   public void start() throws Exception {
//     // nothing to start
//   }
// 
//   @Override
//   public void stop() throws Exception {
//     client.shutdown();
//   }
// }


import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.securitytoken.AWSSecurityTokenService;
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClientBuilder;
import com.amazonaws.services.sqs.AmazonSQS;
import com.amazonaws.services.sqs.AmazonSQSClientBuilder;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.net.HostAndPort;
import com.smoketurner.pipeline.application.managed.AmazonS3ClientManager;
import com.smoketurner.pipeline.application.managed.AmazonSQSClientManager;
import io.dropwizard.setup.Environment;
import java.util.Optional;
import javax.annotation.Nullable;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.NotEmpty;
import org.hibernate.validator.valuehandling.UnwrapValidatedValue;
        AWSSecurityTokenServiceClientBuilder.standard()
            .withCredentials(provider)
            .withClientConfiguration(clientConfig)
            .withRegion(region)
            .build();

    return new STSAssumeRoleSessionCredentialsProvider.Builder(stsRoleArn, "pipeline")
        .withStsClient(stsClient)
        .build();
  }

  @JsonIgnore
  public AmazonS3 buildS3(final Environment environment) {
    final AWSCredentialsProvider provider = getProvider();
    final ClientConfiguration clientConfig = getClientConfiguration();

    final AmazonS3ClientBuilder builder =
        AmazonS3ClientBuilder.standard()
            .withCredentials(provider)
            .withClientConfiguration(clientConfig);

    if (!Strings.isNullOrEmpty(this.region)) {
      final Region region = Region.getRegion(Regions.fromName(this.region));
      Preconditions.checkArgument(
          region.isServiceSupported("s3"), "S3 is not supported in " + region);

      builder.withRegion(this.region);
    }

    final AmazonS3 s3 = builder.build();
// Path: pipeline-application/src/main/java/com/smoketurner/pipeline/application/managed/AmazonS3ClientManager.java
// public class AmazonS3ClientManager implements Managed {
// 
//   private final AmazonS3Client client;
// 
//   /**
//    * Constructor
//    *
//    * @param s3 AmazonS3 to manage
//    */
//   public AmazonS3ClientManager(@Nonnull final AmazonS3 s3) {
//     this.client = (AmazonS3Client) Objects.requireNonNull(s3);
//   }
// 
//   @Override
//   public void start() throws Exception {
//     // nothing to start
//   }
// 
//   @Override
//   public void stop() throws Exception {
//     client.shutdown();
//   }
// }
// 
// Path: pipeline-application/src/main/java/com/smoketurner/pipeline/application/managed/AmazonSQSClientManager.java
// public class AmazonSQSClientManager implements Managed {
// 
//   private final AmazonSQSClient client;
// 
//   /**
//    * Constructor
//    *
//    * @param sqs AmazonSQS to manage
//    */
//   public AmazonSQSClientManager(@Nonnull final AmazonSQS sqs) {
//     this.client = (AmazonSQSClient) Objects.requireNonNull(sqs);
//   }
// 
//   @Override
//   public void start() throws Exception {
//     // nothing to start
//   }
// 
//   @Override
//   public void stop() throws Exception {
//     client.shutdown();
//   }
// }


// Path: pipeline-application/src/main/java/com/smoketurner/pipeline/application/config/AwsConfiguration.java
import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain;
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.securitytoken.AWSSecurityTokenService;
import com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClientBuilder;
import com.amazonaws.services.sqs.AmazonSQS;
import com.amazonaws.services.sqs.AmazonSQSClientBuilder;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.net.HostAndPort;
import com.smoketurner.pipeline.application.managed.AmazonS3ClientManager;
import com.smoketurner.pipeline.application.managed.AmazonSQSClientManager;
import io.dropwizard.setup.Environment;
import java.util.Optional;
import javax.annotation.Nullable;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.NotEmpty;
import org.hibernate.validator.valuehandling.UnwrapValidatedValue;

        AWSSecurityTokenServiceClientBuilder.standard()
            .withCredentials(provider)
            .withClientConfiguration(clientConfig)
            .withRegion(region)
            .build();

    return new STSAssumeRoleSessionCredentialsProvider.Builder(stsRoleArn, "pipeline")
        .withStsClient(stsClient)
        .build();
  }

  @JsonIgnore
  public AmazonS3 buildS3(final Environment environment) {
    final AWSCredentialsProvider provider = getProvider();
    final ClientConfiguration clientConfig = getClientConfiguration();

    final AmazonS3ClientBuilder builder =
        AmazonS3ClientBuilder.standard()
            .withCredentials(provider)
            .withClientConfiguration(clientConfig);

    if (!Strings.isNullOrEmpty(this.region)) {
      final Region region = Region.getRegion(Regions.fromName(this.region));
      Preconditions.checkArgument(
          region.isServiceSupported("s3"), "S3 is not supported in " + region);

      builder.withRegion(this.region);
    }

    final AmazonS3 s3 = builder.build();
    environment.lifecycle().manage(new AmazonS3ClientManager(s3));