1

我正在尝试使用 AWS .NET 核心 SDK 在 dynamodb 中插入记录,但出现以下异常:

请求中包含的安全令牌无效。

请在下面找到我为连接它所做的步骤:

  1. 在 IAM 中创建了一个新的访问密钥。
  2. 在本地下载访问密钥和密钥。
  3. 在 C:/users//.aws/ 中创建了文件名凭据
  4. 在文件中添加了以下代码(出于安全目的删除了凭据)

    [default] aws_access_key_id = xxxxxxxxxxxxxxxxxxxx aws_secret_access_key = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

  5. 在 appsettings.json 文件中添加了以下代码:

    "AWS":{ "Region": "ap-south-1", "Profile": "default"}

  6. 在 startup.cs 的 ConfigureServices 方法中,我添加了以下代码: services.AddDefaultAWSOptions(Configuration.GetAWSOptions()); services.AddAWSService<IAmazonDynamoDB>();

  7. 当我使用以下代码执行我的代码时,我收到异常“请求中包含的安全令牌无效”

  8. 我也尝试过从 appsettings.json 获取访问密钥和密钥 "AWS": { "Region": "ap-south-1", "AccessKey": "xxxxxxxxxxxxxxxxxxxx", "SecretKey": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" }

  9. 并在 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>();

  1. 我仍然遇到同样的异常,请在下面找到堆栈跟踪:

在 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__91.MoveNext() --- 从先前引发异常的位置结束堆栈跟踪 --- 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 的 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 Amazon .Runtime.Internal.CredentialsRetriever.d__7 1.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__101.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__91.MoveNext() --- 从先前引发异常的位置结束堆栈跟踪 --- 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 的 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 Amazon .Runtime.Internal.CallbackHandler.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.ErrorCallbackHandler.<InvokeAsync>d__51.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.TaskAwaiter1.GetResult() 在 D:.Net Projects\TrainerExchange\proj\TXApi\DataAccess\Implementation\TrainerAccess.cs:line 47 中的 DataAccess.Implementation.TrainerAccess.d__6.MoveNext()

有人可以帮我解决这个问题吗?

如果我在这里遗漏任何东西,请告诉我。

4

1 回答 1

1

在此处输入图像描述

在这里,验证您在 AWS Explorer 中所选配置文件的访问密钥 ID 和秘密访问密钥。由于配置文件中的错误凭据,会创建此问题。或者如果您不需要配置文件,只需将其删除。

于 2019-06-19T12:56:41.913 回答