我正在尝试通过Angular应用程序建立与S3的连接。
我照此guide中的描述进行操作:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::BUCKET_NAME"
]
}
]
}
将SDK添加到浏览器脚本中
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.728.0.min.js"></script>
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);
}
});
但仍然出现错误: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
就足够了