我正在尝试使用 AWS .NET 核心 SDK 在 dynamodb 中插入记录,但出现以下异常:
请求中包含的安全令牌无效。
请在下面找到我为连接它所做的步骤:
- 在 IAM 中创建了一个新的访问密钥。
- 在本地下载访问密钥和密钥。
- 在 C:/users//.aws/ 中创建了文件名凭据
在文件中添加了以下代码(出于安全目的删除了凭据)
[default] aws_access_key_id = xxxxxxxxxxxxxxxxxxxx aws_secret_access_key = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
在 appsettings.json 文件中添加了以下代码:
"AWS":{ "Region": "ap-south-1", "Profile": "default"}
在 startup.cs 的 ConfigureServices 方法中,我添加了以下代码:
services.AddDefaultAWSOptions(Configuration.GetAWSOptions()); services.AddAWSService<IAmazonDynamoDB>();
当我使用以下代码执行我的代码时,我收到异常“请求中包含的安全令牌无效”
我也尝试过从 appsettings.json 获取访问密钥和密钥
"AWS": { "Region": "ap-south-1", "AccessKey": "xxxxxxxxxxxxxxxxxxxx", "SecretKey": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" }
并在 startup.cs 文件的环境变量中设置这些凭据
services.AddDefaultAWSOptions(Configuration.GetAWSOptions());
services.AddMvc();
Environment.SetEnvironmentVariable("AWS_ACCESS_KEY_ID", Configuration["AWS:AccessKey"]);
Environment.SetEnvironmentVariable("AWS_SECRET_ACCESS_KEY", Configuration["AWS:SecretKey"]);
Environment.SetEnvironmentVariable("AWS_REGION", Configuration["AWS:Region"]);
services.AddAWSService<IAmazonDynamoDB>();
- 我仍然遇到同样的异常,请在下面找到堆栈跟踪:
在 E:\JenkinsWorkspaces\v3-stage-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Pipeline\ErrorHandler\HttpErrorResponseExceptionHandler.cs:line 中的 Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleException(IExecutionContext executionContext, HttpErrorResponseException 异常) 60 在 E:\JenkinsWorkspaces\v3-stage-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Pipeline\ErrorHandler\ErrorHandler.cs 中的 Amazon.Runtime.Internal.ErrorHandler.ProcessException(IExecutionContext executionContext, Exception exception): Amazon.Runtime.Internal.ErrorHandler.d__5 的第 212 行
1.MoveNext() in E:\JenkinsWorkspaces\v3-stage-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Pipeline\ErrorHandler\ErrorHandler.cs:line 104 --- 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() --- 从先前引发异常的位置结束堆栈跟踪 --- 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 的 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 Amazon .Runtime.Internal.CredentialsRetriever.d__71.MoveNext() in E:\JenkinsWorkspaces\v3-stage-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Pipeline\Handlers\CredentialsRetriever.cs:line 98 --- 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() --- 从先前引发异常的位置结束堆栈跟踪 --- 在 Amazon.Runtime.Internal.RetryHandler 的 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() .d__101.MoveNext() in E:\JenkinsWorkspaces\v3-stage-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Pipeline\RetryHandler\RetryHandler.cs:line 153 --- 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() --- 从先前引发异常的位置结束堆栈跟踪 --- 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 的 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 Amazon .Runtime.Internal.CallbackHandler.d__91.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() 在 E:\JenkinsWorkspaces\v3-stage-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Pipeline\Handlers\ErrorCallbackHandler.cs:line 58 ---从先前引发异常的位置结束堆栈跟踪 --- 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 Amazon.Runtime.Internal.MetricsHandler.d__1 的 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()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 System.Runtime.CompilerServices.TaskAwaiter
1.GetResult() 在 D:.Net Projects\TrainerExchange\proj\TXApi\DataAccess\Implementation\TrainerAccess.cs:line 47 中的 DataAccess.Implementation.TrainerAccess.d__6.MoveNext()
有人可以帮我解决这个问题吗?
如果我在这里遗漏任何东西,请告诉我。