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()
}