Configuring region in Node.js AWS SDK
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();
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 usesAWS_REGION
.Load from a JSON file using
AWS.config.loadFromPath('./config.json');
JSON format:
{ "accessKeyId": "akid", "secretAccessKey": "secret", "region": "us-east-1" }
If you work with AWS CLI, you probably have a default region defined in ~/.aws/config. Unfortunately AWS SDK for JavaScript does not load it by default. To load it define env var
AWS_SDK_LOAD_CONFIG=1