最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

amazon web services - Using the AWS javascript SDK, V3, is there a credentials provider chain equivalent? - Stack Overflow

programmeradmin1浏览0评论

I'm migrating from V2 to V3 of the javascript SDK for AWS, using NodeJS. Our application needs to check for credentials in a couple places. Previously we used the Credential Provider Chain but I cannot find the equivalent in V3. I need to look in the shared INI file (SharedIniFileCredential) when my script runs locally but the script also runs in kubernetes so (I think) I also need roleAssumerWithWebIdentity. How do I use a credential chain in V3?

I'm migrating from V2 to V3 of the javascript SDK for AWS, using NodeJS. Our application needs to check for credentials in a couple places. Previously we used the Credential Provider Chain but I cannot find the equivalent in V3. I need to look in the shared INI file (SharedIniFileCredential) when my script runs locally but the script also runs in kubernetes so (I think) I also need roleAssumerWithWebIdentity. How do I use a credential chain in V3?

Share Improve this question asked Oct 6, 2021 at 16:27 whiterook6whiterook6 3,5443 gold badges42 silver badges85 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

The module @aws-sdk/credential-provider-node provides a default credential provider similar to what you're looking for:

It will attempt to find credentials from the following sources (listed in order of precedence):

  • Environment variables exposed via process.env
  • SSO credentials from token cache
  • Web identity token credentials
  • Shared credentials and config ini files
  • The EC2/ECS Instance Metadata Service

Here's an example from their page:

const { getDefaultRoleAssumerWithWebIdentity } = require("@aws-sdk/client-sts");
const { defaultProvider } = require("@aws-sdk/credential-provider-node");
const { S3Client, GetObjectCommand } = require("@aws-sdk/client-s3");

const provider = defaultProvider({
  roleAssumerWithWebIdentity: getDefaultRoleAssumerWithWebIdentity(),
});

const client = new S3Client({ credentialDefaultProvider: provider });
发布评论

评论列表(0)

  1. 暂无评论