CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
Confirm by changing [ ] to [x] below to ensure that it's a bug:
- [x ] I've gone through Developer Guide and API reference
- [x ] I've checked AWS Forums and StackOverflow for answers
- [ x] I've searched for previous similar issues and didn't find any solution
Describe the bug
I use AWS javascript SDK for enabling my web app clients upload their files to my s3 bucket. But for some client the "managed upload" getting failed (not always but often). Could you please help me debug this, as i am sure i correctly followed all steps mentioned in docs. Please see below for details:
ERROR REPORT
CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
at r (https://sdk.amazonaws.com/js/aws-sdk-2.818.0.min.js?_=1615666287497:78:2417 )
at constructor.getCredentials (https://sdk.amazonaws.com/js/aws-sdk-2.818.0.min.js?_=1615666287497:78:2945 )
at constructor.<anonymous> (https://sdk.amazonaws.com/js/aws-sdk-2.818.0.min.js?_=1615666287497:79:3316 )
at constructor.callListeners (https://sdk.amazonaws.com/js/aws-sdk-2.818.0.min.js?_=1615666287497:81:6740 )
at constructor.emit (https://sdk.amazonaws.com/js/aws-sdk-2.818.0.min.js?_=1615666287497:81:6480 )
at constructor.emitEvent (https://sdk.amazonaws.com/js/aws-sdk-2.818.0.min.js?_=1615666287497:80:24217 )
at constructor.e (https://sdk.amazonaws.com/js/aws-sdk-2.818.0.min.js?_=1615666287497:80:19827 )
at i.runTo (https://sdk.amazonaws.com/js/aws-sdk-2.818.0.min.js?_=1615666287497:82:30056 )
at constructor.runTo (https://sdk.amazonaws.com/js/aws-sdk-2.818.0.min.js?_=1615666287497:80:21515 )
at constructor.send (https://sdk.amazonaws.com/js/aws-sdk-2.818.0.min.js?_=1615666287497:80:21408 )
SDK script used : https://sdk.amazonaws.com/js/aws-sdk-2.864.0.min.js
AWS initialization Code :
function initializeS3() {
var albumBucketName = aws_details.bucket_name;
var bucketRegion = aws_details.bucket_region;
var IdentityPoolId = aws_details.identity_pool_id;
var IdentityPoolRegion = aws_details.identity_pool_region;
$("#upload-box").draggable();
if(typeof(AWS) != 'undefined') {
console.log("initializing s3 : done");
AWS.config.region = bucketRegion;
AWS.config.update({
region: IdentityPoolRegion,
credentials: new AWS.CognitoIdentityCredentials({
IdentityPoolId: IdentityPoolId
})
});
globalBucket = new AWS.S3({
apiVersion: '2006-03-01',
params: {Bucket: albumBucketName},
httpOptions: {timeout: 1800000}
});
}
else {
console.log("initializing s3 : redo");
setTimeout(initializeS3, 1000);
}
}
UPLAOD CODE:
function process_uq(startingIndex, endingIndex) {
for(current_index = startingIndex; current_index <= endingIndex; current_index++) {
var current_item = global_upload_queue[current_index];
var total_file_size = current_item.size;
var params = {
Bucket: aws_details.bucket_name,
Key: current_item.aws_key,
Body: current_item.file,
ACL: "public-read"
};
global_ongoing_xhr_count++;
global_upload_queue[current_index]['upload_instance'] = new AWS.S3.ManagedUpload({queueSize : 3, partSize : const_min_chunk_size, params : params});
global_upload_queue[current_index]['upload_instance'].on('httpUploadProgress', function(evt) {
var local_uploadPartParams = this.service.config.params;
//for getting queue index from upload id
for(xyz in global_upload_queue) {
if(global_upload_queue[xyz]['aws_key'] == local_uploadPartParams['Key']) {
var local_index = xyz;
}
}
//global_upload_queue[local_index]['total_size_uploaded'] += evt.loaded;
showProgressBarMulti({
uq_index : local_index,
loaded : evt.loaded
});
});
var promise = global_upload_queue[current_index]['upload_instance'].promise();
promise.then(
function(data) {
global_ongoing_xhr_count--;
//for getting queue index from upload id
for(xyz in global_upload_queue) {
if(global_upload_queue[xyz]['aws_key'] == data.Key) {
local_index = xyz;
}
}
var index = local_index;
completeMultiPartUpload(index);
},
function(err) {
console.log("retrying : process_uq(" + startingIndex + ", " + endingIndex + ")");
if(!global_upload_cancelled) {
setTimeout(function() {
process_uq(startingIndex, endingIndex);
sendErrorLogToServer(err.stack);
}, 10000);
}
}
);
}
}
Is the issue in the browser/Node.js? Browser
SDK version number https://sdk.amazonaws.com/js/aws-sdk-2.864.0.min.js
To Reproduce (observed behavior) It is sometime working and sometime failing
I have the same issue, with the latest releases of the AWS sdk. Any help?
+1
Hi there, have you tried explicitly setting the credentials in the constructor, I suspect that they get overwritten when the S3 client is initialized.
Basically doing something like:
var s3 = new aws.S3({region: 'us-west-2', credentials: creds});
May also wanna check if they are getting set with using something like:
console.log(s3.config.credentials)
Also can you point out what documentation you followed?
This issue has not received a response in 1 week. If you still think there is a problem, please leave a comment to avoid the issue from automatically closing.
Experiencing a similar challenge to this myself.
@vinithisonline did you solve it?
Same problem
Same problem here
+1, same problem
same issue : CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
BadRequestException: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
I am using "ibm-cos-sdk": "1.10.2" and I have the same problem.
did anyone figure this problem out? I'm having the same issue
@ajredniwja "I suspect that they get overwritten when the S3 client is initialized". That was the main reason in my case. I just have to call
var s3 = new aws.S3({region: 'us-west-2', credentials: creds});
in each function.
So in my case, the error is misleading. I looked at where it was thrown and it's actually the region and a totally different message (that then gets rewritten somehow). If it points to this code:
add('VALIDATE_REGION', 'validate', function VALIDATE_REGION(req) {
if (!req.service.isGlobalEndpoint) {
var dnsHostRegex = new RegExp(/^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9])$/);
if (!req.service.config.region) {
req.response.error = AWS.util.error(new Error(),
{code: 'ConfigError', message: 'Missing region in config'}); // <<< *exception points to here*
} else if (!dnsHostRegex.test(req.service.config.region)) {
req.response.error = AWS.util.error(new Error(),
{code: 'ConfigError', message: 'Invalid region in config'});
}
}
});
Then this is a bug in the service constructor (in my case AWS.Location) and documentation that suggests region can be filled with a string. It may be, but it also has to be set in AWS.config.region. Working example code:
AWS.config.region = 'eu-central-1'
const credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'eu-central-1:your-id-here',
})
const locationClient = new AWS.Location({
credentials,
})
The above solution mentioned by @melvyn-apryl is correct. I was facing the same issue and this one worked for me. :)
same issue here when I try to check "Experiments and Trials" inside Sagemaker Studio:
why this issue was closed?
same issue : CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
exactly the same the error
here it is..... CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
at credError (webpack-internal:///(:3000/app-pages-browser)/./node_modules/aws-sdk/lib/config.js:400:40)
at Config.getCredentials (webpack-internal:///(:3000/app-pages-browser)/./node_modules/aws-sdk/lib/config.js:441:14)
at Request.VALIDATE_CREDENTIALS (webpack-internal:///(:3000/app-pages-browser)/./node_modules/aws-sdk/lib/event_listeners.js:112:28)
at Request.callListeners (webpack-internal:///(:3000/app-pages-browser)/./node_modules/aws-sdk/lib/sequential_executor.js:102:18)
at Request.emit (webpack-internal:///(:3000/app-pages-browser)/./node_modules/aws-sdk/lib/sequential_executor.js:78:10)
at Request.emit (webpack-internal:///(:3000/app-pages-browser)/./node_modules/aws-sdk/lib/request.js:687:14)
at Request.transition (webpack-internal:///(:3000/app-pages-browser)/./node_modules/aws-sdk/lib/request.js:23:10)
at AcceptorStateMachine.runTo (webpack-internal:///(:3000/app-pages-browser)/./node_modules/aws-sdk/lib/state_machine.js:14:12)
at Request.runTo (webpack-internal:///(:3000/app-pages-browser)/./node_modules/aws-sdk/lib/request.js:407:15)
at Request.send (webpack-internal:///(:3000/app-pages-browser)/./node_modules/aws-sdk/lib/request.js:371:10)
at features.constructor.makeRequest (webpack-internal:///(:3000/app-pages-browser)/./node_modules/aws-sdk/lib/service.js:225:27)
at svc.
facing the same error trying to solve it but after spending more than 8 hours on debugging still got no answer ... does any one have solution to this...????
here it is..... CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1 at credError (webpack-internal:///(:3000/app-pages-browser)/./node_modules/aws-sdk/lib/config.js:400:40) at Config.getCredentials (webpack-internal:///(:3000/app-pages-browser)/./node_modules/aws-sdk/lib/config.js:441:14) at Request.VALIDATE_CREDENTIALS (webpack-internal:///(:3000/app-pages-browser)/./node_modules/aws-sdk/lib/event_listeners.js:112:28) at Request.callListeners (webpack-internal:///(:3000/app-pages-browser)/./node_modules/aws-sdk/lib/sequential_executor.js:102:18) at Request.emit (webpack-internal:///(:3000/app-pages-browser)/./node_modules/aws-sdk/lib/sequential_executor.js:78:10) at Request.emit (webpack-internal:///(:3000/app-pages-browser)/./node_modules/aws-sdk/lib/request.js:687:14) at Request.transition (webpack-internal:///(:3000/app-pages-browser)/./node_modules/aws-sdk/lib/request.js:23:10) at AcceptorStateMachine.runTo (webpack-internal:///(:3000/app-pages-browser)/./node_modules/aws-sdk/lib/state_machine.js:14:12) at Request.runTo (webpack-internal:///(:3000/app-pages-browser)/./node_modules/aws-sdk/lib/request.js:407:15) at Request.send (webpack-internal:///(:3000/app-pages-browser)/./node_modules/aws-sdk/lib/request.js:371:10) at features.constructor.makeRequest (webpack-internal:///(:3000/app-pages-browser)/./node_modules/aws-sdk/lib/service.js:225:27) at svc. [as putObject] (webpack-internal:///(:3000/app-pages-browser)/./node_modules/aws-sdk/lib/service.js:707:23) at uploadToS3 (webpack-internal:///(:3000/app-pages-browser)/./src/lib/s3.ts:29:27) at onDrop (webpack-internal:///(:3000/app-pages-browser)/./src/components/FileUpload.tsx:31:87) at eval (webpack-internal:///(:3000/app-pages-browser)/./node_modules/react-dropzone/dist/es/index.js:719:7) at eval (webpack-internal:///(:3000/app-pages-browser)/./node_modules/react-dropzone/dist/es/index.js:770:9)
facing the same error trying to solve it but after spending more than 8 hours on debugging still got no answer ... does any one have solution to this...????
@haris-dev-72 Here is the Answer by @melvyn-apryl . It worked for me. Now I am using aws sdk in 3 projects. Didn't faced any issue after that. Try it https://github.com/aws/aws-sdk-js/issues/3665#issuecomment-1272257650
Ensuring the proper configuration of your .env file in your code is crucial to avoid potential issues. I addressed this concern by conducting a thorough verification of my environment file, validating the correct definition of keys. I employed the following format to conduct the verification:
import env from "dotenv"
env.config()
console.log("AWS_ACCESS_KEY:", process.env.AWS_ACCESS_KEY);
console.log("AWS_SECRET_KEY:", process.env.AWS_SECRET_KEY);
To execute this verification, I created a file named test-env.js in the root directory of my project and ran the command node test-env.js.
Below is the structured configuration for my AWS file:
import AWS from "aws-sdk"
import env from "dotenv"
env.config()
AWS.config.update({
region: "us-west-2",
apiVersion: "latest",
maxRetries: 3,
httpOptions: { timeout: 30000, connectTimeout: 5000 },
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY,
secretAccessKey: process.env.AWS_SECRET_KEY,
},
})
const sesInstance = new AWS.SES()
export { sesInstance }
This meticulous approach ensures that the necessary environment variables are correctly defined and accessible, mitigating potential issues related to the AWS configuration.
Fixed #3665 @Bustami @mrbeans @Groverok @alexhddev @KevinFiorentino @jaller94 @mhart
If you're using nextjs or something and you might be trying to send a SQS from the client side code, you'll see this error unless your env vars are prefixed with NEXT_PUBLIC_ (which you probably don't want for AWS secrets)