Does await PutObjectAsync(PutObjectAsync, CancellationToken) really awaits until the uploading finish in AWS SDK for .NET?

Viewed 2232

I'm using the AmazonS3Client.PutObjectAsync(PutObjectAsync, CancellationToken) method to upload my files to s3 storage. so the code inside my service looks like

await _client.PutObjectAsync(putObject, cancellationToken).ConfigureAwait(false);

I have to wait until the upload completes because the next service should download these files.

Now, I'm facing the problem - PutObjectAsync is executed, but s3 doesn't contain the file I need, it appears only after a few seconds after my program is finished.

I checked the PutObjectResponse class but didn't find anything which can explain if a file was completely uploaded. I also didn't find info about PutObjectAsync method behavior.

So the question is if PutObjectAsync combined with ConfigurateAwait(false) really waits for upload completion or am I missing something?

Thank you in advance. Any guidance would be appreciated.

1 Answers

Yes, await PutObjectAsync will (asynchronously) wait until the upload is complete.

Now, I'm facing the problem - PutObjectAsync is executed, but s3 doesn't contain the file I need, it appears only after a few seconds after my program is finished.

What you're seeing is eventual consistency, which is almost ubiquitous with cloud services. The file has been uploaded, but it may take some time to be available. The most basic approach to resolving this is to poll until the file "appears". I'm not familiar with the details of S3, but some cloud services offer a "read my own writes" or some kind of flag that causes the Put to be delayed until the file can be read; that simplifies your code but in reality is just moving the polling to Amazon's servers.

Related