How to create a bucket with Public Read Access?

后端 未结 2 1061
逝去的感伤
逝去的感伤 2021-01-13 04:05

I´d like to enable Public Read-Access on all items in my Bucket that are in the \"public\" folder in the serverless.yml file.

Currently this is definition code i use

2条回答
  •  粉色の甜心
    2021-01-13 04:31

    Instead of using CorsConfiguration on the bucket, you need to attach a bucket policy to it. Try the following:

    Resources:
      AttachmentsBucket:
        Type: AWS::S3::Bucket
        Properties:
          BucketName: range-picker-bucket-${self:custom.stage}
    
      AttachmentsBucketAllowPublicReadPolicy:
        Type: AWS::S3::BucketPolicy
        Properties:
          Bucket: !Ref AttachmentsBucket
          PolicyDocument:
            Version: "2012-10-17"
            Statement: 
              - Effect: Allow
                Action: 
                  - "s3:GetObject"
                Resource: 
                  - !Join ['/', [!Ref AttachmentsBucket, 'public']]
                Principal: "*"
    
    

提交回复
热议问题