gpt4 book ai didi

c# - 使用错误代码 MovedPermanently 和 Http 状态代码 MovedPermanently 发出请求时出错。服务没有返回更多错误信息?

转载 作者:行者123 更新时间:2023-12-05 07:32:25 29 4
gpt4 key购买 nike

我使用 aws 工具包 lambda 项目模板创建了一个 aws 示例。并将项目发布到 Aws。

public class Function
{
IAmazonS3 S3Client { get; set; }

/// <summary>
/// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment
/// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the
/// region the Lambda function is executed in.
/// </summary>
public Function()
{
S3Client = new AmazonS3Client();
}

/// <summary>
/// Constructs an instance with a preconfigured S3 client. This can be used for testing the outside of the Lambda environment.
/// </summary>
/// <param name="s3Client"></param>
public Function(IAmazonS3 s3Client)
{
this.S3Client = s3Client;
}

/// <summary>
/// This method is called for every Lambda invocation. This method takes in an S3 event object and can be used
/// to respond to S3 notifications.
/// </summary>
/// <param name="evnt"></param>
/// <param name="context"></param>
/// <returns></returns>
public async Task<string> FunctionHandler(S3Event evnt, ILambdaContext context)
{
var s3Event = evnt.Records?[0].S3;
if(s3Event == null)
{
return null;
}

try
{
var response = await this.S3Client.GetObjectMetadataAsync(s3Event.Bucket.Name, s3Event.Object.Key);
return response.Headers.ContentType;
}
catch(Exception e)
{
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.");
context.Logger.LogLine(e.Message);
context.Logger.LogLine(e.StackTrace);
throw;
}
}
}

然后我使用以下 S3 Put 示例测试函数。

{
"Records": [
{
"eventVersion": "2.0",
"eventTime": "1970-01-01T00:00:00.000Z",
"requestParameters": {
"sourceIPAddress": "127.0.0.1"
},
"s3": {
"configurationId": "testConfigRule",
"object": {
"eTag": "0123456789abcdef0123456789abcdef",
"sequencer": "0A1B2C3D4E5F678901",
"key": "HappyFace.jpg",
"size": 1024
},
"bucket": {
"arn": "arn:aws:s3:::mybucket",
"name": "sourcebucket",
"ownerIdentity": {
"principalId": "EXAMPLE"
}
},
"s3SchemaVersion": "1.0"
},
"responseElements": {
"x-amz-id-2": "EXAMPLE123/5678abcdefghijklambdaisawesome/mnopqrstuvwxyzABCDEFGH",
"x-amz-request-id": "EXAMPLE123456789"
},
"awsRegion": "us-east-1",
"eventName": "ObjectCreated:Put",
"userIdentity": {
"principalId": "EXAMPLE"
},
"eventSource": "aws:s3"
}
]
}

但是,响应出现以下错误?

{
"errorType": "AggregateException",
"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.)",
"stackTrace": [
"at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)",
"at lambda_method(Closure , Stream , Stream , LambdaContextInternal )"
],
"cause": {
"errorType": "AmazonS3Exception",
"errorMessage": "Error making request with Error Code MovedPermanently and Http Status Code MovedPermanently. No further error information was returned by the service.",
"stackTrace": [
"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>d__5`1.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
"at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
"at Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
"at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
"at Amazon.Runtime.Internal.CredentialsRetriever.<InvokeAsync>d__7`1.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
"at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
"at Amazon.Runtime.Internal.RetryHandler.<InvokeAsync>d__10`1.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
"at Amazon.Runtime.Internal.RetryHandler.<InvokeAsync>d__10`1.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
"at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
"at Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
"at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
"at Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
"at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
"at Amazon.S3.Internal.AmazonS3ExceptionHandler.<InvokeAsync>d__1`1.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
"at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
"at Amazon.Runtime.Internal.ErrorCallbackHandler.<InvokeAsync>d__5`1.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
"at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
"at Amazon.Runtime.Internal.MetricsHandler.<InvokeAsync>d__1`1.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
"at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
"at StratsLambda.Function.<FunctionHandler>d__6.MoveNext() in C:\\work\\Perforce\\Abs\\Strats\\StratsLambda\\Function.cs:line 64"
],
"cause": {
"errorType": "HttpErrorResponseException",
"errorMessage": "Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown.",
"stackTrace": [
"at Amazon.Runtime.Internal.RedirectHandler.HandleRedirect(IExecutionContext executionContext)",
"at Amazon.Runtime.Internal.RedirectHandler.<InvokeAsync>d__1`1.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
"at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
"at Amazon.Runtime.Internal.Unmarshaller.<InvokeAsync>d__3`1.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
"at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
"at Amazon.S3.Internal.AmazonS3ResponseHandler.<InvokeAsync>d__1`1.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
"at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
"at Amazon.Runtime.Internal.ErrorHandler.<InvokeAsync>d__5`1.MoveNext()"
]
}
},
"causes": [ {
"errorType": "AmazonS3Exception",
"errorMessage": "Error making request with Error Code MovedPermanently and Http Status Code MovedPermanently. No further error information was returned by the service.",
"stackTrace": [
"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>d__5`1.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
"at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
"at Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
"at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
"at Amazon.Runtime.Internal.CredentialsRetriever.<InvokeAsync>d__7`1.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
"at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
"at Amazon.Runtime.Internal.RetryHandler.<InvokeAsync>d__10`1.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
"at Amazon.Runtime.Internal.RetryHandler.<InvokeAsync>d__10`1.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
"at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
"at Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
"at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
"at Amazon.Runtime.Internal.CallbackHandler.<InvokeAsync>d__9`1.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
"at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
"at Amazon.S3.Internal.AmazonS3ExceptionHandler.<InvokeAsync>d__1`1.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
"at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
"at Amazon.Runtime.Internal.ErrorCallbackHandler.<InvokeAsync>d__5`1.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
"at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
"at Amazon.Runtime.Internal.MetricsHandler.<InvokeAsync>d__1`1.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
"at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
"at StratsLambda.Function.<FunctionHandler>d__6.MoveNext() in C:\\work\\Perforce\\Abs\\Strats\\StratsLambda\\Function.cs:line 64"
],
"cause": {
"errorType": "HttpErrorResponseException",
"errorMessage": "Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown.",
"stackTrace": [
"at Amazon.Runtime.Internal.RedirectHandler.HandleRedirect(IExecutionContext executionContext)",
"at Amazon.Runtime.Internal.RedirectHandler.<InvokeAsync>d__1`1.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
"at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
"at Amazon.Runtime.Internal.Unmarshaller.<InvokeAsync>d__3`1.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
"at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
"at Amazon.S3.Internal.AmazonS3ResponseHandler.<InvokeAsync>d__1`1.MoveNext()",
"--- End of stack trace from previous location where exception was thrown ---",
"at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()",
"at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)",
"at Amazon.Runtime.Internal.ErrorHandler.<InvokeAsync>d__5`1.MoveNext()"
]
}
}
]
}

最佳答案

我意识到这是旧的,但没有答案所以...该错误来自使用错误的区域端点向存储桶发出请求。我可以看到你的设置:

"awsRegion": "us-east-1"

检查存储桶是否在该区域中,如果没有通过配置或在 AmazonS3Client 的构造函数中提供正确的区域。例如

var config = new AmazonS3Config {ServiceURL = bucket, RegionEndpoint = RegionEndpoint.EUWest2};
var client = new AmazonS3Client(new BasicAWSCredentials(s3AccessKey, s3Secret), config);

关于c# - 使用错误代码 MovedPermanently 和 Http 状态代码 MovedPermanently 发出请求时出错。服务没有返回更多错误信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51252665/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com