Trying to push a number of images to S3 from DotNet API and I am receiving an unhandled exception at random points (see below). This is not being trapped by try catch.
The requests look valid and it fails at different images in different runs.
This is from the AWSSDK api in DotNet Core 2.0 using
PutObjectResponse response = Task.Run(() => client.PutObjectAsync(putRequest)).Result;
Thanks
InnerException {Amazon.S3.AmazonS3Exception: Error making request with Error Code BadRequest and Http Status Code BadRequest. No further error information was returned by the service. ---> Amazon.Runtime.Internal.HttpErrorResponseException:
Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown.
System.AggregateException
HResult=0x80131500
Message=One or more errors occurred. (Error making request with Error Code BadRequest and Http Status Code BadRequest. No further error information was returned by the service.)
Source=System.Private.CoreLib
StackTrace:
at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification)
at AWS.AWSS3.WriteImage(String apiSource, String COID, String unitIdentifier, String unitcode, String unitName, Int32 index, String requestUri, Int32 width, Int32 height, String caption) in C:\Dev\SourceControl\Development\BeachGuide\Lambda\BeachGuideAPIs\CommonCode\Utilities\AWSS3.cs:line 108
at ISILink.Controllers.APIController.LoadPropertyImagesIntoS3(clsCustomerInfo cust, Int32 timeFrame) in C:\Dev\SourceControl\Development\BeachGuide\Lambda\BeachGuideAPIs\ISILink\Controllers\APIController.cs:line 476
at ISILink.Controllers.APIController.<>c__DisplayClass15_0.<LoadAllImagesIntoS3>b__2(clsCustomerInfo cust) in C:\Dev\SourceControl\Development\BeachGuide\Lambda\BeachGuideAPIs\ISILink\Controllers\APIController.cs:line 413
at System.Threading.Tasks.Parallel.<>c__DisplayClass32_0
2.
at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.
I think what you want is
PutObjectResponse response = client.PutObjectAsync(putRequest).Result;
Good point, no need to double aync it. Thank you for that.
PutObjectResponse response = client.PutObjectAsync(putRequest).Result;
I made the change and ran again. This time it only gets to 1,180 objects before getting the following:
{System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Amazon.S3.AmazonS3Client'.
at Amazon.Runtime.AmazonServiceClient.ThrowIfDisposed() in E:\JenkinsWorkspaces\v3-trebuchet-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\AmazonServiceClient.cs:line 392
at Amazon.Runtime.AmazonServiceClient.InvokeAsync[TRequest,TResponse](TRequest request, IMarshaller2 marshaller, ResponseUnmarshaller unmarshaller, CancellationToken cancellationToken) in E:\JenkinsWorkspaces\v3-trebuchet-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\AmazonServiceClient.cs:line 243
at Amazon.S3.AmazonS3Client.PutObjectAsync(PutObjectRequest request, CancellationToken cancellationToken) in E:\JenkinsWorkspaces\v3-trebuchet-release\AWSDotNetPublic\sdk\src\Services\S3\Generated\_mobile\AmazonS3Client.cs:line 3248
at AWS.AWSS3.WriteImage(String apiSource, String COID, String unitIdentifier, String unitcode, String unitName, Int32 index, String requestUri, Int32 width, Int32 height, String caption) in C:\Dev\SourceControl\Development\BeachGuide\Lambda\BeachGuideAPIs\CommonCode\Utilities\AWSS3.cs:line 109
at ISILink.Controllers.APIController.LoadPropertyImagesIntoS3(clsCustomerInfo cust, Int32 timeFrame) in C:\Dev\SourceControl\Development\BeachGuide\Lambda\BeachGuideAPIs\ISILink\Controllers\APIController.cs:line 476
at ISILink.Controllers.APIController.<>c__DisplayClass15_0.<LoadAllImagesIntoS3>b__2(clsCustomerInfo cust) in C:\Dev\SourceControl\Development\BeachGuide\Lambda\BeachGuideAPIs\ISILink\Controllers\APIController.cs:line 413
at System.Threading.Tasks.Parallel.<>c__DisplayClass32_0
2.
at System.Threading.Tasks.Parallel.<>c__DisplayClass19_0`1.
Seems like your code disposesAmazonS3Client
and attempt to reuse it later. This does't look related to any issues in the SDK.
It seems that moving the S3 client creation closer to the put call improves things
using (client = new AmazonS3Client(aws_access_key, aws_secret_key, Amazon.RegionEndpoint.USEast1))
{
PutObjectResponse response = client.PutObjectAsync(putRequest).Result;
}
Most helpful comment
It seems that moving the S3 client creation closer to the put call improves things
using (client = new AmazonS3Client(aws_access_key, aws_secret_key, Amazon.RegionEndpoint.USEast1))
{
PutObjectResponse response = client.PutObjectAsync(putRequest).Result;
}