我正在使用 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。再次以 root 用户身份使用 AWS CLI 创建它们。这有两个障碍。
第一个是 - 我正在使用 pm2 来运行我的节点服务器。它以根用户身份以及另一个用户配置文件运行服务器的多个实例。
第二个可能与用户访问有关。仍然不确定为什么它不从已经存在的文件中读取凭据。我也创建了环境变量。我已经有两个提供商,但仍然没有从他们那里获取密钥....
下面是任何遇到与提供商相关的问题的人的文档链接。
https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html#cli-quick-configuration
仅供记录:我们昨天遇到了同样的问题,很难找到原因......项目中和
~/.aws/credentials
中的配置是正确的,但我们仍然遇到错误。
原因是 ~/.zshrc
.zshrc
中,环境变量 AWS_PROFILE
设置为已过时的配置文件,该配置文件不再存在于 ~/.aws/credentials
中。因此,不知何故,这个 AWS_PROFILE
的值覆盖了我们在 AWS_PROFILE
中定义的环境变量 .env
集的值。
通过从
AWS_PROFILE
中删除 .zshrc
,问题就消失了。