0

Using .net core here:

I am having the following issue while connecting to my AWS dynamo db.

Below is my startup class

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<UserData>>(provider => new DynamoDbManager<UserData>(client, dynamoDbOptions.UserData));

}   

Below is my appsettings:

"AWS": {
"Region": "us-east-1",
"AwsId": "xxxx",
"AwsPassword": "xxxxx"
 },
"DynamoDbTables": {
"UserData": "UserDataTest"
 }  

FYI below is my DynamoDbManager class:

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

When I run my app it gives me error as:

An error occurred while starting the application.

AmazonServiceException: Unable to find credentials

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

But I never set my environment credentials before and it was working fine. Not sure what changed now and started giving me this error.

aman
  • 4,198
  • 4
  • 24
  • 36
  • Then I would guess that the error message is misleading and that you previously provided credentials using some other mechanism (~/.aws/credentials file or IAM role, for example) and perhaps you changed that to cause it to no longer work. – jarmod Nov 05 '18 at 23:44
  • @jarmod my code with above was working. I was not using any credentials file. The only thing I did was downloaded the AWS sdk and configured the credentials there as I wanted to try out some s3 bucket code. Now even after deleting those profiles in AWS sdk I get this error. – aman Nov 06 '18 at 00:57
  • I'm not too familiar with the AWS .Net SDK but I don't see *any* AWS SDK calls in your code. The code you've shown seems to build an abstraction for configuration reading and creates a number of interface objects, whose definition and use we cannot see. There seems to be a lot missing here. Can you net this down to a simple, complete AWS SDK client that exhibits the problem? – jarmod Nov 06 '18 at 02:11
  • @jarmod I just have removed aws toolkit from my machine and it still gives the same error. Not sure what the issue is now. I have to see what else I can do here. – aman Nov 06 '18 at 03:08
  • For anyone else visiting this, I have resolved and posted my answer here: https://stackoverflow.com/questions/53176420/net-core-2-0-amazonserviceexception-unable-to-find-credentials – aman Nov 09 '18 at 15:19

0 Answers0