【发布时间】:2018-12-15 07:50:19
【问题描述】:
我有 ASP.NET Core 2 应用程序。我已经在 appsettings.json 中配置了 AWS
如下图
"AWS": {
"Profile": "default",
"ProfilesLocation": "D:\\_profiles\\awsprofile"
}
我确定我在该位置有可用的awsprofile 文件以及以下信息
[default]
aws_access_key_id = XXXXXX
aws_secret_access_key = XXXXXXXXXXX
然后我尝试创建如下所示的 S3Client 实例
var regionEndPoint = RegionEndpoint.GetBySystemName("us-west-1");
var client = new AmazonS3Client(regionEndPoint));
但是,我遇到了异常Unable to find the 'default' profile in CredentialProfileStoreChain.
应用程序启动异常:Amazon.Runtime.AmazonServiceException: 找不到凭据
异常 1(共 3 个):Amazon.Runtime.AmazonClientException:无法找到 CredentialProfileStoreChain 中的“默认”配置文件。在 Amazon.Runtime.FallbackCredentialsFactory.GetAWSCredentials(ICredentialProfileSource 来源)在 Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(布尔 fallbackToAnonymous)
异常 2 之 3:System.InvalidOperationException:环境 变量 AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY/AWS_SESSION_TOKEN 未使用 AWS 凭证设置。在 Amazon.Runtime.EnvironmentVariablesAWSCredentials.FetchCredentials()
在 Amazon.Runtime.EnvironmentVariablesAWSCredentials..ctor() 在 Amazon.Runtime.FallbackCredentialsFactory.c.b__9_1() 在 Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(布尔 fallbackToAnonymous)异常 3 之 3:System.Net.Http.HttpRequestException:响应 状态码不表示成功:404(未找到)。在 System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode() 在 System.Net.Http.HttpClient.d__27.MoveNext() --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)在 Amazon.Runtime.Internal.Util.AsyncHelpers.c__DisplayClass1_1
1.<<RunSync>b__0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Amazon.Runtime.Internal.Util.AsyncHelpers.ExclusiveSynchronizationContext.BeginMessageLoop() at Amazon.Runtime.Internal.Util.AsyncHelpers.RunSync[T](Func1 任务)
在 Amazon.Util.AWSSDKUtils.DownloadStringContent(Uri uri,TimeSpan 超时)在 Amazon.Runtime.URIBasedRefreshingCredentialHelper.GetContents(Uri uri) 在 Amazon.Runtime.InstanceProfileAWSCredentials.d__10.MoveNext() 在 Amazon.Runtime.InstanceProfileAWSCredentials.GetFirstRole() 在 Amazon.Runtime.FallbackCredentialsFactory.ECSEC2CredentialsWrapper()
在 Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(布尔 fallbackToAnonymous)在 Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous) 在 XXXXXXXXXXXXXXXXXXXXX.cs:line 30 at Api.Startup.ConfigureServices(IServiceCollection services) 中 D:\Jenkins\XXXXXXXXXXXXXXXXXXXXX\Src\Api\Startup.cs:第 75 行 --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection 服务)在 Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices() 在 Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication() 暴击:Microsoft.AspNetCore.Hosting.Internal.WebHost[6] 应用程序启动异常 Amazon.Runtime.AmazonServiceException:找不到凭据
异常 1(共 3 个):Amazon.Runtime.AmazonClientException:无法找到 CredentialProfileStoreChain 中的“默认”配置文件。在 Amazon.Runtime.FallbackCredentialsFactory.GetAWSCredentials(ICredentialProfileSource 来源)在 Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(布尔 fallbackToAnonymous)
异常 2 之 3:System.InvalidOperationException:环境 变量 AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY/AWS_SESSION_TOKEN 未使用 AWS 凭证设置。在 Amazon.Runtime.EnvironmentVariablesAWSCredentials.FetchCredentials()
在 Amazon.Runtime.EnvironmentVariablesAWSCredentials..ctor() 在 Amazon.Runtime.FallbackCredentialsFactory.c.b__9_1() 在 Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(布尔 fallbackToAnonymous)异常 3 之 3:System.Net.Http.HttpRequestException:响应 状态码不表示成功:404(未找到)。在 System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode() 在 System.Net.Http.HttpClient.d__27.MoveNext() --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)在 Amazon.Runtime.Internal.Util.AsyncHelpers.c__DisplayClass1_1
1.<<RunSync>b__0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Amazon.Runtime.Internal.Util.AsyncHelpers.ExclusiveSynchronizationContext.BeginMessageLoop() at Amazon.Runtime.Internal.Util.AsyncHelpers.RunSync[T](Func1 任务)
在 Amazon.Util.AWSSDKUtils.DownloadStringContent(Uri uri,TimeSpan 超时)在 Amazon.Runtime.URIBasedRefreshingCredentialHelper.GetContents(Uri uri) 在 Amazon.Runtime.InstanceProfileAWSCredentials.d__10.MoveNext() 在 Amazon.Runtime.InstanceProfileAWSCredentials.GetFirstRole() 在 Amazon.Runtime.FallbackCredentialsFactory.ECSEC2CredentialsWrapper()
在 Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(布尔 fallbackToAnonymous)在 Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous) 在 XXXXXXXXXXXXXXXXXXXXX: 第 30 行 Api.Startup.ConfigureServices(IServiceCollection services) 中 D:\Jenkins\XXXXXXXXXXXXXXXXXXXXX\Startup.cs:第 75 行 --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection 服务)在 Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices() 在 Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
未处理的异常:Amazon.Runtime.AmazonServiceException:无法 查找凭据
异常 1(共 3 个):Amazon.Runtime.AmazonClientException:无法找到 CredentialProfileStoreChain 中的“默认”配置文件。在 Amazon.Runtime.FallbackCredentialsFactory.GetAWSCredentials(ICredentialProfileSource 来源)在 Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(布尔 fallbackToAnonymous)
异常 2 之 3:System.InvalidOperationException:环境 变量 AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY/AWS_SESSION_TOKEN 未使用 AWS 凭证设置。在 Amazon.Runtime.EnvironmentVariablesAWSCredentials.FetchCredentials()
在 Amazon.Runtime.EnvironmentVariablesAWSCredentials..ctor() 在 Amazon.Runtime.FallbackCredentialsFactory.c.b__9_1() 在 Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(布尔 fallbackToAnonymous)异常 3 之 3:System.Net.Http.HttpRequestException:响应 状态码不表示成功:404(未找到)。在 System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode() 在 System.Net.Http.HttpClient.d__27.MoveNext() --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)在 Amazon.Runtime.Internal.Util.AsyncHelpers.c__DisplayClass1_1
1.<<RunSync>b__0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Amazon.Runtime.Internal.Util.AsyncHelpers.ExclusiveSynchronizationContext.BeginMessageLoop() at Amazon.Runtime.Internal.Util.AsyncHelpers.RunSync[T](Func1 任务)
在 Amazon.Util.AWSSDKUtils.DownloadStringContent(Uri uri,TimeSpan 超时)在 Amazon.Runtime.URIBasedRefreshingCredentialHelper.GetContents(Uri uri) 在 Amazon.Runtime.InstanceProfileAWSCredentials.d__10.MoveNext() 在 Amazon.Runtime.InstanceProfileAWSCredentials.GetFirstRole() 在 Amazon.Runtime.FallbackCredentialsFactory.ECSEC2CredentialsWrapper()
在 Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(布尔 fallbackToAnonymous)在 Amazon.Runtime.FallbackCredentialsFactory.GetCredentials(Boolean fallbackToAnonymous) 在 XXXXXXXXXXXXXXXXXXXXX: 第 30 行 XXXXXXXXXXXXXXXXXXXXX\Src\Api\Startup.cs:第 75 行 --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection 服务)在 Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices() 在 Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
在 Microsoft.AspNetCore.Hosting.WebHostBuilder.Build() 在 Api.Program.Main(String[] args) 在 D:\Jenkins\XXXXXXXXXXXXXXXXXXXXX\Src\Api\Program.cs:20行
【问题讨论】:
标签: c# amazon-web-services amazon-s3 aws-sdk