AWS SDK 配置中缺少凭据
AWS SDK Missing credentials in config
错误:可能未处理的承诺拒绝(id:0):
CredentialsError:配置中缺少凭据,如果使用 AWS_CONFIG_FILE,请设置 AWS_SDK_LOAD_CONFIG=1
我在 React Native (0.64.0) 项目中使用 "aws-sdk": "^2.918.0"。我是 运行 使用节点 v14.17.0 和 Windows 10 版本 21H1 OS build 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 查询数据库时,我收到此 CredentialsError,尽管我已在 AWS CLI 中配置了我的凭据 (aws-cli/2.2.6 Python/3.8.8 Windows/10 exe/AMD64 prompt/off)。你知道可能是什么问题吗?以及如何解决?
------------------------------------ 编辑 ------ ------------------------------
按照@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}
在您的 ~/.aws/config
文件中,您能否也尝试这样设置:
..
..
AWS_SDK_LOAD_CONFIG=1
或者,您可以尝试删除 ~/.aws/credentials
文件并将 aws_access_key_id
和 aws_secret_access_key
移动到 ~/.aws/config
文件,如下所示:
[default]
region=us-east-1
output=json
aws_access_key_id = XXX
aws_secret_access_key = XXX
首先感谢nishkaush和Jatin Mehrotra的帮助。最后,我解决问题的唯一方法是将 'accessKeyId' 和 'secretAccessKey' 直接添加到我的 AWS.config.update。这绝不是最终的解决方案,您应该避免将凭据直接放入您的代码(出于安全原因)。请注意,如果您打算使用此解决方案,则应通过 .env 文件设置您的凭据并将其添加到 gitignore 以保护您的凭据。我本来想使用共享凭据文件配置我的凭据,但我 运行 没时间了,问题仍然存在。如果对您有帮助,请查看:
AWS Getting Started in Node.js
AWS Loading Credentials in Node.js from the Shared Credentials File
话虽如此,问题可能与我正在使用 react native 有关,无论如何这是解决方案:
AWS.config.update({
maxRetries: 3,
httpOptions: {timeout: 30000, connectTimeout: 5000},
region: 'us-east-1',
accessKeyId: 'XXXX...',
secretAccessKey: 'XXXX...',
});
错误:可能未处理的承诺拒绝(id:0): CredentialsError:配置中缺少凭据,如果使用 AWS_CONFIG_FILE,请设置 AWS_SDK_LOAD_CONFIG=1
我在 React Native (0.64.0) 项目中使用 "aws-sdk": "^2.918.0"。我是 运行 使用节点 v14.17.0 和 Windows 10 版本 21H1 OS build 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 查询数据库时,我收到此 CredentialsError,尽管我已在 AWS CLI 中配置了我的凭据 (aws-cli/2.2.6 Python/3.8.8 Windows/10 exe/AMD64 prompt/off)。你知道可能是什么问题吗?以及如何解决?
------------------------------------ 编辑 ------ ------------------------------
按照@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}
在您的 ~/.aws/config
文件中,您能否也尝试这样设置:
..
..
AWS_SDK_LOAD_CONFIG=1
或者,您可以尝试删除 ~/.aws/credentials
文件并将 aws_access_key_id
和 aws_secret_access_key
移动到 ~/.aws/config
文件,如下所示:
[default]
region=us-east-1
output=json
aws_access_key_id = XXX
aws_secret_access_key = XXX
首先感谢nishkaush和Jatin Mehrotra的帮助。最后,我解决问题的唯一方法是将 'accessKeyId' 和 'secretAccessKey' 直接添加到我的 AWS.config.update。这绝不是最终的解决方案,您应该避免将凭据直接放入您的代码(出于安全原因)。请注意,如果您打算使用此解决方案,则应通过 .env 文件设置您的凭据并将其添加到 gitignore 以保护您的凭据。我本来想使用共享凭据文件配置我的凭据,但我 运行 没时间了,问题仍然存在。如果对您有帮助,请查看:
AWS Getting Started in Node.js
AWS Loading Credentials in Node.js from the Shared Credentials File
话虽如此,问题可能与我正在使用 react native 有关,无论如何这是解决方案:
AWS.config.update({
maxRetries: 3,
httpOptions: {timeout: 30000, connectTimeout: 5000},
region: 'us-east-1',
accessKeyId: 'XXXX...',
secretAccessKey: 'XXXX...',
});