访问未经Contigo IdentityPoolId认证的AWS S3,错误:CredentialsError:配置中缺少凭据

时间:2020-08-08 09:06:34

标签: amazon-web-services amazon-s3 aws-sdk

我正在尝试通过Angular应用程序建立与S3的连接。

我照此guide中的描述进行操作:

  1. 创建身份池
  2. 配置角色权限
{
   "Version": "2012-10-17",
   "Statement": [
      {
         "Effect": "Allow",
         "Action": [
            "s3:ListBucket"
         ],
         "Resource": [
            "arn:aws:s3:::BUCKET_NAME"
         ]
      }
   ]
}
  1. 配置CORS
  2. 定义网页

将SDK添加到浏览器脚本中

<script src="https://sdk.amazonaws.com/js/aws-sdk-2.728.0.min.js"></script>
  1. 配置SDK
const AWS = (window as any).AWS;
AWS.config.region = 'eu-west-1'; // Region
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
  IdentityPoolId: 'eu-west-1:bla-bla-bla',
});

const s3 = new AWS.S3({
  apiVersion: '2006-03-01',
  params: { Bucket: 'my-bucket' }
});

运行此命令时:

  s3.listObjects({ Delimiter: '/' }, (err, data) => {
      if (err) {
        console.log("Error", err);
      } else {
        console.log("Success", data.Buckets);
      }
    });

我在AWS控制台中看到一个连接: enter image description here

但仍然出现错误:Error CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1

message: "Invalid identity pool configuration. Check assigned IAM roles for this pool." __type: "InvalidIdentityPoolConfigurationException"

我在这里想念什么?我以为 IdentityPoolId就足够了

0 个答案:

没有答案