node.js - 无法从 NodeJS 中的任何提供程序加载凭据
问题描述
我正在使用 AWSservices,所以我正在为 nodeJS 使用“aws-sdk”包。根据他们在官方网站上的说明,他们要求在您当前的用户配置文件中创建一个 .aws 文件夹,并在其中创建带有秘密和访问密钥的凭据文件。
AWS 文档链接 -
https://aws.amazon.com/developers/getting-started/nodejs/
我在 windows 和 ubuntu 上遵循相同的程序。在 Windows 中,AWS 服务运行良好,但是当我将代码设置上传到 AWS ubuntu 实例时,它开始出现以下错误。
{
"message": "Missing credentials in config",
"retryable": false,
"time": "2019-05-13T12:34:45.834Z",
"code": "CredentialsError",
"originalError": {
"message": "Could not load credentials from any providers",
"retryable": false,
"time": "2019-05-13T12:34:45.834Z",
"code": "CredentialsError"
}
}
这是我在 JS 文件中包含“aws-sdk”的代码。
const AWS = require('aws-sdk');
const {
saveUserTokens,
updateMigratedUser
} = require('./databaseOperations');
const AWS_REGION = "us-west-2";
const CLIENT_ID = "5f70t79un9ep945645k5rooqocr4mfg";
const USER_POOL_ID = "us-west-2_xxxxx";
AWS.config.update({ region: AWS_REGION });
const cognitoidentityserviceprovider = new AWS.CognitoIdentityServiceProvider();
AWS.config 对象的控制台日志 -
Config {
credentials:
SharedIniFileCredentials {
expired: false,
expireTime: null,
refreshCallbacks: [],
accessKeyId: 'XXXXXXXXXXXXXXX',
sessionToken: undefined,
filename: undefined,
profile: 'default',
disableAssumeRole: true,
preferStaticCredentials: false,
tokenCodeFn: null,
httpOptions: null },
credentialProvider:
CredentialProviderChain {
providers:
[ [Function],
[Function],
[Function],
[Function],
[Function],
[Function] ],
resolveCallbacks: [] },
region: 'us-west-2',
logger: null,
apiVersions: {},
apiVersion: null,
endpoint: undefined,
httpOptions: { timeout: 120000 },
maxRetries: undefined,
maxRedirects: 10,
paramValidation: true,
sslEnabled: true,
s3ForcePathStyle: false,
s3BucketEndpoint: false,
s3DisableBodySigning: true,
computeChecksums: true,
convertResponseTypes: true,
correctClockSkew: false,
customUserAgent: null,
dynamoDbCrc32: true,
systemClockOffset: 0,
signatureVersion: null,
signatureCache: true,
retryDelayOptions: {},
useAccelerateEndpoint: false,
clientSideMonitoring: false,
endpointDiscoveryEnabled: false,
endpointCacheSize: 1000,
hostPrefixEnabled: true }
解决方案
问题已解决。我删除了 .aws/credentials。再次以根用户身份使用AWS CLI创建它们。这有两个障碍。
第一个是 - 我正在使用 pm2 来运行我的节点服务器。它作为 root 用户以及另一个用户配置文件运行服务器的多个实例。
其次可能与用户访问有关。仍然不确定为什么它不从已经存在的文件中读取凭据。我也创建了环境变量。我已经有两个提供商,但仍然没有从他们那里挑选钥匙....
以下是面临与提供商相关的此问题的任何人的文档链接。
https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html#cli-quick-configuration
推荐阅读
- autohotkey - 按钮自动激活
- angular - Formbuilder反应表单的自定义名称 - Angular 7
- ag-grid - 事件侦听器在网格之外工作,但在 ag-grid 中的单元格内不起作用
- google-sheets - 谷歌表格公式计算一列中与另一张表中的多列匹配的值的总和
- python-3.x - 在预测期间使用来自 tensorflow hub 的 Elmo 作为自定义 tf.keras 层的问题
- perl - 如何在perl中的列表中间添加一个项目
- angular - 打字稿:花括号作为函数参数
- latex - 如何在 nativescript-vue 中渲染编写复杂的数学方程?
- vim - 如何在 vimdiff 中合并来自一个修订版的两行和来自另一修订版的第三行?
- swift - Facebook-IOS-SDK pod 安装问题