-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bulk Load CDK: S3 client and minimal S3V2 usage (#46897)
- Loading branch information
1 parent
cbcb669
commit e5a89ce
Showing
5 changed files
with
77 additions
and
5 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
airbyte-cdk/bulk/core/load/src/main/kotlin/io/airbyte/cdk/load/file/ObjectStorageClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.cdk.load.file | ||
|
||
import io.airbyte.cdk.load.message.RemoteObject | ||
|
||
interface ObjectStorageClient<T : RemoteObject> { | ||
suspend fun list(prefix: String): List<T> | ||
} |
60 changes: 60 additions & 0 deletions
60
airbyte-cdk/bulk/toolkits/load-s3/src/main/kotlin/io/airbyte/cdk/load/command/s3/S3Client.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (c) 2024 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.cdk.load.command.s3 | ||
|
||
import aws.sdk.kotlin.runtime.auth.credentials.StaticCredentialsProvider | ||
import aws.sdk.kotlin.services.s3.model.ListObjectsRequest | ||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings | ||
import io.airbyte.cdk.load.command.aws.AWSAccessKeyConfigurationProvider | ||
import io.airbyte.cdk.load.file.ObjectStorageClient | ||
import io.airbyte.cdk.load.message.RemoteObject | ||
import io.micronaut.context.annotation.Factory | ||
import io.micronaut.context.annotation.Secondary | ||
import jakarta.inject.Singleton | ||
|
||
class S3Object( | ||
override val key: String, | ||
) : RemoteObject() | ||
|
||
@SuppressFBWarnings("NP_NONNULL_PARAM_VIOLATION", justification = "Kotlin async continuation") | ||
class S3Client( | ||
private val client: aws.sdk.kotlin.services.s3.S3Client, | ||
private val bucketConfig: S3BucketConfiguration | ||
) : ObjectStorageClient<S3Object> { | ||
override suspend fun list(prefix: String): List<S3Object> { | ||
val request = ListObjectsRequest { | ||
bucket = bucketConfig.s3BucketName | ||
this.prefix = prefix | ||
} | ||
return client.listObjects(request).contents?.mapNotNull { | ||
it.key?.let { key -> S3Object(key) } | ||
} | ||
?: emptyList() | ||
} | ||
} | ||
|
||
@Factory | ||
class S3ClientFactory( | ||
private val keyConfig: AWSAccessKeyConfigurationProvider, | ||
private val bucketConfig: S3BucketConfigurationProvider | ||
) { | ||
|
||
@Singleton | ||
@Secondary | ||
fun make(): S3Client { | ||
val credentials = StaticCredentialsProvider { | ||
accessKeyId = keyConfig.awsAccessKeyConfiguration.accessKeyId | ||
secretAccessKey = keyConfig.awsAccessKeyConfiguration.secretAccessKey | ||
} | ||
|
||
val client = | ||
aws.sdk.kotlin.services.s3.S3Client { | ||
region = bucketConfig.s3BucketConfiguration.s3BucketRegion.name | ||
credentialsProvider = credentials | ||
} | ||
|
||
return S3Client(client, bucketConfig.s3BucketConfiguration) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters