'getting Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1 despite having credentials in config file
I have a typescript/node-based application where the following line of code is throwing an error:
const res = await s3.getObject(obj).promise();
The error I'm getting in terminal output is:
❌ Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1
However, I do actually have a credentials file in my .aws directory with values for aws_access_key_id
and aws_secret_access_key
. I have also exported the values for these with the variables AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
. I have also tried this with and without running export AWS_SDK_LOAD_CONFIG=1
but to no avail (same error message). Would anyone be able to provide any possible causes/suggestions for further troubleshooting?
Solution 1:[1]
Try not setting AWS_SDK_LOAD_CONFIG
to anything (unset it). Unset all other AWS variables. In Mac/linux, you can do export | grep AWS_
to find others you might have set.
Next, do you have AWS connectivity from the command line? Install the AWS CLI v2 if you don't have it yet, and run aws sts get-caller-identity
from a terminal window. Don't bother trying to run node until you get this working. You can also try aws configure list
.
Read through all the sections of Configuring the AWS CLI, paying particular attention to how to use the credentials
and config
files at $HOME/.aws/credentials
and $HOME/.aws/config
. Are you using the default profile or a named profile?
I prefer to use named profiles, but I use more than one so that may not be needed for you. I have always found success using the AWS_PROFILE
environment variable:
export AWS_PROFILE=your_profile_name # macOS/linux
setx AWS_PROFILE your_profile_name # Windows
$Env:AWS_PROFILE="your_profile_name" # PowerShell
This works for me both with an Okta/gimme-aws-creds
scenario, as well as an Amazon SSO scenario. With the Okta scenario, just the AWS secret keys go into $HOME/.aws/credentials
, and further configuration such as default region or output format go in $HOME/.aws/config
(this separation is so that tools can completely rewrite the credentials
file without touching the config
). With the Amazon SSO scenario, all the settings go in the config
.
Solution 2:[2]
Install npm i dotenv
Add a .env
file with your AWS_ACCESS_KEY_ID
etc credentials in.
Then in your index.js
or equivalent file add require("dotenv").config();
Then update the config of your AWS instance:
region: "eu-west-2",
maxRetries: 3,
httpOptions: { timeout: 30000, connectTimeout: 5000 },
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | ErikE |
Solution 2 | highrankin |