question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

type checking error with `fromEnv` in @aws-sdk/credential-providers

See original GitHub issue

Describe the bug

While using @aws-sdk/credential-providers in a React typescript application having the following code:

import { initialize } from "@iot-app-kit/source-iotsitewise";
import { fromEnv } from "@aws-sdk/credential-providers";

const { query } = initialize({
  awsCredentials: fromEnv(),
  awsRegion: "us-east-1",
});

We encounter the following build error:

ERROR in ./src/App.tsx 16:18-25
export 'fromEnv' (imported as 'fromEnv') was not found in '@aws-sdk/credential-providers' (possible exports: fromCognitoIdentity, fromCognitoIdentityPool, fromTemporaryCredentials, fromWebToken)

Your environment

macOS

SDK version number

@aws-sdk/credential-providers@3.53.0

Is the issue in the browser/Node.js/ReactNative?

Browser

Details of the browser/Node.js/ReactNative version

Browsers:
    Chrome: 98.0.4758.109
    Firefox: 91.6.0
    Safari: 15.3

Steps to reproduce

Please share code or minimal repo, and steps to reproduce the behavior.

  • Create a new ReactJS application
npx create-react-app my-app --template typescript
  • Install minimal packages to reproduce issue
npm install @aws-sdk/credential-providers @iot-app-kit/source-iotsitewise
  • Add following code to App.tsx
import { initialize } from '@iot-app-kit/source-iotsitewise';
import { fromEnv } from '@aws-sdk/credential-providers';

const { query } = initialize({ awsCredentials: fromEnv(), awsRegion: 'us-east-1' });
  • Either run npm start or npm run build

Observed behavior

React app fails to run or build due to following type checking error

ERROR in ./src/App.tsx 16:18-25
export 'fromEnv' (imported as 'fromEnv') was not found in '@aws-sdk/credential-providers' (possible exports: fromCognitoIdentity, fromCognitoIdentityPool, fromTemporaryCredentials, fromWebToken)

Expected behavior

Although @aws-sdk/credential-providers has the following exported member, the type resolution fails. The type resolution for fromEnv should not fail.

export * from "./fromCognitoIdentity";
export * from "./fromCognitoIdentityPool";
export * from "./fromContainerMetadata";
export * from "./fromEnv";
export * from "./fromIni";
export * from "./fromInstanceMetadata";
export * from "./fromProcess";
export * from "./fromSSO";
export * from "./fromTemporaryCredentials";
export * from "./fromTokenFile";
export * from "./fromWebToken";

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
diehbriacommented, May 2, 2022

It is incorrect to say that fromEnv wouldn’t work in the browser environment, it is common for environment variables to be placed into process.env via build processes. The use case is for local development work flows - it is a huge burden to users of software to need to figure out how to set up something such as IAM to get a ‘hello world’ working.

Due to security concerns, it is highly recommended against guiding people towards hard coding strings directly into their code bases. Within Amazon, we are actually strictly forbidden from even suggesting this within our example repositories or code samples.

For this reason we need a good path forward on these local development use cases.

Additionally, for any credential-providers which are intentionally not supported in the browser, they should be:

  • documented (of which these omissions are not)
  • throw an error, with an intelligible message, rather than simply being omitted from the bundles which causes lots of confusion.
1reaction
evanottingercommented, Jul 15, 2022

I have just encountered this same issue. I don’t really understand the logic of not including fromEnv / fromProcess / fromIni in the exports for the browser version.

How do frontend developers ensure that environment variables are removed when pushing to production?

Using AWS, we can inject secrets into the environment of containerized applications at runtime. This is even the recommended practice with ECS according to the documentation. We can also make the environmental variables accessible from containers by mapping the environmental variables of an EC2 from EB to the container using docker-compose according to the EB developer’s guide. It’s not a stretch to use an entrypoint script in a container to retrieve the secrets from the environment (as described in the documentation) and place them in a credentials file which the React application can access.

I would also like to emphasize @diehbria 's comment:

If the decision is made not to include these, I think it should be considered to have the credential providers throw errors at run time which point towards the documentation and explain these aren’t supported.

My question then becomes, what is the recommendation from AWS if we’re not able to import fromEnv / fromProcess / fromIni in a containerized React application?

Read more comments on GitHub >

github_iconTop Results From Across the Web

@aws-sdk/credential-providers | AWS SDK for JavaScript v3
fromEnv returns a AwsCredentialIdentityProvider function, that reads credentials from the following environment variables: AWS_ACCESS_KEY_ID - The access key ...
Read more >
Can't export fromIni from @aws-sdk/credential-providers
I get the same error trying to use fromIni() for a simple CreateInvalidationCommand using the CloudFrontClient. Trying to configure the client ...
Read more >
aws-sdk/credential-provider-node - npm.io
Check @aws-sdk/credential-provider-node 3.186.0 package - Last release 3.186.0 with ... fromEnv , that will attempt to source AWS credentials from a Node.
Read more >
@aws-sdk/credential-provider-node | Yarn - Package Manager
JS. This module provides a factory function, fromEnv , that will attempt to source AWS credentials from a Node.JS environment. It will attempt ......
Read more >
Configuring the AWS SDK for Go V2
Use this method only for testing purposes. Single Sign-on Credentials. The SDK provides a credential provider for retrieving temporary AWS ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found