我正在开发一个React/Node.js应用程序,并试图从~/..aws/凭据文件中读取我的IAM用户凭据。我正在尝试使用@aws/凭证提供者节点包中的fromIni。根据AWS v3文档,我可以做以下工作:
import { fromIni } from "@aws-sdk/credential-providers"; // ES6 import
// const { fromIni } = require("@aws-sdk/credential-providers"); // CommonJS import
const client = new FooClient({
credentials: fromIni({
// Optional. The configuration profile to use. If not specified, the provider will use the value
// in the `AWS_PROFILE` environment variable or a default of `default`.
profile: "profile",
// Optional. The path to the shared credentials file. If not specified, the provider will use
// the value in the `AWS_SHARED_CREDENTIALS_FILE` environment variable or a default of
// `~/.aws/credentials`.
filepath: "~/.aws/credentials",
// Optional. The path to the shared config file. If not specified, the provider will use the
// value in the `AWS_CONFIG_FILE` environment variable or a default of `~/.aws/config`.
configFilepath: "~/.aws/config",
// Optional. A function that returns a a promise fulfilled with an MFA token code for the
// provided MFA Serial code. If a profile requires an MFA code and `mfaCodeProvider` is not a
// valid function, the credential provider promise will be rejected.
mfaCodeProvider: async (mfaSerial) => {
return "token";
},
// Optional. Custom STS client configurations overriding the default ones.
clientConfig: { region },
}),
});但是,当我在我的index.js文件中尝试这个时:
import { fromIni } from '@aws-sdk/credential-providers';
const createLink = {
url: config.aws_appsync_graphqlEndpoint,
region: config.aws_appsync_region,
auth: {
type: config.aws_appsync_authenticationType,
credentials: fromIni()
}
};然后运行npm start,得到以下错误:
export 'fromIni' (imported as 'fromIni') was not found in '@aws-sdk/credential-providers' (possible exports: fromCognitoIdentity, fromCognitoIdentityPool, fromTemporaryCredentials, fromWebToken)我想要的函数似乎不是从包中导出的,但是文档中却不这么说。
编辑:输出到@aws-sdk/credential-providers @aws-sdk/credential-provider-ini
port-dashboard@0.1.0 C:\Users\kshang\Documents\pov-ui
├─┬ @aws-sdk/client-cognito-identity-provider@3.79.0
│ ├─┬ @aws-sdk/client-sts@3.79.0
│ │ └─┬ @aws-sdk/credential-provider-node@3.79.0
│ │ └── @aws-sdk/credential-provider-ini@3.79.0
│ └─┬ @aws-sdk/credential-provider-node@3.79.0
│ └── @aws-sdk/credential-provider-ini@3.79.0
├─┬ @aws-sdk/credential-providers@3.79.0
│ ├─┬ @aws-sdk/client-cognito-identity@3.79.0
│ │ └─┬ @aws-sdk/credential-provider-node@3.79.0
│ │ └── @aws-sdk/credential-provider-ini@3.79.0 deduped
│ └── @aws-sdk/credential-provider-ini@3.79.0
└─┬ aws-amplify@4.3.20
├─┬ @aws-amplify/analytics@5.2.5
│ └─┬ @aws-sdk/client-firehose@3.6.1
│ └─┬ @aws-sdk/credential-provider-node@3.6.1
│ ├── @aws-sdk/credential-provider-ini@3.6.1
│ └─┬ @aws-sdk/credential-provider-process@3.6.1
│ └── @aws-sdk/credential-provider-ini@3.6.1 deduped
└─┬ @aws-amplify/geo@1.3.1
└─┬ @aws-sdk/client-location@3.48.0
└─┬ @aws-sdk/credential-provider-node@3.48.0
└── @aws-sdk/credential-provider-ini@3.48.0发布于 2022-05-06 20:07:33
更新:在做了更多的研究并与一些AWS专家交谈后,我们发现我们需要使用Amazon来获得基于浏览器的应用程序的凭据。
在使用fromIni()对简单的CreateInvalidationCommand使用CloudFrontClient时,我也会遇到同样的错误。
尝试在没有credentials键的情况下配置客户端会导致Error: Credential is missing
我当前在本地开发的解决方法是使用.env.local文件,并使用accessKeyId和secretAccessKey属性来配置:
const cloudfront = new CloudFrontClient({
credentials: {
accessKeyId: process.env.REACT_APP_AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.REACT_APP_SECRET_ACCESS_KEY,
},
region: "us-east-1",
});这显然并不理想,但它在本地用于测试和开发。
我还想指出,出口产品中也缺少fromEnv()。这会在EC2实例中引发此解决方案的问题。
不管是哪种方式,都希望能在不久的更新中看到这个问题得到解决。
cache-invalidator@0.1.0 /Users/miguelmaldonado/Desktop/projects/prototypes/cache-invalidator
├─┬ @aws-sdk/client-cloudfront@3.85.0
│ └─┬ @aws-sdk/credential-provider-node@3.85.0
│ └── @aws-sdk/credential-provider-ini@3.85.0 deduped
└─┬ @aws-sdk/credential-providers@3.85.0
└── @aws-sdk/credential-provider-ini@3.85.0https://stackoverflow.com/questions/72088326
复制相似问题