提前致谢!
我整个周末都被困在这个...我试图在cloudformation中创建一个cloudtrail服务,但在运行时收到此错误 - 检测到存储桶的S3存储桶策略不正确:s3bucket-xxxxxx
这是我的代码;
"s3bucket-xxxxxx": {
"Type": "AWS::S3::Bucket",
"Properties": {
"AccessControl": "Private",
"VersioningConfiguration": {
"Status": "Suspended"
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "XXXX"
}
}
},
"s3policytraillogs": {
"Type": "AWS::S3::BucketPolicy",
"Properties": {
"Bucket": {
"Ref": "s3bucket-xxxxxx"
},
"PolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AWSCloudTrailAclCheck20150319",
"Effect": "Allow",
"Principal": {
"Service": "cloudtrail.amazonaws.com"
},
"Action": "s3:GetBucketAcl",
"Resource": "arn:aws:s3:::s3bucket-xxxxxx"
},
{
"Sid": "AWSCloudTrailWrite20150319",
"Effect": "Allow",
"Principal": {
"Service": "cloudtrail.amazonaws.com"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::s3bucket-xxxxxx/AWSLogs/XXXXXXXX/*",
"Condition": {
"StringEquals": {
"s3:x-amz-acl": "bucket-owner-full-control"
}
}
}
]
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "XXXX"
}
}
},
"trailtraillogs": {
"Type": "AWS::CloudTrail::Trail",
"Properties": {
"IncludeGlobalServiceEvents": true,
"IsLogging": "true",
"S3BucketName": {
"Ref": "s3bucket-xxxxxx"
}
},
"Metadata": {
"AWS::CloudFormation::Designer": {
"id": "XXXX"
}
}
}
答案 0 :(得分:2)
要解决此问题,需要使用引用
将资源连接到存储桶 "Resource": [{
"Fn::Join": [ "", [
"arn:aws:s3:::", {
"Ref": "s3traillogs"
}, "/AWSLogs/XXXXXXXXXXX/*"
]
]
}],
答案 1 :(得分:0)
根据资源定义,YAML可能如下:
EventBucketStorage:
Type: "AWS::S3::Bucket"
Properties:
#AccessControl: PublicRead
MetricsConfigurations:
- Id: EventBucketStorageMetrics
BucketName: !Sub "s3-event-step-bucket-storage-s"
EventBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref EventBucketStorage
PolicyDocument:
Version: 2012-10-17
Statement:
-
Sid: "AWSCloudTrailAclCheck20150319"
Effect: Allow
Principal:
Service: cloudtrail.amazonaws.com
Action: s3:GetBucketAcl
Resource: !Join
- ""
- - "arn:aws:s3:::"
- !Ref EventBucketStorage
-
Sid: AWSCloudTrailWrite20150319
Effect: Allow
Principal:
Service: cloudtrail.amazonaws.com
Action: s3:PutObject
Resource: !Join
- ""
- - "arn:aws:s3:::"
- !Ref EventBucketStorage
- /*
Condition:
StringEquals:
s3:x-amz-acl: bucket-owner-full-control
您还可以检查链接Start the execution of State Machine based on Amazon S3 Event
答案 2 :(得分:0)
所提到的错误也可能是由于:
1)路径与存储桶之间的依赖性问题。
这可以通过参考线索中的存储桶来解决:
"DependsOn": [
"TheLogBucket"
]
2)存储桶策略配置错误。
例如,在第二条语句中:"Resource":"arn:aws:s3:::myBucketName/<prefix>/AWSLogs/<account-id>/*"
传递错误的前缀,帐户ID或忘记"*"
后缀。
3) YAML文件中的缩进错误或引号放置错误。
(*)#1和#2的问题也提到了https://www.w3schools.com/css/css_rwd_mediaqueries.asp。
(**)请确保您遵循here。