Can someone explain how to fix a missing config error with Node.js? I\'ve followed all the examples from the aws doc page but I still get this error no matter what.
How about changing the order of statements? Update AWS config before instantiating s3 and dd
var AWS = require('aws-sdk');
AWS.config.update({region:'us-east-1'});
var dd = new AWS.DynamoDB();
var s3 = new AWS.S3();
Best Practice would be to utilize an Amazon Cognito Identity pool.
Create an IAM Policy that defines the access to the resource you want. (Least Access Privilege)
Then create an Amazon Cognito Identity Pool allowing unauthenticated identities. Then attached the IAM Policy you created to the Unauthenticated Role for the Identity Pool.
Once that is setup you use the following code:
AWS.config.region = 'us-east-1';
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'IdentityPoolIdHere',
});
Amazon Cognito assumes the IAM Role specified in unauthenticated identities where Amazon STS is utilized in the background which then populates config with temporary credentials with accessibility as defined in the attached IAM Policy for the IAM Role.
I had the same issue "Missing region in config" and in my case it was that, unlike in the CLI or Python SDK, the Node SDK won't read from the ~\.aws\config
file.
To solve this, you have three options:
Configure it programmatically (hard-coded): AWS.config.update({region:'your-region'});
Use an environment variable. While the CLI uses AWS_DEFAULT_REGION
, the Node SDK uses AWS_REGION
.
Load from a JSON file using AWS.config.loadFromPath('./config.json');
JSON format:
{
"accessKeyId": "akid",
"secretAccessKey": "secret",
"region": "us-east-1"
}
To the comment above, you can always it run from your local global config file ~./aws/config by adding the following:
process.env.AWS_SDK_LOAD_CONFIG="true";
This will load your local global config file and use whatever credentials/account you are in which is really handy when iterating through multiple accounts / roles.
You can specify the region when creating the dynamodb connection (haven't tried s3 but that should work too).
var AWS = require('aws-sdk');
var dd = new AWS.DynamoDB({'region': 'us-east-1'});
var AWS = require('aws-sdk');
// assign AWS credentials here in following way:
AWS.config.update({
accessKeyId: 'asdjsadkskdskskdk',
secretAccessKey: 'sdsadsissdiidicdsi',
region: 'us-east-1'
});
var dd = new AWS.DynamoDB();
var s3 = new AWS.S3();