【问题标题】:How to have AWS Amplify ignore my developer account credentials from AWS CLI如何让 AWS Amplify 忽略来自 AWS CLI 的开发人员账户凭证
【发布时间】:2020-04-20 15:08:46
【问题描述】:

我正在使用 React 和 Amplify 开发 SPA,并尝试围绕各种身份验证状态编写测试。我使用 Cognito 作为我的身份验证提供者。

我对用户退出但尝试访问 s3 资源的条件的测试失败,因为 Auth.currentCredentials() 正在返回我的开发人员用户 IAM 凭证,该凭证是通过 AWS CLI (aws configure) 在我的机器上配置的用于运行测试。

  await Auth.signOut();
  Auth.currentCredentials()
    .then(credentials => {
      const s3 = new S3({
        credentials: Auth.essentialCredentials(credentials),
        signatureVersion: 'v4',
        region: 'us-east-1'
      });
      s3.getSignedUrl(
        'getObject',
        {
          Bucket: 'myBucket',
          Key:'myKey'
        },
        (err, data) => {
          if (err) {
            console.log(err);
          } else {
            console.log('got data: ', data);
            //a presigned URL is returned which successfully accesses content
          }
        }
      );
    })
    .catch(err => {
      console.log(err);
      //where I expect code to reach
    });

如何将我的开发者凭据与 Amplify 隔离开来,强制它仅查看来自 Cognito 的基于会话的临时凭据?如果重要的话,我正在使用 Windows 10 进行开发。

【问题讨论】:

    标签: reactjs amazon-web-services aws-amplify


    【解决方案1】:

    从 AWS CLI 中删除默认配置文件,具体取决于 (UserHomeDirectory) / 之类的操作系统。 Aws/凭证文件..

    您可以只更新文件以将默认更改为另一个名称。然后当您希望它设置配置文件时..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-19
      • 1970-01-01
      • 1970-01-01
      • 2020-11-08
      • 2022-08-10
      相关资源
      最近更新 更多