1313 */
1414package com .facebook .presto .iceberg .container ;
1515
16- import com .amazonaws .auth .AWSStaticCredentialsProvider ;
17- import com .amazonaws .auth .BasicAWSCredentials ;
18- import com .amazonaws .client .builder .AwsClientBuilder ;
19- import com .amazonaws .services .s3 .AmazonS3 ;
20- import com .amazonaws .services .s3 .AmazonS3ClientBuilder ;
2116import com .facebook .presto .testing .containers .MinIOContainer ;
2217import com .facebook .presto .util .AutoCloseableCloser ;
2318import com .google .common .collect .ImmutableMap ;
2419import org .testcontainers .containers .Network ;
20+ import software .amazon .awssdk .auth .credentials .AwsBasicCredentials ;
21+ import software .amazon .awssdk .auth .credentials .StaticCredentialsProvider ;
22+ import software .amazon .awssdk .core .sync .RequestBody ;
23+ import software .amazon .awssdk .regions .Region ;
24+ import software .amazon .awssdk .services .s3 .S3Client ;
25+ import software .amazon .awssdk .services .s3 .S3Configuration ;
26+ import software .amazon .awssdk .services .s3 .model .CreateBucketRequest ;
27+ import software .amazon .awssdk .services .s3 .model .PutObjectRequest ;
2528
2629import java .io .Closeable ;
2730import java .io .IOException ;
31+ import java .net .URI ;
2832import java .util .concurrent .atomic .AtomicBoolean ;
2933
3034import static java .util .Objects .requireNonNull ;
@@ -39,7 +43,6 @@ public class IcebergMinIODataLake
3943 private final String bucketName ;
4044 private final String warehouseDir ;
4145 private final MinIOContainer minIOContainer ;
42-
4346 private final AtomicBoolean isStarted = new AtomicBoolean (false );
4447 private final AutoCloseableCloser closer = AutoCloseableCloser .create ();
4548
@@ -63,19 +66,39 @@ public void start()
6366 if (isStarted ()) {
6467 return ;
6568 }
69+
6670 try {
6771 this .minIOContainer .start ();
68- AmazonS3 s3Client = AmazonS3ClientBuilder
69- .standard ()
70- .withEndpointConfiguration (new AwsClientBuilder .EndpointConfiguration (
71- "http://localhost:" + minIOContainer .getMinioApiEndpoint ().getPort (),
72- "us-east-1" ))
73- .withPathStyleAccessEnabled (true )
74- .withCredentials (new AWSStaticCredentialsProvider (
75- new BasicAWSCredentials (ACCESS_KEY , SECRET_KEY )))
72+
73+ S3Client s3Client = S3Client .builder ()
74+ .endpointOverride (URI .create ("http://localhost:" + minIOContainer .getMinioApiEndpoint ().getPort ()))
75+ .region (Region .US_EAST_1 )
76+ .forcePathStyle (true )
77+ .serviceConfiguration (S3Configuration .builder ()
78+ // Disable checksum validation and chunked encoding for MinIO compatibility
79+ // MinIO checksum handling differs from AWS S3
80+ // Prevents chunked transfer encoding issues with MinIO
81+ .checksumValidationEnabled (false )
82+ .chunkedEncodingEnabled (false )
83+ .build ())
84+ .credentialsProvider (StaticCredentialsProvider .create (
85+ AwsBasicCredentials .create (ACCESS_KEY , SECRET_KEY )))
7686 .build ();
77- s3Client .createBucket (this .bucketName );
78- s3Client .putObject (this .bucketName , this .warehouseDir , "" );
87+
88+ s3Client .createBucket (CreateBucketRequest .builder ()
89+ .bucket (this .bucketName )
90+ .build ());
91+ String objectKey = this .warehouseDir .endsWith ("/" )
92+ ? this .warehouseDir + ".keep"
93+ : this .warehouseDir + "/.keep" ;
94+
95+ s3Client .putObject (
96+ PutObjectRequest .builder ()
97+ .bucket (this .bucketName )
98+ .key (objectKey )
99+ .build (),
100+ RequestBody .fromString ("placeholder" ));
101+ closer .register (s3Client );
79102 }
80103 finally {
81104 isStarted .set (true );
0 commit comments