存储桶列表访问权限_如何使用公共读取访问权限创建存储桶?

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 to declare my bucket. Its a bit of copy and paste from one of the serverless-stack examples.

Resources:

AttachmentsBucket:

Type: AWS::S3::Bucket

Properties:

AccessControl: PublicRead

# Set the CORS policy

BucketName: range-picker-bucket-${self:custom.stage}

CorsConfiguration:

CorsRules:

-

AllowedOrigins:

- '*'

AllowedHeaders:

- '*'

AllowedMethods:

- GET

- PUT

- POST

- DELETE

- HEAD

MaxAge: 3000

# Print out the name of the bucket that is created

Outputs:

AttachmentsBucketName:

Value:

Ref: AttachmentsBucket

Now when i try to use a url for a file, it returns access denied. I manually have to set the public read permission for every file by hand in the aws-s3 web interface.

What am i doing wrong?

解决方案

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: "*"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值