- Newest
- Most votes
- Most comments
The issue you're experiencing with your Lambda function being triggered twice is not uncommon and can happen for several reasons, even when your EventBridge rule configuration appears correct.
Based on your description, you have a single EventBridge rule with a CRON expression of 0 14 1 * ? * which should trigger your Lambda function only once at 14:00 UTC on the first day of each month. However, you're observing an additional execution at 13:00 UTC.
Here are some possible explanations for this behavior:
-
Multiple triggers: Even though you only see one trigger in the Lambda configuration, there might be another service or event source invoking your function. Lambda functions can have multiple triggers, each acting independently.
-
Lambda's execution behavior: AWS Lambda is designed with high availability in mind, which sometimes means it cannot guarantee exactly-once execution. In some cases, Lambda might execute a function twice due to internal service operations like load balancing or scaling activities.
-
Retry mechanisms: If your function encountered an error or timeout during execution, Lambda might automatically retry the invocation, leading to what appears to be multiple executions.
-
Time zone considerations: If you're looking at logs in a different time zone, it might appear as if the function is running at different times when it's actually just one execution.
To troubleshoot this issue:
-
Check CloudWatch Logs for both executions to see if they have identical event data or if there are any error messages.
-
Implement idempotency in your Lambda function to ensure that even if it runs multiple times, it won't send duplicate emails.
-
Add logging at the beginning of your function to capture and compare the event data from both executions.
-
Check if there are any other AWS services in your account that might be invoking this Lambda function.
-
Review the Lambda metrics in CloudWatch to see if there are any errors or throttling events that might be causing retries.
If this continues to be an issue, you might need to implement a deduplication mechanism using a unique identifier for each scheduled event to prevent sending duplicate emails.
Sources
Invoking Lambda with events from other AWS services - AWS Lambda
lambda function is executed twice without an additional trigger | AWS re:Post
Lambda Invoke Manually from jenkins using AWS Lambda Invoke | AWS re:Post
Hello.
EventBridge may run multiple times in rare cases.
However, it only runs multiple times on rare occasions, so if it's running multiple times each month it's a bit puzzling.
As stated in the automated response to re:Post Agent, it is possible that it is being executed from somewhere other than EventBridge.
https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-troubleshooting.html#eb-rule-triggered-more-than-once
If it's running monthly, why not enable Lambda data events in CloudTrail and check the Lambda execution history?
This will allow you to identify which service is executing Lambda at 13:00.
https://docs.aws.amazon.com/lambda/latest/dg/logging-using-cloudtrail.html#cloudtrail-data-events
https://repost.aws/knowledge-center/lambda-user-invoked-function
