Multiple triggers on S3 bucket?

0

Scratching my head on this one, maybe it's not possible but I can't see why not if so.

I have an S3 bucket with two event notifications configured.

  1. The first is for Put of objects with prefix 'CB' and suffix '.eml'. The target is a lambda function called 'Reporter'.
  2. The second is for Put and Delete of objects with prefix 'CB' and suffix '.zip'. The target is a lambda function called 'Launcher'.

The second works fine: the Launcher function is called with the correct event when a matching object is added or removed from the bucket. However the first one never fires, as there are no log streams generated in the log group for the lambda function.

Is there any obvious reason? e.g. only one trigger is allowed per bucket? I don't really know how to troubleshoot this further, as there are no logs that I'm aware of that would contain a "trigger failed" entry.

The configuration looks fine:

$ aws s3api get-bucket-notification-configuration --bucket <bucket_name>
{
    "LambdaFunctionConfigurations": [
        {
            "Id": "Launch/Terminate trigger",
            "LambdaFunctionArn": "arn:aws:lambda:eu-west-1:<acc_id>:function:Launcher",
            "Events": [
                "s3:ObjectCreated:*",
                "s3:ObjectRemoved:*"
            ],
            "Filter": {
                "Key": {
                    "FilterRules": [
                        {
                            "Name": "Prefix",
                            "Value": "CB"
                        },
                        {
                            "Name": "Suffix",
                            "Value": ".zip"
                        }
                    ]
                }
            }
        },
        {
            "Id": "Email trigger",
            "LambdaFunctionArn": "arn:aws:lambda:eu-west-1:<acc_id>:function:Reporter",
            "Events": [
                "s3:ObjectCreated:*"
            ],
            "Filter": {
                "Key": {
                    "FilterRules": [
                        {
                            "Name": "Prefix",
                            "Value": "CB"
                        },
                        {
                            "Name": "Suffix",
                            "Value": ".eml"
                        }
                    ]
                }
            }
        }
    ]
}

The S3 permissions on each of the target lambda functions are also OK:

Reporter lambda permissions:

Statement ID trigger-Reporter
Principal s3.amazonaws.com
Effect Allow
Action lambda:InvokeFunction
Conditions
{
  "ArnLike": {
        "AWS:SourceArn": "arn:aws:s3:::<bucket_name>"
  }
}

Launcher lambda permissions:

Statement ID trigger-Launcher
Principal s3.amazonaws.com
Effect Allow
Action lambda:InvokeFunction
Conditions
{
  "ArnLike": {
        "AWS:SourceArn": "arn:aws:s3:::<bucket_name>"
  }
}

Thanks,

David

dmb0058
asked a month ago406 views
2 Answers
1
Accepted Answer

Hello.

I tested it with the same settings as below in my AWS account.
It was confirmed that when the file "CB-test.eml" is uploaded, the Lambda function "testfunc" runs, and when the file "CB-test.zip" is uploaded, the Lambda function "s3test" runs.
Therefore, I don't think there is any problem with multiple settings.
There may be a problem with the file name you are uploading.

{
    "LambdaFunctionConfigurations": [
        {
            "Id": "test",
            "LambdaFunctionArn": "arn:aws:lambda:ap-northeast-1:111111111111:function:s3test",
            "Events": [
                "s3:ObjectCreated:*",
                "s3:ObjectRemoved:*"
            ],
            "Filter": {
                "Key": {
                    "FilterRules": [
                        {
                            "Name": "Prefix",
                            "Value": "CB"
                        },
                        {
                            "Name": "Suffix",
                            "Value": ".zip"
                        }
                    ]
                }
            }
        },
        {
            "Id": "test1",
            "LambdaFunctionArn": "arn:aws:lambda:ap-northeast-1:111111111111:function:testfunc",
            "Events": [
                "s3:ObjectCreated:*"
            ],
            "Filter": {
                "Key": {
                    "FilterRules": [
                        {
                            "Name": "Prefix",
                            "Value": "CB"
                        },
                        {
                            "Name": "Suffix",
                            "Value": ".eml"
                        }
                    ]
                }
            }
        }
    ]
}
profile picture
EXPERT
answered a month ago
profile picture
EXPERT
reviewed a month ago
profile pictureAWS
EXPERT
SriniV
reviewed a month ago
profile pictureAWS
EXPERT
iBehr
reviewed a month ago
profile pictureAWS
EXPERT
reviewed a month ago
  • That's good news - at least it confirms that my understanding of how it should work is correct, and I'm not going crazy :)

    I think you're right that the event filter isn't being matched and I'll re-check this again. It did occur to me earlier that the filename might have a hidden space or control character as the first character or something like that, but I haven't found a problem so far.

    David

0

I found the (self-inflicted) answers to my problem so I thought I'd put it here in case it helps anyone.

  1. The Reporter lambda probably was being called, but it had a syntax error (a class I hadn't imported after the last change). I discovered this when I re-ran my test code from the lambda dashboard;
  2. Once the error was fixed, the lambda ran (it delivered the expected email) but produced no CloudWatch log streams. This was because the lambda's IAM role didn't include a policy that would give it permission to create or write to Cloud Watch. Once I added "CloudWatchFullAccessV2" everything worked as expected.

Pilot error again :)

David

dmb0058
answered a month ago