0

I've been stuck on this for a while now...

I used aws configure to set up my credentials/region but every time I try to store in DynamoDB, I get a 'Missing credentials in config' error. I'm using Javascript, and when I test by hardcoding the region in, it will complain about not finding my credentials. Finally, if I hardcode everything, it works flawlessly. The issue shouldn't be with the credentials but somehow with the ability to find them locally.

config file(Users/myuseraccount/.aws/config):

[default]
region = us-east-1
output = json

credential file(Users/myuseraccount/.aws/credentials):

[default]
aws_access_key_id = <MyAccessKey>
aws_secret_access_key = <MySecretKey>

I don't fully understand the implications of the below text, but it happens when I run aws configure list (maybe this will help someone understand the issue). I just removed the keys from being shown, but they are shown for me.

 Name                       Value             Type                       Location
      ----                    -----           ----                       --------
   profile                <not set>           None                         None
access_key              <accesskeyremoved>    shared-credentials-file    
secret_key              <secretkeyremoved>    shared-credentials-file    
    region                us-east-1           config-file               ~/.aws/config

Edit: Added connection to DynamoDB

var AWS = require('aws-sdk');
AWS.config.region = 'us-east-1';

export async function putUser(userId, firstName, lastName, email, school, program, password) {
  var ddb = new AWS.DynamoDB();
  var params = {
    TableName: 'loci-users',
    Item: {
      'user_id' : { S: userId },
      'first_name' : { S: firstName },
      'last_name' : { S: lastName },
      'email' : { S: email },
      'password' : { S: password },
      'school' : { S: school },
      'program' : { S: program},
    }
  }

  ddb.putItem(params, function(err, data) {
    if (err) {
      console.log("Error", err);
      return false;
    } else {
      console.log("Success", data);
    }
    return true;
  });

}

export async function getUser(email) {
  var ddb = new AWS.DynamoDB.DocumentClient();
  var params = {
    TableName: 'loci-users',
    IndexName: 'email-index',
    KeyConditionExpression: "email = :email",
    ExpressionAttributeValues: { ":email": email }
  }
  let userData = await ddb.query(params).promise()
  return userData.Items.pop()
}
korum
  • 172
  • 1
  • 14
  • 1
    Can you share your code that tries to connect to DynamoDB? Also, what is the pathing to your node script? e.g. `Users/myuseraccount/code/myscript.js` – Gary Holiday Jan 26 '20 at 20:38
  • 1
    Presumably the effective user when running these scripts is the same each time (myuseraccount in your example)? Show us the code used to create session/client objects. – jarmod Jan 26 '20 at 23:21
  • I just added the connection code! It seems to work if I hardcode the credentials directly here, but maybe I'm missing something crucial. – korum Jan 27 '20 at 14:28
  • As for the path, it's automatically set up through 'aws configure', so I believe it should place the config and credentials file in the correct location. I didn't create any scripts on my own. Yes, the user will always be the same. – korum Jan 27 '20 at 14:39
  • I actually just got it to work... I used Amazon Cognito to allow unauth access and then added the identity pool into the code. Do you guys know if this is the recommended method? – korum Jan 27 '20 at 15:10

0 Answers0