Creating an S3 bucket policy that allows access to Cloudfront but restricts access to anyone else

后端 未结 2 1683
太阳男子
太阳男子 2021-02-01 18:29

I have the following policy:

{
        \"Version\": \"2008-10-17\",
        \"Id\": \"PolicyForCloudFrontPrivateContent\",
        \"Statement\": [
                  


        
2条回答
  •  半阙折子戏
    2021-02-01 18:51

    This is what you're looking for. Replace XXXXXXXXXXXXXX with you origin access id

    {
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AddPerm",
            "Effect": "Deny",
            "NotPrincipal": {
                "AWS": "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity XXXXXXXXXXXXXX"
            },
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::your.bucket.com/*"
        },
        {
            "Sid": "2",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity XXXXXXXXXXXXXX"
            },
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::your.bucket.com/*"
        }
    ]
    }
    

提交回复
热议问题