<legend id='StOqc'><style id='StOqc'><dir id='StOqc'><q id='StOqc'></q></dir></style></legend>
    1. <small id='StOqc'></small><noframes id='StOqc'>

        <i id='StOqc'><tr id='StOqc'><dt id='StOqc'><q id='StOqc'><span id='StOqc'><b id='StOqc'><form id='StOqc'><ins id='StOqc'></ins><ul id='StOqc'></ul><sub id='StOqc'></sub></form><legend id='StOqc'></legend><bdo id='StOqc'><pre id='StOqc'><center id='StOqc'></center></pre></bdo></b><th id='StOqc'></th></span></q></dt></tr></i><div id='StOqc'><tfoot id='StOqc'></tfoot><dl id='StOqc'><fieldset id='StOqc'></fieldset></dl></div>

      1. <tfoot id='StOqc'></tfoot>

        • <bdo id='StOqc'></bdo><ul id='StOqc'></ul>

        Net Core 2.0 AmazonServiceException:找不到凭证

        时间:2023-09-14

        <small id='6e3gc'></small><noframes id='6e3gc'>

        • <tfoot id='6e3gc'></tfoot>
            <tbody id='6e3gc'></tbody>
        • <i id='6e3gc'><tr id='6e3gc'><dt id='6e3gc'><q id='6e3gc'><span id='6e3gc'><b id='6e3gc'><form id='6e3gc'><ins id='6e3gc'></ins><ul id='6e3gc'></ul><sub id='6e3gc'></sub></form><legend id='6e3gc'></legend><bdo id='6e3gc'><pre id='6e3gc'><center id='6e3gc'></center></pre></bdo></b><th id='6e3gc'></th></span></q></dt></tr></i><div id='6e3gc'><tfoot id='6e3gc'></tfoot><dl id='6e3gc'><fieldset id='6e3gc'></fieldset></dl></div>
        • <legend id='6e3gc'><style id='6e3gc'><dir id='6e3gc'><q id='6e3gc'></q></dir></style></legend>

              <bdo id='6e3gc'></bdo><ul id='6e3gc'></ul>

                1. 本文介绍了Net Core 2.0 AmazonServiceException:找不到凭证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有以下代码:

                  public void ConfigureServices(IServiceCollection services){//AWS 选项var awsOptions = Configuration.GetAWSOptions();services.AddDefaultAWSOptions(awsOptions);var client = awsOptions.CreateServiceClient();var dynamoDbOptions = 新的 DynamoDbOptions();ConfigurationBinder.Bind(Configuration.GetSection("DynamoDbTables"), dynamoDbOptions);services.AddScoped<IDynamoDbManager<MyModel>>(provider => new DynamoDbManager<MyModel>(client, dynamoDbOptions.MyModel));}公共类 DynamoDbManager<T>: DynamoDBContext, IDynamoDbManager<T>其中 T :类{私有 DynamoDBOperationConfig _config;公共 DynamoDbManager(IAmazonDynamoDB 客户端,字符串 tableName):基础(客户端){_config = 新的 DynamoDBOperationConfig(){覆盖表名 = 表名};}}

                  我的 Appsettings.json 为:

                  <代码>{AWS":{"区域": "us-east-1",AwsId":xxx",AwsPassword":xxx"},DynamoDbTables":{我的模型":我的表"}}

                  当我运行我的代码时,我收到了错误:

                  AmazonServiceException:找不到凭证

                  3 个中的第 1 个例外:Amazon.Runtime.AmazonClientException:无法在 CredentialProfileStoreChain 中找到默认"配置文件.在 E:JenkinsWorkspacesv3-trebuchet-releaseAWSDotNetPublicsdksrcCoreAmazon.RuntimeCredentialsFallbackCredentialsFactory.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:无法找到凭据

                  还尝试设置环境变量:

                  https://github.com/aws/aws-sdk-net/issues/499

                  但仍然无法克服这个错误.

                  解决方案

                  所以当我们使用 AWS SDK 时,我们需要设置并提供一个 AWS 访问密钥 &一个密钥.从我所遇到的情况来看,它并没有直接从应用程序设置中读取.所以我发现下面是您可以设置这些凭据的两种工作方法.

                  方法一 - 使用凭证文件

                  您可以创建一个凭据文件并将您的凭据存储在那里.下面是文件的格式.

                  [默认]aws_access_key_id = 你的 id 放在这里aws_secret_access_key = 您的密码在此处

                  在上述文件中,default"是您的个人资料的名称.

                  创建上述文件后,您需要在 Appsettings.json 文件中指定相同的内容为:

                  "AWS": {配置文件":默认","ProfilesLocation": "C:\filelocation\awscredentials","区域": "us-east-1",}

                  方法二 - 设置和读取环境变量

                  我们可以在我们的startup.cs文件中设置环境变量如下:

                  Environment.SetEnvironmentVariable("AWS_ACCESS_KEY_ID", Configuration["AWS:AwsId"]);Environment.SetEnvironmentVariable("AWS_SECRET_ACCESS_KEY", Configuration["AWS:AwsPassword"]);Environment.SetEnvironmentVariable("AWS_REGION", Configuration["AWS:Region"]);

                  并从我们的 appSettings.json 文件中读取这些变量:

                  AWS": {"区域": "us-east-1",AwsId":xxxx",AwsPassword":xxxx"}

                  I have the following code:

                  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
                          };
                      }       
                  }
                  

                  My Appsettings.json is as:

                  {
                      "AWS": {
                          "Region": "us-east-1",
                          "AwsId": "xxx",
                          "AwsPassword": "xxx"
                      },
                      "DynamoDbTables": {
                          "MyModel": "MyTable"
                      }
                  }
                  

                  When I run my code I am getting the error:

                  AmazonServiceException: Unable to find credentials
                  

                  Exception 1 of 3: Amazon.Runtime.AmazonClientException: Unable to find the 'default' profile in CredentialProfileStoreChain. at Amazon.Runtime.FallbackCredentialsFactory.GetAWSCredentials(ICredentialProfileSource source) in E:JenkinsWorkspacesv3-trebuchet-releaseAWSDotNetPublicsdksrcCoreAmazon.RuntimeCredentialsFallbackCredentialsFactory.cs:line 72

                  Exception 2 of 3: System.InvalidOperationException: The environment variables AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY/AWS_SESSION_TOKEN were not set with AWS credentials.

                  Exception 3 of 3: System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.Http.WinHttpException: The operation timed out at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

                  I have tried many things but not getting this to work.

                  I have tried:

                  Setting up profile as: Amazon.Runtime.AmazonServiceException: Unable to find credentials

                  And also tried settingup of environment variables:

                  https://github.com/aws/aws-sdk-net/issues/499

                  But still cannot get past this error.

                  解决方案

                  So when we are using AWS SDK we need to setup and provide an AWS access key & a secret key. And from what I have come across it does not read directly from the app settings. So I found below are the two working methods with which you can set these credentials.

                  Method 1 - Using Credentials file

                  You can create a credentials file and store your credentials there. Below is the format of the file.

                  [default]
                  aws_access_key_id = your id goes here
                  aws_secret_access_key = your password goes here
                  

                  In above file, "default" is the name of your profile.

                  After creating the above file you need to specify the same in Appsettings.json file as:

                  "AWS": {
                      "Profile": "default",
                      "ProfilesLocation": "C:\filelocation\awscredentials",
                      "Region": "us-east-1",
                     }
                  

                  Method 2 - Setting and Reading from Environment Variables

                  We can setup the environment variables in our startup.cs file as below:

                  Environment.SetEnvironmentVariable("AWS_ACCESS_KEY_ID", Configuration["AWS:AwsId"]);
                  Environment.SetEnvironmentVariable("AWS_SECRET_ACCESS_KEY", Configuration["AWS:AwsPassword"]);
                  Environment.SetEnvironmentVariable("AWS_REGION", Configuration["AWS:Region"]); 
                  

                  And read these variables from our appSettings.json file as:

                  AWS": {
                          "Region": "us-east-1",
                          "AwsId": "xxxx",
                          "AwsPassword": "xxxx"
                        }
                  

                  这篇关于Net Core 2.0 AmazonServiceException:找不到凭证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:DynamoDB .NET - 从表中删除所有项目 下一篇:全球二级索引的 DynamoDB 一致性读取

                  相关文章

                2. <tfoot id='N9eJf'></tfoot>

                    <legend id='N9eJf'><style id='N9eJf'><dir id='N9eJf'><q id='N9eJf'></q></dir></style></legend>

                    <small id='N9eJf'></small><noframes id='N9eJf'>

                    • <bdo id='N9eJf'></bdo><ul id='N9eJf'></ul>
                    1. <i id='N9eJf'><tr id='N9eJf'><dt id='N9eJf'><q id='N9eJf'><span id='N9eJf'><b id='N9eJf'><form id='N9eJf'><ins id='N9eJf'></ins><ul id='N9eJf'></ul><sub id='N9eJf'></sub></form><legend id='N9eJf'></legend><bdo id='N9eJf'><pre id='N9eJf'><center id='N9eJf'></center></pre></bdo></b><th id='N9eJf'></th></span></q></dt></tr></i><div id='N9eJf'><tfoot id='N9eJf'></tfoot><dl id='N9eJf'><fieldset id='N9eJf'></fieldset></dl></div>