简体   繁体   中英

give public read and view access to s3 bucket objects using cloudformation template

I am writing a AWS cloudformation template to receive a file inside a s3 bucket from Kinesis Firehose. I have gave public read access to the bucket (bucket is public) but when i access the file inside the bucket using object URL, i get "The XML file does not appear to have any style associated with it" error and it says access denied. However the object (JSON file) is downloadable.

I have given full access to the s3 bucket

Resources:

# Create s3 bucket
MyS3Bucket:
 Type: AWS::S3::Bucket
 Properties:
    BucketName: health-app-buckett
    AccessControl: PublicRead

# Create Role
S3BucketRole:
 Type: 'AWS::IAM::Role'
 Properties:
  AssumeRolePolicyDocument:
    Statement:
      - Effect: Allow
        Principal:
          Service:
            - s3.amazonaws.com
        Action:
          - 'sts:AssumeRole'

#Create policy for bucket
S3BucketPolicies:
 Type: 'AWS::IAM::Policy'
 Properties:
  PolicyName: S3BucketPolicy
  PolicyDocument:
    Statement:
      - Sid: PublicReadForGetBucketObjects
        Effect: Allow
        Action: 's3:GetObject'
        Resource: !Join
          - ''
          - - 'arn:aws:s3:::'
            - !Ref MyS3Bucket
            - /*
  Roles:
    - !Ref S3BucketRole

I want to be able to view the file using Object URL

You need to add PublicAccessBlockConfiguration to your template

MyS3Bucket:
 Type: AWS::S3::Bucket
 Properties:
    BucketName: health-app-buckett
    AccessControl: PublicRead
    PublicAccessBlockConfiguration:
            BlockPublicAcls : false
            BlockPublicPolicy : false
            IgnorePublicAcls : false
            RestrictPublicBuckets : false

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM