private AWSCredentials getCredentialsForBucket(String bucketName) {
    if (configuration.getS3BucketCredentials().containsKey(bucketName)) {
      return configuration.getS3BucketCredentials().get(bucketName).toAWSCredentials();
    }

    return new AWSCredentials(
        configuration.getS3AccessKey().get(), configuration.getS3SecretKey().get());
  }
  @Inject
  public SingularityS3UploaderDriver(
      SingularityS3UploaderConfiguration configuration,
      SingularityS3Configuration s3Configuration,
      SingularityS3UploaderMetrics metrics,
      JsonObjectFileHelper jsonObjectFileHelper) {
    super(
        configuration.getPollForShutDownMillis(),
        configuration.getS3MetadataDirectory(),
        ImmutableList.of(
            StandardWatchEventKinds.ENTRY_CREATE,
            StandardWatchEventKinds.ENTRY_MODIFY,
            StandardWatchEventKinds.ENTRY_DELETE));

    this.metrics = metrics;

    this.fileSystem = FileSystems.getDefault();
    try {
      this.s3Service =
          new RestS3Service(
              new AWSCredentials(
                  s3Configuration.getS3AccessKey(), s3Configuration.getS3SecretKey()));
    } catch (Throwable t) {
      throw Throwables.propagate(t);
    }

    this.jsonObjectFileHelper = jsonObjectFileHelper;
    this.configuration = configuration;

    this.metadataToUploader = Maps.newHashMap();
    this.uploaderLastHadFilesAt = Maps.newHashMap();
    this.expiring = Sets.newHashSet();

    this.metrics.setExpiringCollection(expiring);

    this.runLock = new ReentrantLock();

    this.executorService =
        JavaUtils.newFixedTimingOutThreadPool(
            configuration.getExecutorMaxUploadThreads(),
            TimeUnit.SECONDS.toMillis(30),
            "SingularityS3Uploader-%d");
    this.scheduler =
        Executors.newScheduledThreadPool(
            1, new ThreadFactoryBuilder().setNameFormat("SingularityS3Driver-%d").build());
  }