Guest User

Untitled

a guest
May 24th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.39 KB | None | 0 0
  1. public async Task<string> FunctionHandler(S3Event evnt, ILambdaContext context)
  2. {
  3. var s3Event = evnt.Records?[0].S3;
  4. if(s3Event == null)
  5. {
  6. return null;
  7. }
  8.  
  9. try
  10. {
  11. if(s3Event.Object.Key.ToLower().Contains("thumb"))
  12. {
  13. Console.WriteLine("The image is already a thumb file");
  14. return "";
  15. }
  16.  
  17.  
  18.  
  19. var response = await this.S3Client.GetObjectMetadataAsync(s3Event.Bucket.Name, s3Event.Object.Key);
  20. return response.Headers.ContentType;
  21. }
  22. catch(Exception e)
  23. {
  24. context.Logger.LogLine($"Error getting object {s3Event.Object.Key} from bucket {s3Event.Bucket.Name}. Make sure they exist and your bucket is in the same region as this function.");
  25. context.Logger.LogLine(e.Message);
  26. context.Logger.LogLine(e.StackTrace);
  27. throw;
  28. }
  29. }
  30.  
  31. {
  32. "errorType": "AggregateException",
  33. "errorMessage": "One or more errors occurred. (Error making request with Error Code MovedPermanently and Http Status Code MovedPermanently. No further error information was returned by the service.)",
  34. "stackTrace": [
  35. "at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)",
  36. "at lambda_method(Closure , Stream , Stream , LambdaContextInternal )"
  37. ],
  38. "cause": {
  39. "errorType": "AmazonS3Exception",
  40. "errorMessage": "Error making request with Error Code MovedPermanently and Http Status Code MovedPermanently. No further error information was returned by the service.",
  41. "stackTrace": [
  42. "at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleException(IExecutionContext executionContext, HttpErrorResponseException exception)",
  43. "at Amazon.Runtime.Internal.ErrorHandler.ProcessException(IExecutionContext executionContext, Exception exception)",
  44. "at Amazon.Runtime.Internal.ErrorHandler.<InvokeAsync>d__5`1.MoveNext()",
  45. "--- End of stack trace from previous location where exception was thrown ---",
  46. "at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
  47. "at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
  48. "at Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()",
  49. "--- End of stack trace from previous location where exception was thrown ---",
  50. "at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
  51. "at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
  52. "at Amazon.Runtime.Internal.CredentialsRetriever.<InvokeAsync>d__7`1.MoveNext()",
  53. "--- End of stack trace from previous location where exception was thrown ---",
  54. "at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
  55. "at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
  56. "at Amazon.Runtime.Internal.RetryHandler.<InvokeAsync>d__10`1.MoveNext()",
  57. "--- End of stack trace from previous location where exception was thrown ---",
  58. "at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
  59. "at Amazon.Runtime.Internal.RetryHandler.<InvokeAsync>d__10`1.MoveNext()",
  60. "--- End of stack trace from previous location where exception was thrown ---",
  61. "at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
  62. "at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
  63. "at Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()",
  64. "--- End of stack trace from previous location where exception was thrown ---",
  65. "at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
  66. "at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
  67. "at Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()",
  68. "--- End of stack trace from previous location where exception was thrown ---",
  69. "at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
  70. "at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
  71. "at Amazon.S3.Internal.AmazonS3ExceptionHandler.<InvokeAsync>d__1`1.MoveNext()",
  72. "--- End of stack trace from previous location where exception was thrown ---",
  73. "at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
  74. "at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
  75. "at Amazon.Runtime.Internal.ErrorCallbackHandler.<InvokeAsync>d__5`1.MoveNext()",
  76. "--- End of stack trace from previous location where exception was thrown ---",
  77. "at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
  78. "at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
  79. "at Amazon.Runtime.Internal.MetricsHandler.<InvokeAsync>d__1`1.MoveNext()",
  80. "--- End of stack trace from previous location where exception was thrown ---",
  81. "at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
  82. "at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
  83. "at AwsS3Lambda.Function.<FunctionHandler>d__6.MoveNext() in C:\Users\Acer\Desktop\MementoCSharp\memento-dotnet\AwsS3Lambda\Function.cs:line 73"
  84. ],
  85. "cause": {
  86. "errorType": "HttpErrorResponseException",
  87. "errorMessage": "Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown.",
  88. "stackTrace": [
  89. "at Amazon.Runtime.Internal.RedirectHandler.HandleRedirect(IExecutionContext executionContext)",
  90. "at Amazon.Runtime.Internal.RedirectHandler.<InvokeAsync>d__1`1.MoveNext()",
  91. "--- End of stack trace from previous location where exception was thrown ---",
  92. "at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
  93. "at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
  94. "at Amazon.Runtime.Internal.Unmarshaller.<InvokeAsync>d__3`1.MoveNext()",
  95. "--- End of stack trace from previous location where exception was thrown ---",
  96. "at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
  97. "at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
  98. "at Amazon.S3.Internal.AmazonS3ResponseHandler.<InvokeAsync>d__1`1.MoveNext()",
  99. "--- End of stack trace from previous location where exception was thrown ---",
  100. "at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
  101. "at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
  102. "at Amazon.Runtime.Internal.ErrorHandler.<InvokeAsync>d__5`1.MoveNext()"
  103. ]
  104. }
  105. },
  106. "causes": [
  107. {
  108. "errorType": "AmazonS3Exception",
  109. "errorMessage": "Error making request with Error Code MovedPermanently and Http Status Code MovedPermanently. No further error information was returned by the service.",
  110. "stackTrace": [
  111. "at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleException(IExecutionContext executionContext, HttpErrorResponseException exception)",
  112. "at Amazon.Runtime.Internal.ErrorHandler.ProcessException(IExecutionContext executionContext, Exception exception)",
  113. "at Amazon.Runtime.Internal.ErrorHandler.<InvokeAsync>d__5`1.MoveNext()",
  114. "--- End of stack trace from previous location where exception was thrown ---",
  115. "at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
  116. "at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
  117. "at Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()",
  118. "--- End of stack trace from previous location where exception was thrown ---",
  119. "at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
  120. "at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
  121. "at Amazon.Runtime.Internal.CredentialsRetriever.<InvokeAsync>d__7`1.MoveNext()",
  122. "--- End of stack trace from previous location where exception was thrown ---",
  123. "at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
  124. "at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
  125. "at Amazon.Runtime.Internal.RetryHandler.<InvokeAsync>d__10`1.MoveNext()",
  126. "--- End of stack trace from previous location where exception was thrown ---",
  127. "at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
  128. "at Amazon.Runtime.Internal.RetryHandler.<InvokeAsync>d__10`1.MoveNext()",
  129. "--- End of stack trace from previous location where exception was thrown ---",
  130. "at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
  131. "at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
  132. "at Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()",
  133. "--- End of stack trace from previous location where exception was thrown ---",
  134. "at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
  135. "at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
  136. "at Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()",
  137. "--- End of stack trace from previous location where exception was thrown ---",
  138. "at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
  139. "at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
  140. "at Amazon.S3.Internal.AmazonS3ExceptionHandler.<InvokeAsync>d__1`1.MoveNext()",
  141. "--- End of stack trace from previous location where exception was thrown ---",
  142. "at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
  143. "at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
  144. "at Amazon.Runtime.Internal.ErrorCallbackHandler.<InvokeAsync>d__5`1.MoveNext()",
  145. "--- End of stack trace from previous location where exception was thrown ---",
  146. "at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
  147. "at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
  148. "at Amazon.Runtime.Internal.MetricsHandler.<InvokeAsync>d__1`1.MoveNext()",
  149. "--- End of stack trace from previous location where exception was thrown ---",
  150. "at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
  151. "at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
  152. "at AwsS3Lambda.Function.<FunctionHandler>d__6.MoveNext() in C:\Users\Acer\Desktop\MementoCSharp\memento-dotnet\AwsS3Lambda\Function.cs:line 73"
  153. ],
  154. "cause": {
  155. "errorType": "HttpErrorResponseException",
  156. "errorMessage": "Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown.",
  157. "stackTrace": [
  158. "at Amazon.Runtime.Internal.RedirectHandler.HandleRedirect(IExecutionContext executionContext)",
  159. "at Amazon.Runtime.Internal.RedirectHandler.<InvokeAsync>d__1`1.MoveNext()",
  160. "--- End of stack trace from previous location where exception was thrown ---",
  161. "at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
  162. "at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
  163. "at Amazon.Runtime.Internal.Unmarshaller.<InvokeAsync>d__3`1.MoveNext()",
  164. "--- End of stack trace from previous location where exception was thrown ---",
  165. "at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
  166. "at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
  167. "at Amazon.S3.Internal.AmazonS3ResponseHandler.<InvokeAsync>d__1`1.MoveNext()",
  168. "--- End of stack trace from previous location where exception was thrown ---",
  169. "at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
  170. "at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
  171. "at Amazon.Runtime.Internal.ErrorHandler.<InvokeAsync>d__5`1.MoveNext()"
  172. ]
  173. }
  174. }
  175. ]
  176. }
Add Comment
Please, Sign In to add comment