在使用Node.js的aws-sdk时,使用`~/.aws/credentials`的方法

创建以下的配置文件

[default]
aws_access_key_id = xxxxxx
aws_secret_access_key = yyyyy
region = ap-northeast-1

如果执行以下操作,会出现配置文件中缺少地区的错误提示。

const AWS = require('aws-sdk')

const config = AWS.Config
const eb = new AWS.ElasticBeanstalk()

eb.describeEnvironments({EnvironmentNames: ['hogehoge']}, (err, data) => {
    console.log(err)
    console.log(data)
})
$ node app.js
{ ConfigError: Missing region in config
....

如果要使用config文件,则需要设置AWS_SDK_LOAD_CONFIG=true。

$ env AWS_SDK_LOAD_CONFIG=true node app.js

请参考以下链接:https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-region.html