title: AWS S3 AmazonServiceException A WebException with status SecureChannelFailure
body: <p>Have service that receives requests, generates data and saves this in files to AWS S3.
  If service receives many requests can try to save up to 20 files (2 servers x 10 workers each) in parallel. 
  Data generated by requests and saved to S3 can be from few KB to around ~400MB</p>
  
  <p>Problem is that sometimes (seems to be when service is busy/big files to save) S3 fails with the exception below:
  We discussed 2 solutions:</p>
  
  <p>1) Implement a retry of S3.UploadAsync() if save fails.
     Not sure if will make any difference. Assume S3 already retries internally so maybe is no point to retry. If problem is that files are too big/takes to long to save this won't solve the issue maybe make it worst.</p>
  
  <p>2) Increase the TransferUtilityConfig.DefaultTimeout to, lets say 10min (default is 5min).
     If problem is that saving takes more than 5 minutes, this will fix the issue but exception thrown by S3 doesn't indicate is a timeout exception so maybe this will solve anything.</p>
  
  <p>3) Is this an intermittent issue in AWS infrastructure? Could retry help?</p>
  
  <p>Does anyone have experience/solution when this exception happens? Any other ideas?</p>
  
  <p>UPDATE: 
  TransferUtilityConfig() does not contain DefaultTimeout if using NET 4.5. The functionality has been moved to AmazonS3Config. This offers more parameters to control the upload: Timeout, ReadWriteTimeout, MaxErrorRetry
  <a href="http://docs.aws.amazon.com/sdkfornet1/latest/apidocs/html/T_Amazon_S3_AmazonS3Config.htm" rel="nofollow noreferrer">AmazonS3Config Class</a>
  Settings are explained here
  <a href="http://docs.aws.amazon.com/sdk-for-net/v2/developer-guide/retries-timeouts.html" rel="nofollow noreferrer">AWS Retries and Timeouts</a></p>
  
  <p>This is the code used by the service to save:</p>
  
  <pre><code>using (var amazonS3Client = new AmazonS3Client(RegionEndpoint.GetBySystemName(_iAwsS3Settings.RegionEndpoint)))
  using (var fileTransferUtility = new TransferUtility(amazonS3Client))
  using (var memoryStream = new MemoryStream(data))
  {
      var fileTransferUtilityRequest = new TransferUtilityUploadRequest
      {
          BucketName = _iAwsS3Settings.BucketName,
          InputStream = memoryStream,
          StorageClass = S3StorageClass.ReducedRedundancy,
          PartSize = 6291456, // 6 MB.
          Key = fileLocation,
          CannedACL = S3CannedACL.BucketOwnerFullControl
      };
  
      await fileTransferUtility.UploadAsync(fileTransferUtilityRequest, ct);
  }
  </code></pre>
  
  <p>This is the exception given when S3 save fails:</p>
  
  <blockquote>
    <p>System.AggregateException: One or more errors occurred. ---> 
    Amazon.Runtime.AmazonServiceException: A WebException with status
    SecureChannelFailure was thrown. --->  System.Net.WebException: The
    request was aborted: Could not create SSL/TLS secure channel.  at
    System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult
    asyncResult, TransportContext&amp; context)  at
    System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult
    asyncResult)  at
    System.Threading.Tasks.TaskFactory<code>1.FromAsyncCoreLogic(IAsyncResult
    iar, Func</code>2 endFunction, Action<code>1 endAction, Task</code>1 promise, Boolean
    requiresSynchronization) ---  End of stack trace from previous
    location where exception was thrown ---  at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
    task)  at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task)  at
    Amazon.Runtime.Internal.HttpHandler<code>1.&lt;InvokeAsync&gt;d__9</code>1.MoveNext()
    ---  End of stack trace from previous location where exception was thrown ---  at
    Amazon.Runtime.Internal.HttpHandler<code>1.&lt;InvokeAsync&gt;d__9</code>1.MoveNext()
    ---  End of stack trace from previous location where exception was thrown ---  at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
    task)  at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task)  at
    Amazon.Runtime.Internal.RedirectHandler.d__1<code>1.MoveNext()
    ---  End of stack trace from previous location where exception was thrown ---  at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
    task)  at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task)  at
    Amazon.Runtime.Internal.Unmarshaller.&lt;InvokeAsync&gt;d__3</code>1.MoveNext()
    ---  End of stack trace from previous location where exception was thrown ---  at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
    task)  at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task)  at
    Amazon.S3.Internal.AmazonS3ResponseHandler.d__1<code>1.MoveNext()
    ---  End of stack trace from previous location where exception was thrown ---  at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
    task)  at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task)  at
    Amazon.Runtime.Internal.ErrorHandler.&lt;InvokeAsync&gt;d__5</code>1.MoveNext() 
    --- End of inner exception stack trace ---  at Amazon.Runtime.Internal.WebExceptionHandler.HandleException(IExecutionContext
    executionContext, WebException exception)  at
    Amazon.Runtime.Internal.ErrorHandler.ProcessException(IExecutionContext
    executionContext, Exception exception)  at
    Amazon.Runtime.Internal.ErrorHandler.d__5<code>1.MoveNext()
    ---  End of stack trace from previous location where exception was thrown ---  at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
    task)  at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task)  at
    Amazon.Runtime.Internal.CallbackHandler.&lt;InvokeAsync&gt;d__9</code>1.MoveNext()
    ---  End of stack trace from previous location where exception was thrown ---  at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
    task)  at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task)  at
    Amazon.Runtime.Internal.CredentialsRetriever.d__7<code>1.MoveNext()
    ---  End of stack trace from previous location where exception was thrown ---  at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
    task)  at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
    task)  at
    Amazon.Runtime.Internal.RetryHandler.&lt;InvokeAsync&gt;d__10</code>1.MoveNext() 
    --- End of stack trace from previous location where exception was thrown ---  at
    Amazon.Runtime.Internal.RetryHandler.d__10`1.MoveNext()</p>
  </blockquote>