AWS Lambda中的AggregateException错误

时间:2018-08-22 06:42:21

标签: c# amazon-web-services amazon-s3 aws-lambda

在ObjectCreated(All)事件上,lambda函数被触发,但是在以下错误消息中结束。不知道是什么导致了此错误,我为S3存储桶创建了策略,如下所示。错误消息还提到访问被拒绝和HttpResponseException。

错误:

One or more errors occurred. (Access Denied): AggregateException
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at lambda_method(Closure , Stream , Stream , LambdaContextInternal )

at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleException(IExecutionContext executionContext, HttpErrorResponseException exception)
at Amazon.Runtime.Internal.ErrorHandler.ProcessException(IExecutionContext executionContext, Exception exception)
at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CredentialsRetriever.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.S3.Internal.AmazonS3ExceptionHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.MetricsHandler.InvokeAsync[T](IExecutionContext executionContext)
at S3TestFunction.Function.FunctionHandler(S3Event s3Event, ILambdaContext lambdaContext) in /home/aniruddha/AWS/S3TestFunction/src/S3TestFunction/Function.cs:line 84
Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown.: HttpErrorResponseException
at Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken)
at Amazon.Runtime.Internal.HttpHandler`1.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.RedirectHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.Unmarshaller.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.S3.Internal.AmazonS3ResponseHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)

Lambda代码:

public async Task FunctionHandler(S3Event s3Event, ILambdaContext lambdaContext)
 {
    RegionEndpoint region = RegionEndpoint.USEast1;
    AmazonS3Client s3Client = new AmazonS3Client("accessID","accessKey", region);
    GetObjectRequest request = new GetObjectRequest();
    request.BucketName = "bucketname";
    request.Key = "username/testfile.txt";
    GetObjectResponse response = await s3Client.GetObjectAsync(request);
    StreamReader streamReader = new StreamReader(response.ResponseStream);
    String content = streamReader.ReadToEnd(); 
    lambdaContext.Logger.LogLine(content);             
 }

政策:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": ["s3:ListBucket"],
            "Resource": ["arn:aws:s3:::<BUCKET-NAME>"]
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:GetObject"
            ],
            "Resource": ["arn:aws:s3:::<BUCKET-NAME>/*"]
        }
    ]
}

0 个答案:

没有答案