Sometimes, an event isn't successfully delivered to the target(s) specified in a rule. By default, EventBridge will retry for 24 hours and up to 185 times, but you can customize the retry policy.
If EventBridge cannot deliver an event after all its retries, it can send it to a dead-letter queue. You can then inspect the event and remediate the underlying issue.
import{Function}from'@aws-cdk/aws-lambda';import{Rule}from'@aws-cdk/aws-events';import*astargetsfrom'@aws-cdk/aws-events-targets';exportclassMyStackextendscdk.Stack{constructor(scope:cdk.Construct,id:string,props?:cdk.StackProps){super(scope,id,props);constmyFunction=newFunction(scope,'MyFunction',{code:Code.fromAsset('src/hello/'),handler:'main.handler',runtime:Runtime.PYTHON_3_8,});constmyRule=newRule(scope,'MyRule',{eventPattern:{source:['my-source'],}});myRule.addTarget(newtargets.LambdaFunction(myfunction,// Add a DLQ to the 'myFunction' target{deadLetterQueue:myQueue,}));}}
1 2 3 4 5 6 7 8 910111213141516171819
{"Resources":{"MyRule":{"Type":"AWS::Events::Rule","Properties":{"EventBusName":"default","EventPattern":"{\"source\": [\"my-source\"]}","Targets":[{"Id":"MyFunction","Arn":"arn:aws:lambda:us-east-1:111122223333:function:MyFunction",// Add a DLQ to the 'MyFunction' target"DeadLetterConfig":{"Arn":"arn:aws:sqs:us-east-1:111122223333:dlq"}}]}}}}
1 2 3 4 5 6 7 8 9101112131415
Resources:MyRule:Type:AWS::Events::RuleProperties:EventBusName:defaultEventPattern:|{"source": ["my-source"]}Targets:-Id:MyFunctionArn:arn:aws:lambda:us-east-1:111122223333:function:MyFunction# Add a DLQ to the 'MyFunction' targetDeadLetterConfig:Arn:arn:aws:sqs:us-east-1:111122223333:dlq
1 2 3 4 5 6 7 8 910111213141516
resources:Resources:MyRule:Type:AWS::Events::RuleProperties:EventBusName:defaultEventPattern:|{"source": ["my-source"]}Targets:-Id:MyFunctionArn:arn:aws:lambda:us-east-1:111122223333:function:MyFunction# Add a DLQ to the 'MyFunction' targetDeadLetterConfig:Arn:arn:aws:sqs:us-east-1:111122223333:dlq
1 2 3 4 5 6 7 8 9101112131415161718
resource"aws_cloudwatch_event_rule""this"{event_pattern=<<EOF{ "source": ["my-source"]}EOF}resource"aws_cloudwatch_event_target""this"{rule=aws_cloudwatch_event_rule.this.nametarget_id="MyFunction"arn="arn:aws:lambda:us-east-1:111122223333:function:MyFunction" # Add a DLQ to the 'MyFunction' targetdead_letter_config{arn="arn:aws:sqs:us-east-1:111122223333:dlq"}}