aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
3.05k stars 573 forks source link

S3Client initialization failes for credentials fromEnv() #5574

Closed skew202 closed 8 months ago

skew202 commented 9 months ago

Checkboxes for prior research

Describe the bug

When creating an S3Client with the aws-sdk the initialisation failes for UA_APP_ID_ENV_NAME in @smithy/node-config-provider

Expected Behavior

A successfully initialized S3Client using the variables available in the process.env

SDK version number

3.470.0

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v18.17.0

Reproduction Steps

.env

AWS_ACCESS_KEY_ID=ABC1234567890
AWS_SECRET_ACCESS_KEY=Abcd1234567890
AWS_REGION=eu-central-1

.index.js

import { S3Client } from "@aws-sdk/client-s3";
import { fromEnv } from "@aws-sdk/credential-providers";

const s3Client = new S3Client({
    credentials: fromEnv()
});

Observed Behavior

Exception has occurred: CredentialsProviderError: Cannot load config from environment variables with getter: (env) => env[exports.UA_APP_ID_ENV_NAME]
  at /node_modules/@smithy/node-config-provider/dist-cjs/fromEnv.js:14:15
    at /node_modules/@smithy/property-provider/dist-cjs/chain.js:12:39
    at coalesceProvider (/node_modules/@smithy/property-provider/dist-cjs/memoize.js:11:23)
    at /node_modules/@smithy/property-provider/dist-cjs/memoize.js:26:34
    at defaultUserAgent (/node_modules/@aws-sdk/util-user-agent-node/dist-cjs/index.js:34:7)
    at getRuntimeConfig (/node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.js:39:57)
    at new S3Client (/node_modules/@aws-sdk/client-s3/dist-cjs/S3Client.js:24:64)

Expected Behavior

A successfully initialized S3Client using the variables available in the process.env

Possible Solution

No response

Additional Information/Context

No response

aBurmeseDev commented 8 months ago

Hi @skew202 - thanks for reaching out and apologies for not responding it sooner.

I was able to reproduce it and found out that you'd need to import SignatureV4 and use fromEnv method to provide credentials as shown below. The reason behind, I think, is because JS v3 is opt-in for the use of Sigv4 due to a large optional dependency on the aws-crt node bindings package. It doesn't automatically include nor dynamically import this package due to its size negatively affecting customer who don't need it.

import { S3Client, ListBucketsCommand } from "@aws-sdk/client-s3";
import { SignatureV4 } from "@smithy/signature-v4";
import { fromEnv } from "@aws-sdk/credential-providers";

const signatureV4 = new SignatureV4({
    credentials: fromEnv()
})
const s3Client = new S3Client({
    region: process.env.AWS_REGION
});

const listBuckets = new ListBucketsCommand({});
const response = await s3Client.send(listBuckets)

Hope that makes sense and if you have any further questions, please let me know! Best, John

github-actions[bot] commented 8 months ago

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[bot] commented 7 months ago

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.