如何构造SNS过滤策略以匹配部分S3对象键

时间:2018-01-18 22:22:58

标签: amazon-web-services amazon-sns

我已经创建了对SNS主题的订阅,其中所有事件都来自S3 ObjectCreated:Put actions。我只想收到S3对象键包含字符串' KLWX'的通知。该过滤政策应该是什么样的?通知数据如下,但是'消息'属性值以字符串形式给出,而不是JSON对象。我只是扩展它以便于阅读。

{
"SignatureVersion": "1",
"Type": "Notification",
"TopicArn": "xxx",
"Message": {
    "Records": [{
        "eventVersion": "2.0",
        "eventSource": "aws:s3",
        "awsRegion": "us-east-1",
        "eventTime": "2018-01-18T20:16:27.590Z",
        "eventName": "ObjectCreated:Put",
        "userIdentity": {
            "principalId": "xxx"
        },
        "requestParameters": {
            "sourceIPAddress": "xxx"
        },
        "responseElements": {
            "x-amz-request-id": "6CF3314E6D6B7671",
            "x-amz-id-2": "tJdr3KDcAsp1tuGdo6y4jBLkYXsEDEeVPcvQ1SWQoLXWsZL81WUzbloDe1HxbhGes4u0tY9Jh+g="
        },
        "s3": {
            "s3SchemaVersion": "1.0",
            "configurationId": "NewNEXRADLevel2Object",
            "bucket": {
                "name": "xxx",
                "ownerIdentity": {
                    "principalId": "xxx"
                },
                "arn": "xxx"
            },
            "object": {
                "key": "KCBW/881/20180118-201329-015-I",
                "size": 16063,
                "eTag": "772cd2d2e82b22448792308755891350",
                "sequencer": "005A61009B8EC82991"
            }
        }
    }]
},
"UnsubscribeURL": "xxx",
"Signature": "xxx",
"Timestamp": "2018-01-18T20:16:27.626Z",
"SigningCertURL": "xxx",
"Subject": "Amazon S3 Notification",
"MessageId": "ed6a0365-4af2-5497-9be0-51be4829cdee"

}

2 个答案:

答案 0 :(得分:0)

你必须在S3上这样做。创建事件时,可以使用前缀/后缀的组合来过滤哪个对象将通知发送到您的SNS主题。

假设存储桶名称为YourBucket,而您的对象键为KCBW/881/20180118-201329-015-I,则必须使用prefix = KLWX/

在YourBucket上配置S3事件

答案 1 :(得分:0)

您可以订阅并添加AWS Lambda函数的目标。在该功能中,您可以编写逻辑代码。如果需要,您可以从那里发送另一条SNS消息,或根据需要存储/处理数据。 enter image description here