如何构建 SNS 过滤策略来匹配部分 S3 对象密钥

sup*_*azy 5 amazon-web-services amazon-sns

我创建了一个 SNS 主题的订阅,其中所有事件都来自 S3 ObjectCreated:Put 操作。我只想接收 S3 对象键包含字符串“KLWX”的通知。该过滤策略应该是什么样的?通知数据如下,但“Message”属性值以字符串形式给出,而不是 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"
Run Code Online (Sandbox Code Playgroud)

}

小智 1

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

假设存储桶名称是YourBucket,并且您的对象键是KCBW/881/20180118-201329-015-I,您必须使用以下命令在 YourBucket 上配置 S3 事件prefix = KLWX/