Closed HaiderAli008 closed 2 years ago
As the error message says you need to call client.syncShutdown()
once you have finished with it. There is also an async/await version client.shutdown
you could use.
It is best practice to not keep creating and destroying AWSClients
as the construction can use a lot of resources. You are best to store one globally and reuse across all the functions that need one.
Thanks for quick reply
Really sorry I'm new in swift can you please guide me where I wrong ?
var client = AWSClient(
credentialProvider: .static(accessKeyId: access, secretAccessKey: secret)
, httpClientProvider: .createNew
)
let s3 = S3(client: client, region: .eucentral1)
let s3FileTransfer = S3FileTransferManager(s3: s3, threadPoolProvider: .createNew)
let downloadFuture = s3FileTransfer.copy(
from: S3File(url: "s3://my-buckett/my-key")!,
to: filePath)
I use that library for file transfer : https://github.com/soto-project/soto-s3-file-transfer
You need to call at the end of your code. These assume you are running inside an async function though
// wait for download future to complete
try await downloadFuture.get()
// shutdown client now we don't need it anymore
try await client.shutdown()
Alternatively you could store AWSClient in a global variable and not worry about shutting it down
let client = AWSClient(...)
func download() async throws {
let s3 = S3(client: client, region: .eucentral1)
let s3FileTransfer = S3FileTransferManager(s3: s3, threadPoolProvider: .createNew)
try await s3FileTransfer.copy(
from: S3File(url: "s3://my-buckett/my-key")!,
to: filePath
).get()
Great Thanks
log when I want to init Client
Assertion failed: AWSClient not shut down before the deinit. Please call client.syncShutdown() when no longer needed. 2022-06-22 20:25:53.435699+0500 Autrado[17144:133064] SotoCore/AWSClient.swift:110: Assertion failed: AWSClient not shut down before the deinit. Please call client.syncShutdown() when no longer needed.