Configuring region in Node.js AWS SDK

前端 未结 14 1540
失恋的感觉
失恋的感觉 2020-12-05 03:30

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.

14条回答
  •  眼角桃花
    2020-12-05 04:11

    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:

    1. Configure it programmatically (hard-coded): AWS.config.update({region:'your-region'});

    2. Use an environment variable. While the CLI uses AWS_DEFAULT_REGION, the Node SDK uses AWS_REGION.

    3. Load from a JSON file using AWS.config.loadFromPath('./config.json');

    JSON format:

    { 
        "accessKeyId": "akid", 
        "secretAccessKey": "secret", 
        "region": "us-east-1" 
    }
    

提交回复
热议问题