首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何用前置桶分割放大S3存储

如何用前置桶分割放大S3存储
EN

Stack Overflow用户
提问于 2020-08-01 09:38:59
回答 1查看 1.2K关注 0票数 1

首先,我想在我的放大项目中设置多个S3存储。

但目前不允许这样做(放大-cli显示我是Amazon S3 storage was already added to your project.)

我通过创建分区为用例找到了可能的解决方案。

在下面的链接中提到了这一点。

https://github.com/aws-amplify/amplify-cli/issues/1923#issuecomment-516508923

上面写着如下。

代码语言:javascript
运行
复制
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.

但它没有解释如何设置分区以及如何使用分区。

有人能解释一下怎么做吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-02 14:15:24

在amplify/backend/storage/s3-cloudformation-template.json文件夹中,可以为新前缀添加一个新策略,这将是s3桶中的文件夹名。

代码语言:javascript
运行
复制
        "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文件夹中。

代码语言:javascript
运行
复制
Storage.put("storageTest.png", file, {
  contentType: "image/png",
  level: 'public',
  customPrefix: {
    public: "storage1/"
  }
})
  .then(result => console.log(result))
  .catch(err => console.log(err));

};

对于另一个前缀(在本例中为存储2),您可以在另一个文件夹中存储来自另一个用例的文件。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63203788

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档