我使用这里中的一个例子,以便在c#代码中从AWS SecretsManager中撤回一个秘密。
我已经通过AWS在本地设置了凭据,并且我能够使用AWS命令"aws秘密管理器列表-机密“撤回秘密列表。
但是c#控制台应用程序出错了:
> Unhandled exception. System.AggregateException: One or more errors occurred. (Unable to get IAM security credentials from EC2 Instance Metadata Service.)
---> Amazon.Runtime.AmazonServiceException: Unable to get IAM security credentials from EC2 Instance Metadata Service.
at Amazon.Runtime.DefaultInstanceProfileAWSCredentials.FetchCredentials()
at Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentials()
at Amazon.Runtime.DefaultInstanceProfileAWSCredentials.GetCredentialsAsync()
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.Runtime.Internal.ErrorCallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
at Amazon.Runtime.Internal.MetricsHandler.InvokeAsync[T](IExecutionContext executionContext)
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task`1.get_Result()
at AWSConsoleApp2.GetSecretValueFirst.GetSecret() in D:\Work\Projects\Training\AWSConsoleApp2\AWSConsoleApp2\GetSecretValueFirst.cs:line 53
at AWSConsoleApp2.Program.Main(String[] args) in D:\Work\Projects\Training\AWSConsoleApp2\AWSConsoleApp2\Program.cs:line 11
当我更改原始构造函数调用时
IAmazonSecretsManager client =新的AmazonSecretsManagerClient();
添加AWSCredentials类型的继承参数
IAmazonSecretsManager client =新AmazonSecretsManagerClient(新StoredProfileAWSCredentials());
效果很好。
类StoredProfileAWSCredentials是过时的,但它可以使用它。我使用在其他机器上工作而没有错误的库,并且不能更改它们。
我对属于Administrators组并完全访问SecretsMnager的用户使用凭据。区域已在c#代码中正确设置,配置文件是默认的。
有什么想法吗?谢谢你提前
发布于 2021-07-29 20:17:19
只需在控制面板AWS_ACCESS_KEY_ID和AWS_SECRET_ACCESS_KEY中添加env变量即可。两者的实际价值并不重要。我把它们都设成了一个空格。不知道它为什么会起作用,但它起作用了。似乎需要更长的时间才能登录。看起来,SDK没有进入buggy流,而是尝试使用env,大约在30秒后按要求登录。
在没有安装AWS或配置任何Win10配置文件的两台不同的Win10 PC上测试它。该问题被重新100%和所描述的w/a固定。
https://stackoverflow.com/questions/60815037
复制相似问题