首先,我想在我的放大项目中设置多个S3存储。
但目前不允许这样做(放大-cli显示我是Amazon S3 storage was already added to your project.
)
我通过创建分区为用例找到了可能的解决方案。
在下面的链接中提到了这一点。
https://github.com/aws-amplify/amplify-cli/issues/1923#issuecomment-516508923
上面写着如下。
As a best practice, the Amplify Framwork allows you to have multiple prefixes in the bucket as a best practice instead of having multiple buckets.
You could partition your bucket by prefixes like the following:
`mybucket/partition1` and `mybucket/partition2` which can potentially have different auth policies and lambda triggers.
但它没有解释如何设置分区以及如何使用分区。
有人能解释一下怎么做吗?
发布于 2020-08-02 14:15:24
在amplify/backend/storage/s3-cloudformation-template.json文件夹中,可以为新前缀添加一个新策略,这将是s3桶中的文件夹名。
"S3AuthStorage1Policy": {
"DependsOn": [
"S3Bucket"
],
"Condition": "CreateAuthStorage1",
"Type": "AWS::IAM::Policy",
"Properties": {
"PolicyName": {
"Ref": "s3Storage1Policy"
},
"Roles": [
{
"Ref": "authRoleName"
}
],
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": {
"Fn::Split" : [ "," , {
"Ref": "s3PermissionsAuthenticatedStorage1"
} ]
},
"Resource": [
{
"Fn::Join": [
"",
[
"arn:aws:s3:::",
{
"Ref": "S3Bucket"
},
"/storage1/*"
]
]
}
]
}
]
}
}
},
https://docs.amplify.aws/lib/storage/getting-started/q/platform/js#using-amazon-s3 https://github.com/aws-amplify/amplify-js/issues/332#issuecomment-602606514
现在您可以使用自定义前缀" storage1“将文件存储在storage1文件夹中。
Storage.put("storageTest.png", file, {
contentType: "image/png",
level: 'public',
customPrefix: {
public: "storage1/"
}
})
.then(result => console.log(result))
.catch(err => console.log(err));
};
对于另一个前缀(在本例中为存储2),您可以在另一个文件夹中存储来自另一个用例的文件。
https://stackoverflow.com/questions/63203788
复制相似问题