reactjs – React aws-sdk “ConfigError: Missing region in config” after setting region DynamoDB
I have set the region in the AWS.config at the start of my code. I confirmed it was set properly before calling the DocClient.scan function. However, on running the code, I get an error that the region is missing in the config.
region:’us-east-1′ —- ConfigError: Missing region in config
index.js
import * as AWS from 'aws-sdk'
const configuration = {
region: 'us-east-1',
secretAccessKey: 'SECRETKEYHERE',
accessKeyId: 'KEYIDHERE'
}
AWS.config.update(configuration)
AwsFunctions.js
import * as AWS from 'aws-sdk'
const docClient = new AWS.DynamoDB.DocumentClient()
export const scanTable = async (tableName) => {
const params = {
TableName: tableName,
};
console.log(AWS.config);
const scanResults = [];
var items;
do{
items = await docClient.scan(params).promise();
items.Items.forEach((item) => scanResults.push(item));
params.ExclusiveStartKey = items.LastEvaluatedKey;
}while(typeof items.LastEvaluatedKey !== "undefined");
return scanResults;
};
export const putData = (tableName , data) => {
var params = {
TableName: tableName,
Item: data
}
docClient.put(params, function (err, data) {
if (err) {
console.log('Error', err)
} else {
console.log('Success', data)
}
})
}
Read more here: Source link