问题描述: 在AWS CloudFormation中配置了S3事件通知到SQS,但是通知不起作用,消息没有被发送到SQS队列。
解决方法:
确保SQS队列和S3存储桶都在同一个AWS区域中。如果它们在不同的区域中,S3事件通知将无法发送到SQS队列。
确保S3存储桶已启用事件通知。可以使用以下CloudFormation模板片段来配置S3事件通知:
Resources:
MyBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: my-bucket
NotificationConfiguration:
QueueConfigurations:
- Event: s3:ObjectCreated:*
QueueArn: !GetAtt MyQueue.Arn
MyQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: my-queue
上述示例中,我们将S3存储桶的创建事件(s3:ObjectCreated:*)配置为通知SQS队列。确保在您的CloudFormation模板中正确配置了BucketName和QueueName。
Resources:
MyQueuePolicy:
Type: AWS::SQS::QueuePolicy
Properties:
Queues:
- !Ref MyQueue
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal: "*"
Action: sqs:SendMessage
Resource: !GetAtt MyQueue.Arn
Condition:
ArnEquals:
aws:SourceArn: !GetAtt MyBucket.Arn
上述示例中,我们将允许任何主体(Principal)向SQS队列发送消息,并且限制发送者必须与S3存储桶的ARN(SourceArn)匹配。
确保在您的CloudFormation模板中正确配置了MyBucket和MyQueue。
转到S3控制台,选择存储桶,然后选择“属性”选项卡。
在“事件通知”部分,检查是否已配置正确的SQS队列。
确保存储桶策略允许S3向SQS队列发送通知。可以使用以下策略片段作为参考:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowSQSNotification",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "sqs:SendMessage",
"Resource": "arn:aws:sqs:us-east-1:123456789012:my-queue",
"Condition": {
"ArnLike": {
"aws:SourceArn": "arn:aws:s3:::my-bucket"
}
}
}
]
}
确保在您的存储桶策略中正确配置了SQS队列的ARN和S3存储桶的ARN。
通过执行上述步骤,您应该能够解决AWS CloudFormation的S3事件通知到SQS不起作用的问题,并使通知能够正常发送到SQS队列。