错误:可能存在未处理的 Promise 拒绝 (ID: 0): 缺少配置中的凭据,如果使用 AWS_CONFIG_FILE,请设置 AWS_SDK_LOAD_CONFIG=1。
我在一个React Native(0.64.0)项目中使用“aws-sdk”:“^2.918.0”。我正在使用 node v14.17.0 运行程序,并在 Windows 10 版本 21H1 OS 构建 19043.985 上运行:
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
AWS.config.update({
region: 'us-east-1',
maxRetries: 3,
httpOptions: {timeout: 30000, connectTimeout: 5000},
});
// Create the DynamoDB service object
var ddb = new AWS.DynamoDB({
apiVersion: '2012-08-10',
});
console.log('ddb: ', ddb);
~/.aws/config
[default]
region=us-east-1
output=json
[profile myName]
region = us-east-1
output = json
~/.aws/credentials
[default]
aws_access_key_id=XXX...
aws_secret_access_key=XXX...
[mateo\.lara]
aws_access_key_id=XXX...
aws_secret_access_key=XXX...
在使用ddb查询数据库时,尽管我已经在AWS CLI(aws-cli/2.2.6 Python/3.8.8 Windows/10 exe/AMD64 prompt/off)中配置了我的凭证,但仍然出现CredentialsError错误。您知道问题可能是什么吗?如何解决?
-------------------------------------- 编辑 -------------------------------------
如@nishkaush建议的那样,我已尝试将AWS_SDK_LOAD_CONFIG=1添加到配置文件中,并尝试删除凭据文件并将aws_access_key_id和aws_secret_access_key添加到配置文件中,但均未成功。
以下为ddb日志输出:
ddb: {"CALL_EVENTS_BUBBLE": [Function CALL_EVENTS_BUBBLE], "MONITOR_EVENTS_BUBBLE": [Function EVENTS_BUBBLE], "_clientId": 1, "_events": {"apiCall": [[Function CALL_EVENTS_BUBBLE]], "apiCallAttempt": [[Function EVENTS_BUBBLE]]}, "config": {"apiVersion": "2012-08-10", "apiVersions": {}, "clientSideMonitoring":
false, "computeChecksums": true, "convertResponseTypes": true, "correctClockSkew": false, "credentialProvider": null, "credentials": null, "customUserAgent": null, "dynamoDbCrc32": true, "endpoint": "dynamodb.us-east-1.amazonaws.com", "endpointCacheSize": 1000, "endpointDiscoveryEnabled": undefined, "hostPrefixEnabled": true, "httpOptions": {"connectTimeout": 5000, "timeout": 30000}, "logger": null, "maxRedirects": 10, "maxRetries": 3, "paramValidation": true, "region": "us-east-1", "retryDelayOptions": {}, "s3BucketEndpoint": false, "s3DisableBodySigning": true, "s3ForcePathStyle": false, "s3UsEast1RegionalEndpoint": "legacy",
"s3UseArnRegion": undefined, "signatureCache": true, "signatureVersion": "v4", "sslEnabled": true, "stsRegionalEndpoints": "legacy", "systemClockOffset": 0, "useAccelerateEndpoint": false}, "endpoint": {"host": "dynamodb.us-east-1.amazonaws.com", "hostname": "dynamodb.us-east-1.amazonaws.com", "href": "https://dynamodb.us-east-1.amazonaws.com/", "path": "/", "pathname": "/", "port": 443, "protocol": "https:"}, "isGlobalEndpoint": false}
export AWS_SDK_LOAD_CONFIG=1
,如果错误仍然存在,请尝试将你的密钥添加到你的代码中,如下所示:aws.config.update({ region: "eu-west-1", endpoint: "http://localhost:8080", accessKeyId: “xxxxxx”, secretAccessKey: “xxxxxx” });
- Jatin Mehrotra