An EventBridge rule should trigger a Lambda on EC2 state changes, but the Lambda never runs.
AdvancedTroubleshootingRoute 53, CloudFront, API Gateway and Messaging
Answer
Likely causes → The event pattern does not match: a typo, wrong case, or values not wrapped in arrays. The rule is on the wrong event bus or Region. The Lambda resource policy does not allow events.amazonaws.com, which shows up as FailedInvocations. Or the rule is disabled.
Diagnose →
aws events describe-rule --name ec2-state --query '[State,EventBusName,EventPattern]'
aws events test-event-pattern --event-pattern file://pattern.json --event file://sample-event.json
aws cloudwatch get-metric-statistics --namespace AWS/Events --metric-name FailedInvocations \
--dimensions Name=RuleName,Value=ec2-state --statistics Sum --period 300 \
--start-time $(date -u -d '-1 day' +%FT%TZ) --end-time $(date -u +%FT%TZ)
aws lambda get-policy --function-name on-ec2-change
Fix →
- Correct the pattern, for example
{"source":["aws.ec2"],"detail-type":["EC2 Instance State-change Notification"],"detail":{"state":["stopped"]}} - Add the permission:
aws lambda add-permission --function-name on-ec2-change --statement-id evb --action lambda:InvokeFunction --principal events.amazonaws.com --source-arn <rule-arn> - Add a DLQ on the target
Prevent → Unit-test patterns with test-event-pattern in CI, and alarm on FailedInvocations.
More on Route 53, CloudFront, API Gateway and Messaging
You created a public hosted zone and records for `example.com`, but `dig example.com` returns `NXDOMAIN` or old records.Beginner`InvalidChangeBatch: RRSet of type CNAME with DNS name example.com. is not permitted at apex in zone example.com.`BeginnerThe primary Region is down, but Route 53 failover records still send traffic to it.IntermediateA Route 53 health check reports `Failure: Connection timed out` for an endpoint that works fine from your laptop.IntermediateYou changed an A record an hour ago, but some users still reach the old server, and a newly created name returned `NXDOMAIN` for a while.AdvancedCloudFront returns `403 AccessDenied` (S3 XML) for every object after you switched the S3 origin to Origin Access Control.Intermediate