Aakash Dev
Aakash Dev

Reputation: 1

AWS EventBridge : Exclude specific s3 file patterns from triggering Lambda Function

I have an EventBridge rule that triggers a lambda function whenever a .txt or .csv file is uploaded to a specific s3 bucket. I want to modify the rule so that it wont trigger for files with certain pattern. eg : files that start with "abc". The following is my event pattern :

 {
        "detail": {
            "eventName": [
                "PutObject",
                "CopyObject",
                "CompleteMultipartUpload"
            ],
            "eventSource": [
                "s3.amazonaws.com"
            ],
            "requestParameters": {
                "bucketName": [
                    <bucket_name>
                ],
                "key": [
                    {
                        "wildcard": "folder_name/*/*.csv"
                    },
                    {
                        "wildcard": "folder_name/*/*.txt"
                    }
                ]
            }
        },
        "detail-type": [
            "AWS API Call via CloudTrail"
        ],
        "source": [
            "aws.s3"
        ]
    }

How can I achieve this ?

Upvotes: 0

Views: 404

Answers (2)

Matt Hill
Matt Hill

Reputation: 11

Echoing what @Michael Gasch said above. I would try to add "anything-but" similar to what is below. Note that you can't have multiple values in an anything-but matching rule, and I'm not sure if it will support wildcard matching which is what it looks like you want to do with "folder_name/*".

{
    "detail": {
        "eventName": [
            "PutObject",
            "CopyObject",
            "CompleteMultipartUpload"
        ],
        "eventSource": [
            "s3.amazonaws.com"
        ],
        "requestParameters": {
            "bucketName": [
                <bucket_name>
            ],
            "key": [
                {
                    "wildcard": "folder_name/*/*.csv"
                },
                {
                    "wildcard": "folder_name/*/*.txt"
                },
                {
                    "anything-but": {"prefix": "abc"}
                }
            ]
        }
    },
    "detail-type": [
        "AWS API Call via CloudTrail"
    ],
    "source": [
        "aws.s3"
    ]
}

Upvotes: 0

Related Questions