Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3Client Instantiation not finding ENV variables #6211

Closed
3 tasks done
ChaoChow opened this issue Jun 22, 2024 · 2 comments
Closed
3 tasks done

S3Client Instantiation not finding ENV variables #6211

ChaoChow opened this issue Jun 22, 2024 · 2 comments
Assignees
Labels
bug This issue is a bug. closed-for-staleness p3 This is a minor priority issue response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days.

Comments

@ChaoChow
Copy link

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

  1. Save the GetObject example js code from https://docs.aws.amazon.com/AmazonS3/latest/userguide/example_s3_GetObject_section.html locally
  2. Change the bucket to your own bucket your AWS account
  3. Set AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN as environment variables in terminal from your AWS login
  4. in the same terminal window run the example js code script using node
  5. See exception for invalid credentials
  6. Edit the example js code line 3 to the following: const client = new S3Client({credentials: fromEnv()}); you will need to npm 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

@ChaoChow ChaoChow added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 22, 2024
@aBurmeseDev
Copy link
Member

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

@aBurmeseDev aBurmeseDev self-assigned this Jun 25, 2024
@aBurmeseDev aBurmeseDev added response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. p3 This is a minor priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Jun 25, 2024
Copy link

github-actions bot commented Jul 6, 2024

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.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Jul 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. closed-for-staleness p3 This is a minor priority issue response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants