Closed ChaoChow closed 2 months ago
Hi @ChaoChow - thanks for reaching out.
I followed your repro steps and was able to successfully make the API call reading credentials from environment variables. It's strange that you can use credential-providers to read your variables but Can you please verify the variables are being exported and loaded correctly? Sometimes you may need to restart the IDE since if the variables were set after you launched your IDE, they will not be propagated to that process until a restart happens. You can also validate if the variables are being loaded by node process by doing the following before instancing the client:
const varsSet = process.env.AWS_SECRET_ACCESS_KEY && process.env.AWS_ACCESS_KEY_ID;
console.log(varsSet ? "Variables are set" : "Variables are not set!");
As you've already mentioned, you can also use one of our @aws-sdk/credential-providers
methods fromEnv
to read the credentials from your environment variables.
Let me know if that helps or there's any further questions! Best, John
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.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.
Checkboxes for prior research
Describe the bug
When instantiating the S3Client object on a Nodejs project with an empty configuration object, the S3Client fails to pull AWS credentials stored as env variables despite the documentation stating that the credential provider chain searches in multiple locations for credentials.
I found that instantiating the S3Client object bare like the below line does not fetch credentials properly
const client = new S3Client({});
However, instantiating the S3Client object with the fromEnv() function does result in credentials being fetched properly from env variables.
const client = new S3Client({credentials: fromEnv()});
SDK version number
@aws-sdk/client-s3@3.588.0
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
v20.11.1
Reproduction Steps
const client = new S3Client({credentials: fromEnv()});
you will need tonpm install @aws-sdk/credential-provider-env
and import fromEnv iin order to resolve fromEnv()Observed Behavior
Running the script results in an invalid credentials error
Expected Behavior
Running the script fetches the specified file
Possible Solution
credential provider chain not searching for env variables first OR is unable to fetch env variables
Additional Information/Context
Running on ARM Mac OS