aws getCredentials nodejs 的问题

issue with aws getCredentials nodejs

提问人:satyendra 提问时间:10/31/2023 更新时间:10/31/2023 访问量:24

问:

我正在尝试使用 getCredentials() 创建会话令牌来访问 s3 对象。

我尝试切换到的配置文件需要 MFA 身份验证,我收到错误 - InvalidClientTokenId:请求中包含的安全令牌无效。 输入 MFA 令牌后

这是代码片段...知道我做错了什么

import  { S3Client, ListBucketsCommand, ListObjectsV2Command } from '@aws-sdk/client-s3';
import { fromIni } from "@aws-sdk/credential-providers";
import * as readline from 'readline';

const bucketName = 'my-bucket-name';
const fq3Profile = 'my-profile-name'; // this profile is setup correctly in .aws/config..verified by console access
const awsRegion = 'my-region';

function prompt(query) {
    const rl = readline.createInterface({input: process.stdin, output: process.stdout});
  
    return new Promise((resolve) =>
      rl.question(query, (ans) => {
        rl.close();
        // console.log(`++++mfa token  - ${ans}`)
        resolve(ans);
      })
    );
}

const   getCredentials = async () =>  {
    return fromIni({
      profile: fq3Profile,
      mfaCodeProvider: async (serial) => prompt(
          `Enter mfa token for the account: ${serial}\n`
      ),
    });
  }

const s3client = new S3Client({ 
    region: awsRegion,
    credentials: await getCredentials()
});
节点.js 亚马逊网络服务 多因素身份验证

评论


答: 暂无答案