Net Core 2.0 AmazonServiceException: Unable to find credentials

后端 未结 1 561
我寻月下人不归
我寻月下人不归 2021-01-23 08:37

I have the following code:

public void ConfigureServices(IServiceCollection services)
{
    // AWS Options
    var awsOptions = Configuration.GetAWSOptions();
           


        
相关标签:
1条回答
  • 2021-01-23 09:02

    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"
          }
    
    0 讨论(0)
提交回复
热议问题