授予 AWS Config 访问 Amazon S3 存储桶的权限

时间:2021-06-13 14:58:40

标签: amazon-web-services amazon-s3 aws-policies

我想创建对 Amazon S3 存储桶的 AWS Config 访问权限,下面提供了我根据链接 https://docs.aws.amazon.com/config/latest/developerguide/s3-bucket-policy.html 编写的策略:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AWSConfigBucketPermissionsCheck",
      "Effect": "Allow",
      "Principal": {
        "Service": [
         "config.amazonaws.com"
        ]
      },
      "Action": "s3:GetBucketAcl",
      "Resource": "arn:aws:s3:::targetBucketName"
    },
    {
      "Sid": "AWSConfigBucketExistenceCheck",
      "Effect": "Allow",
      "Principal": {
        "Service": [
          "config.amazonaws.com"
        ]
      },
      "Action": "s3:ListBucket",
      "Resource": "arn:aws:s3:::targetBucketName"
    },
    {
      "Sid": "AWSConfigBucketDelivery",
      "Effect": "Allow",
      "Principal": {
        "Service": [
         "config.amazonaws.com"    
        ]
      },
      "Action": "s3:PutObject",
      "Resource": "arn:aws:s3:::targetBucketName/[optional] prefix/AWSLogs/sourceAccountID-WithoutHyphens/Config/*",
      "Condition": { 
        "StringEquals": { 
          "s3:x-amz-acl": "bucket-owner-full-control"
        }
      }
    }
  ]
}   

我想了解以下提供的部分:

"Resource": "arn:aws:s3:::targetBucketName/[optional] prefix/AWSLogs/sourceAccountID-WithoutHyphens/Config/*",

prefix 的含义是什么?如何填写政策的 prefix/AWSLogs/sourceAccountID-WithoutHyphens/Config/* 部分?

谢谢。

1 个答案:

答案 0 :(得分:1)

前缀是您在配置到 S3 的日志记录时定义的内容。这是可选的。 Config 使用标准路径/密钥格式将日志写入 S3 存储桶,该格式为“prefix/AWSLogs/sourceAccountID-WithoutHyphens/Config/*”。

如果您从控制台配置到 S3 的配置日志记录,您将不必担心存储桶策略,因为它将自动创建。您只需提供存储桶名称和可选前缀。