您可以使用AWS CloudFormation配置S3事件到SQS的方法如下所示:
Resources:
MyBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: my-bucket
MyQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: my-queue
Resources:
MyQueuePolicy:
Type: AWS::SQS::QueuePolicy
Properties:
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal: "*"
Action: "sqs:SendMessage"
Resource:
- !GetAtt MyQueue.Arn
Condition:
ArnLike:
aws:SourceArn: !GetAtt MyBucket.Arn
Queues:
- !Ref MyQueue
Resources:
MyBucketNotification:
Type: AWS::S3::BucketNotification
Properties:
Bucket: !Ref MyBucket
NotificationConfiguration:
QueueConfigurations:
- Event: s3:ObjectCreated:*
Queue: !GetAtt MyQueue.Arn
完整的CloudFormation模板示例:
Resources:
MyBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: my-bucket
MyQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: my-queue
MyQueuePolicy:
Type: AWS::SQS::QueuePolicy
Properties:
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal: "*"
Action: "sqs:SendMessage"
Resource:
- !GetAtt MyQueue.Arn
Condition:
ArnLike:
aws:SourceArn: !GetAtt MyBucket.Arn
Queues:
- !Ref MyQueue
MyBucketNotification:
Type: AWS::S3::BucketNotification
Properties:
Bucket: !Ref MyBucket
NotificationConfiguration:
QueueConfigurations:
- Event: s3:ObjectCreated:*
Queue: !GetAtt MyQueue.Arn
这样,当S3存储桶中有新的对象创建时,该事件将被发送到SQS队列中。
上一篇:AWS CloudFormation模板:哪个部分?
下一篇:AWS CloudFormation启动Hyperledger Fabric失败,错误原因:无法创建:[EC2InstanceForDev]。