【发布时间】:2019-04-10 02:42:30
【问题描述】:
我有以下代码:
public void ConfigureServices(IServiceCollection services)
{
// AWS Options
var awsOptions = Configuration.GetAWSOptions();
services.AddDefaultAWSOptions(awsOptions);
var client = awsOptions.CreateServiceClient<IAmazonDynamoDB>();
var dynamoDbOptions = new DynamoDbOptions();
ConfigurationBinder.Bind(Configuration.GetSection("DynamoDbTables"), dynamoDbOptions);
services.AddScoped<IDynamoDbManager<MyModel>>(provider => new DynamoDbManager<MyModel>(client, dynamoDbOptions.MyModel));
}
public class DynamoDbManager<T> : DynamoDBContext, IDynamoDbManager<T> where T : class
{
private DynamoDBOperationConfig _config;
public DynamoDbManager(IAmazonDynamoDB client, string tableName) : base(client)
{
_config = new DynamoDBOperationConfig()
{
OverrideTableName = tableName
};
}
}
我的 Appsettings.json 为:
{
"AWS": {
"Region": "us-east-1",
"AwsId": "xxx",
"AwsPassword": "xxx"
},
"DynamoDbTables": {
"MyModel": "MyTable"
}
}
当我运行我的代码时,我收到了错误:
AmazonServiceException: Unable to find credentials
3 个中的第 1 个例外: Amazon.Runtime.AmazonClientException:无法在 CredentialProfileStoreChain 中找到“默认”配置文件。在 E:\JenkinsWorkspaces\v3-trebuchet-release\AWSDotNetPublic\sdk\src\Core\Amazon.Runtime\Credentials\FallbackCredentialsFactory.cs:line 72 中的 Amazon.Runtime.FallbackCredentialsFactory.GetAWSCredentials(ICredentialProfileSource 源)
例外 2 之 3: System.InvalidOperationException:环境变量 AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY/AWS_SESSION_TOKEN 未使用 AWS 凭证设置。
3 个中的第 3 个例外: System.Net.Http.HttpRequestException:发送请求时出错。 ---> System.Net.Http.WinHttpException: 操作超时 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
我尝试了很多方法,但没有成功。
我试过了:
将配置文件设置为: Amazon.Runtime.AmazonServiceException: Unable to find credentials
还尝试设置环境变量:
https://github.com/aws/aws-sdk-net/issues/499
但仍然无法克服这个错误。
【问题讨论】:
-
您是否尝试过使用调试器或添加一些 Console.WriteLine 语句来证明您的设置正确?例如,Configuration.GetSection("DynamoDbTables") 应该是 awsOptions.something 吗?
标签: c# amazon-web-services asp.net-core amazon-dynamodb aws-sdk