com.markosindustries.distroboy.aws.s3.StreamToS3 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aws-s3 Show documentation
Show all versions of aws-s3 Show documentation
DistroBoy support library for interacting with AWS S3 using the AWS SDK
The newest version!
package com.markosindustries.distroboy.aws.s3;
import com.markosindustries.distroboy.core.operations.ForEachOp;
import java.util.function.Function;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.services.s3.S3Client;
public class StreamToS3 implements ForEachOp {
private final S3Client s3Client;
private final String bucket;
private final Function keyAccessor;
private final Function requestBodyAccessor;
public StreamToS3(
S3Client s3Client,
String bucket,
Function keyAccessor,
Function requestBodyAccessor) {
this.s3Client = s3Client;
this.bucket = bucket;
this.keyAccessor = keyAccessor;
this.requestBodyAccessor = requestBodyAccessor;
}
@Override
public void forEach(I input) {
String key = keyAccessor.apply(input);
RequestBody requestBody = requestBodyAccessor.apply(input);
s3Client.putObject(req -> req.bucket(bucket).key(key), requestBody);
}
}