Error: Possible Unhandled Promise Rejection (id: 0): CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
I am using "aws-sdk": "^2.918.0" in a react native (0.64.0) project. I am running the program using node v14.17.0 and on a Windows 10 version 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...
When using ddb to query the database, I am getting this CredentialsError, despite having configured my credential in AWS CLI (aws-cli/2.2.6 Python/3.8.8 Windows/10 exe/AMD64 prompt/off). Do you know what the problem could be? And how to solve it?
-------------------------------------- EDIT -------------------------------------
As suggested by @nishkaush I have tried adding AWS_SDK_LOAD_CONFIG=1 to the config file, and I have tried deleting the credential file and adding aws_access_key_id and aws_secret_access_key to the config file without success.
Here is the output of the ddb log:
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}
First of all, thank nishkaush and Jatin Mehrotra for their help. In the end, the only way I could solve my problem was by adding the 'accessKeyId' and 'secretAccessKey' directly to my AWS.config.update. This is not by any means a final solution, and you should avoid putting the credentials directly to your code (security reasons). Be aware that if you intend to use this solution, you should set your credentials through a.env file and add it to a gitignore to protect your credentials. I would have liked to configure my credentials using the shared credentials file, but I am running out of time, and the problem persists. If it is of any help, please check:
AWS Getting Started in Node.js
AWS Loading Credentials in Node.js from the Shared Credentials File
Having said that, the problem may be related to the fact that I am working with react native, anyway here is the solution:
AWS.config.update({
maxRetries: 3,
httpOptions: {timeout: 30000, connectTimeout: 5000},
region: 'us-east-1',
accessKeyId: 'XXXX...',
secretAccessKey: 'XXXX...',
});
In your ~/.aws/config
file, could you try setting this as well:
..
..
AWS_SDK_LOAD_CONFIG=1
Alternatively, you can try deleting ~/.aws/credentials
file and move both aws_access_key_id
and aws_secret_access_key
to ~/.aws/config
file instead, something like so:
[default]
region=us-east-1
output=json
aws_access_key_id = XXX
aws_secret_access_key = XXX
You can also set
s3.config.s3UseArnRegion = true;
condition if you get error related to s3UseArnRegion undefined
In my case, the error was caused due to incorrect credentials. My identityPoolID
value was erroneously stored as undefined
due to a parsing error.
I was facing the same issue, I resolved it by
credentials
in the file ~/.aws/credentials
.[default]
aws_access_key_id = XXXXX
aws_secret_access_key = XXXXX
AWS_SDK_LOAD_CONFIG
in the file ~/.aws/config
.[default]
AWS_SDK_LOAD_CONFIG=1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.