【问题标题】:Make specific S3 bucket folder public with amplify overrideMake specific S3 bucket folder public with amplify override
【发布时间】:2022-12-19 03:03:55
【问题描述】:

make specific s3 folders publicly accessible. For example make public/ accessible to all. protected/ to be private.

【问题讨论】:

    标签: amazon-s3 amazon-cloudformation aws-amplify


    【解决方案1】:
    1. Do amplify override storage
    2. The command creates a new overrides.ts file under amplify/backend/storage/<resource-name>/
    3. Add a bucket policy as below in override.ts
      import {AmplifyS3ResourceTemplate} from '@aws-amplify/cli-extensibility-helper'
      
      export function override(resources: AmplifyS3ResourceTemplate) {
        resources.addCfnResource(
          {
            type: 'AWS::S3::BucketPolicy',
            properties: {
              Bucket: {
                Ref: 'S3Bucket',
              },
              PolicyDocument: {
                Statement: [
                  {
                    Action: ['s3:GetObject'],
                    Effect: 'Allow',
                    Resource: [
                      {
                        'Fn::Sub': 'arn:aws:s3:::${S3Bucket}/public/*',
                      },
                    ],
                    Principal: {
                      AWS: ['*'],
                    },
                  },
                ],
              },
            },
          },
          'MyS3BucketPolicy'
        )
      }
      
      

    【讨论】:

      猜你喜欢
      • 2015-08-19
      • 2018-07-28
      • 1970-01-01
      • 2020-04-27
      • 2021-05-14
      • 2012-12-07
      • 2013-09-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多