type checking error with `fromEnv` in @aws-sdk/credential-providers
See original GitHub issueDescribe 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
ornpm 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:
- Created 2 years ago
- Reactions:4
- Comments:16 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It is incorrect to say that
fromEnv
wouldn’t work in the browser environment, it is common for environment variables to be placed intoprocess.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:
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.
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:
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?