我正在编写一个CloudFormation,它创建一个S3存储桶和一个SQS队列。在同一个CFN中,我试图允许S3存储桶将消息发送到SQS队列。我不断收到此错误:
无法验证以下目标配置
昨天我花了大约12个小时进行反复试验。我想我现在已经阅读了有关该主题的每篇文章。大多数似乎都在Lambda或SNS主题上,但是过程应该相同。我试过在S3存储桶中添加DependsOn,以便在存储桶之前创建SQS策略,但这没有用。然后,我提出了另一个建议的解决方案,即创建存储桶和sqs,然后为sqs存储桶创建策略,该策略允许s3向其发布,最后创建通知。我成功创建了通知。
这是我的sqs创作:
SQSBiaData:
Type: AWS::SQS::Queue
Properties:
QueueName: !Ref Queue
Tags:
- Key: 'Environment'
Value: !Ref Environment
这是我的sqs政策:
SQSBiaPolicy:
Type: AWS::SQS::QueuePolicy
Properties:
Queues:
- !Ref SQSBiaData
PolicyDocument:
Statement:
- Sid: SendMessage
Effect: Allow
Principal:
AWS: !Ref AccountNumber
Action: SQS:SendMessage
Resource:
- 'arn:aws:sqs:us-east-1:123456:bia-data'
Condition:
ArnLike:
aws:SourceArn:
Fn::Join:
- ''
- - 'arn:aws:s3:*:*:'
- 'bia-data'
这是我创建的存储桶:
S3BucketBiaData:
Type: AWS::S3::Bucket
DependsOn:
- SQSBiaPolicy
DeletionPolicy: Retain
Properties:
AccessControl: Private
BucketName: !Ref BucketName
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
Tags:
- Key: 'Environment'
Value: !Ref Environment
NotificationConfiguration:
QueueConfigurations:
- Event: 's3:ObjectCreated:*'
Queue: 'arn:aws:sqs:us-east-1:123456:bia-data'
Filter:
S3Key:
Rules:
- Name: 'prefix'
Value: 'manifest/'
最后,这是我的存储桶策略:
S3BucketBiaPolicies:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref BucketName
PolicyDocument:
Statement:
- Sid: DenyInsecureConnections
Effect: Deny
Principal: '*'
Action: s3:*
Resource:
- !Sub 'arn:aws:s3:::${S3BucketBiaData}/*'
Condition:
Bool:
aws:SecureTransport: 'false'
- Sid: DenyPublicReadGrant
Effect: Deny
Principal:
AWS: "*"
Action:
- s3:PutObject
- s3:PutObjectAcl
Resource:
- !Sub 'arn:aws:s3:::${S3BucketBiaData}/*'
Condition:
StringLike:
s3:x-amz-grant-read:
- "*http://acs.amazonaws.com/groups/global/AllUsers*"
- "*http://acs.amazonaws.com/groups/global/AuthenticatedUsers*"
- Sid: OnlyAllowVPCAccess
Effect: Deny
Principal: '*'
Action: s3:*
Resource:
- !Sub 'arn:aws:s3:::${S3BucketBiaData}/*'
Condition:
ForAnyValue:StringNotEquals:
'aws: sourceVpce': !Ref VPCs
我希望CFN可以按以下顺序进行:
谁能告诉我我做错了什么?请记住,直到我添加NotificationConfiguration部分,CFN才能正常工作。
谢谢!
答案 0 :(得分:0)
虽然我不知道您所遇到问题的确切问题,但我还是建议您大量使用伪参数,以简化调试工作。
我将用${AWS::Region}
替换“ us-east-1”,并用${AWS::AccountId}
替换“ 123456”。
在S3定义中引用Queue时,我也会使用!GetAtt。代替Queue: 'arn:aws:sqs:us-east-1:123456:bia-data'
Queue: !GetAtt SQSBiaData.Arn
最后,我将在您的SQS政策的最后一行中使用参数“ BucketName”作为参考。
这些更改可能会使此处的某人调试起来更容易。