通过cloudFormation模板启用日志记录S3?

c0d*_*0de 7 amazon-s3 amazon-web-services aws-cloudformation amazon-iam

我正在尝试使用2种不同的策略创建2个桶.

一个桶VendorsWGLogs将成为日志输出的目标.

另一个存储桶VendorsWG将为指定的IAM组提供GetObject,PutObject和DeleteObject访问权限.

这是我到目前为止:

"Resources": {
    "VendorsWGLogs": {
      "Type": "AWS::S3::Bucket",
      "Properties": {},
    },
    "LogsBucketPolicy": {
      "Type": "AWS::S3::BucketPolicy",
      "Properties": {
        "Bucket": {
          "Ref": "VendorsWGLogs"
        },
        "PolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Sid": "WeatherGuidance LogBucket permissions",
              "Effect": "Allow",
              "Principal": {
                "AWS" : "arn:aws:s3:::VendorsWG"
              },
              "Action": [
                "s3:GetObject",
                "s3:PutObject",
                "s3:PutObjectAcl"
              ],
              "Resource" : { "Fn::Join" : [
                  "", [ "arn:aws:s3:::", { "Ref" : "VendorsWGLogs" } , "/*" ]
               ]}
            }
          ]
        }
      }
    },
    "VendorsWG": {
      "Type": "AWS::S3::Bucket",
      "Properties": {
        "LoggingConfiguration": {
          "DestinationBucketName": {"Ref" : "VendorsWGLogs"},
          "LogFilePrefix": "testing-logs"
        }
      },
      "Metadata": {
        "AWS::CloudFormation::Designer": {
          "id": "a1169860-d743-406e-a3e5-e12831826439"
        },
      }
    },
    "S3BP4TNQZ": {
      "Type": "AWS::S3::BucketPolicy",
      "Properties": {
        "Bucket": {
          "Ref": "VendorsWG"
        },
        "PolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Sid": "WeatherGuidance Object permissions",
              "Effect": "Allow",
              "Principal": {
                "AWS" : "arn:aws:iam::someUserGroup"
              },
              "Action": [
                "s3:GetObject",
                "s3:PutObject",
                "s3:DeleteObject"
              ],
              "Resource" : { "Fn::Join" : [
                  "", [ "arn:aws:s3:::", { "Ref" : "VendorsWG" } , "/*" ]
               ]}
            },
            {
              "Sid": "WeatherGuidance ListBucket",
              "Effect": "Allow",
              "Principal": {
                "AWS" : "arn:aws:iam::someUserGroup"
              },
              "Action": "s3:ListBucket",
              "Resource" : { "Fn::Join" : [
                  "", [ "arn:aws:s3:::", { "Ref" : "VendorsWG" } ]
               ]},
              "Condition": {
                "StringLike": {
                  "s3:prefix": "weatherguidance*"
                }
              }
            }
          ]
        }
      }
    }
  }
Run Code Online (Sandbox Code Playgroud)

当我尝试创建堆栈时,我收到此错误在此输入图像描述

事件日志输出:

类型:

AWS::S3::Bucket
Run Code Online (Sandbox Code Playgroud)

逻辑ID:

VendorsWG   
Run Code Online (Sandbox Code Playgroud)

身份原因:

You must give the log-delivery group WRITE and READ_ACP permissions to the target bucket
Run Code Online (Sandbox Code Playgroud)

我认为将目标桶的策略主体指定为VendorsWGLogs可以解决这个问题,现在我已经没有想法了.

我究竟做错了什么?如何启用日志记录?谢谢

c0d*_*0de 12

需要将它放在日志桶的属性下

Properties: {
      AccessControl: "LogDeliveryWrite"
}
Run Code Online (Sandbox Code Playgroud)