【发布时间】:2020-08-18 21:56:40
【问题描述】:
我正在使用 aws dynamodb 开发基于 nodejs 的 api。 API 工作正常,但今天我收到此错误:
{
"success": false,
"message": {
"message": "Missing region in config",
"code": "ConfigError",
"time": "2020-08-17T19:17:17.462Z"
}
}
下面是我的用户 api 路由:
const AWS = require('aws-sdk');
const config = require('config');
const { v4: uuidv4 } = require('uuid');
// Set the region
AWS.config.update({ region: 'us-east-2' });
router.post(`/api/user`, (req, res) => {
console.log('User Add Services Called');
try {
//Constants
AWS.config.update(config.aws_remote_config);
var params = {
TableName: config.aws_table_name,
Item: {
PK: `${uuidv4()}`,
SK: `User`,
name: 'Test'
}
};
//Calling DynamoDB to add the item to the table
docClient.put(params, function (err) {
if (err) {
res.send({
success: false,
message: err
});
} else {
res.send({
success: true,
message: 'User Added'
});
}
});
} catch (error) {
return res.status(500).json({
status: 'error',
message: 'An error occurred trying to process your request'
});
}
});
有时也会显示这些错误:
- 连接 ENETUNREACH 169.254.169.254:80
- 配置中缺少凭据,如果使用 AWS_CONFIG_FILE,请设置 AWS_SDK_LOAD_CONFIG=1
谁能告诉它为什么会发生,API 工作正常,我也尝试过重新生成访问密钥,但同样的问题来了
【问题讨论】:
-
还有什么解决方案吗?
-
使用 api 几天后遇到同样的问题。
标签: node.js api express amazon-dynamodb aws-sdk