Skip to content

Commit 65cd134

Browse files
authored
Merge pull request #2981 from rssasidharan2/rssasidharan2-feature-eventbridge-schedule-lambda-dlq
New serverless pattern - EventBridge Scheduler to Lambda with Dual DLQs
2 parents 88ce7d6 + daa807b commit 65cd134

7 files changed

Lines changed: 666 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# SAM build artifacts
2+
.aws-sam/
3+
samconfig.toml
4+
5+
# Python
6+
__pycache__/
7+
*.py[cod]
8+
*$py.class
9+
*.so
10+
.Python
11+
env/
12+
venv/
13+
ENV/
14+
build/
15+
develop-eggs/
16+
dist/
17+
downloads/
18+
eggs/
19+
.eggs/
20+
lib/
21+
lib64/
22+
parts/
23+
sdist/
24+
var/
25+
wheels/
26+
*.egg-info/
27+
.installed.cfg
28+
*.egg
29+
30+
# IDE
31+
.vscode/
32+
.idea/
33+
*.swp
34+
*.swo
35+
*~
36+
37+
# OS
38+
.DS_Store
39+
Thumbs.db
40+
41+
# Logs
42+
*.log
43+
44+
# Environment variables
45+
.env
46+
.env.local
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# Amazon EventBridge Scheduler to AWS Lambda with Dual Dead Letter Queues
2+
3+
This pattern demonstrates how to use Amazon EventBridge Scheduler to invoke AWS Lambda functions with comprehensive failure handling through dual Dead Letter Queues (DLQs). The pattern is deployed using the AWS Serverless Application Model (SAM).
4+
5+
Learn more about this pattern at Serverless Land Patterns: [https://serverlessland.com/patterns](https://serverlessland.com/patterns)
6+
7+
Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.
8+
9+
## Requirements
10+
11+
* [Create an AWS account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
12+
* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured
13+
* [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
14+
* [AWS Serverless Application Model](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) (AWS SAM) installed
15+
16+
## Deployment Instructions
17+
18+
1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:
19+
```
20+
git clone https://github.com/aws-samples/serverless-patterns
21+
```
22+
1. Change directory to the pattern directory:
23+
```
24+
cd eventbridge-schedule-to-lambda-dlq-sam-python
25+
```
26+
1. From the command line, use AWS SAM to deploy the AWS resources for the pattern as specified in the template.yaml file:
27+
```
28+
sam deploy --guided
29+
```
30+
1. During the prompts:
31+
* Enter a stack name
32+
* Enter the desired AWS Region
33+
* Allow SAM CLI to create IAM roles with the required permissions.
34+
35+
Once you have run `sam deploy --guided` mode once and saved arguments to a configuration file (samconfig.toml), you can use `sam deploy` in future to use these defaults.
36+
37+
1. Note the outputs from the SAM deployment process. These contain the resource names and/or ARNs which are used for testing.
38+
39+
## How it works
40+
41+
This pattern showcases EventBridge Scheduler's robust failure handling capabilities through two distinct failure paths:
42+
43+
### Dual Dead Letter Queue Architecture
44+
45+
**Lambda Execution DLQ**: Captures failures that occur during Lambda function execution (code errors, timeouts, out-of-memory errors). After Lambda's built-in async retry mechanism exhausts its attempts (default: 2 retries), failed events are sent to this queue.
46+
47+
**EventBridge Scheduler DLQ**: Captures failures that occur at the invocation level before the Lambda function executes. This includes:
48+
- IAM permission errors (scheduler role lacks lambda:InvokeFunction permission)
49+
- Lambda service throttling (concurrent execution limits reached)
50+
- Lambda function state issues (function being deleted, doesn't exist, invalid ARN)
51+
- Resource not found errors (function deleted after schedule creation)
52+
- Maximum event age exceeded (event couldn't be delivered within configured time window)
53+
- Maximum retry attempts exhausted (all scheduler retries failed)
54+
55+
### Workflow
56+
57+
1. EventBridge Scheduler invokes the Lambda function asynchronously every 5 minutes
58+
2. If invocation fails (permissions, throttling, etc.), EventBridge Scheduler retries up to 3 times
59+
3. After scheduler retries are exhausted, the event is sent to the EventBridge Scheduler DLQ
60+
4. If invocation succeeds but execution fails (code error), Lambda retries automatically
61+
5. After Lambda retries are exhausted, the event is sent to the Lambda Execution DLQ
62+
63+
This dual DLQ architecture provides complete visibility into both configuration-level and code-level failures, enabling appropriate remediation strategies for each failure type.
64+
65+
## Testing
66+
67+
### Test Normal Execution
68+
69+
The function runs automatically every 5 minutes. View the logs:
70+
71+
```bash
72+
# Get function name from stack outputs
73+
FUNCTION_NAME=$(aws cloudformation describe-stacks \
74+
--stack-name <your-stack-name> \
75+
--query 'Stacks[0].Outputs[?OutputKey==`ScheduledFunctionName`].OutputValue' \
76+
--output text)
77+
78+
# Tail logs
79+
aws logs tail /aws/lambda/${FUNCTION_NAME} --follow
80+
```
81+
82+
### Test Lambda Execution Failure
83+
84+
Enable failure simulation to test the Lambda Execution DLQ:
85+
86+
```bash
87+
# Update function to simulate failures
88+
aws lambda update-function-configuration \
89+
--function-name ${FUNCTION_NAME} \
90+
--environment 'Variables={LOG_LEVEL=INFO,SIMULATE_FAILURE=true}'
91+
```
92+
93+
Wait up to 5 minutes for the next scheduled execution. After Lambda retries are exhausted, check the Lambda Execution DLQ:
94+
95+
```bash
96+
LAMBDA_DLQ_URL=$(aws cloudformation describe-stacks \
97+
--stack-name <your-stack-name> \
98+
--query 'Stacks[0].Outputs[?OutputKey==`LambdaExecutionDLQUrl`].OutputValue' \
99+
--output text)
100+
101+
aws sqs receive-message --queue-url ${LAMBDA_DLQ_URL}
102+
```
103+
104+
Disable failure simulation:
105+
106+
```bash
107+
aws lambda update-function-configuration \
108+
--function-name ${FUNCTION_NAME} \
109+
--environment 'Variables={LOG_LEVEL=INFO,SIMULATE_FAILURE=false}'
110+
```
111+
112+
### Test EventBridge Scheduler Invocation Failure
113+
114+
Remove Lambda invoke permission to test the EventBridge Scheduler DLQ:
115+
116+
```bash
117+
# Get schedule name
118+
SCHEDULE_NAME=$(aws cloudformation describe-stacks \
119+
--stack-name <your-stack-name> \
120+
--query 'Stacks[0].Outputs[?OutputKey==`ScheduleName`].OutputValue' \
121+
--output text)
122+
123+
# Get scheduler role name
124+
SCHEDULER_ROLE=$(aws cloudformation describe-stack-resources \
125+
--stack-name <your-stack-name> \
126+
--logical-resource-id SchedulerRole \
127+
--query 'StackResources[0].PhysicalResourceId' \
128+
--output text)
129+
130+
# Remove Lambda invoke permission
131+
aws iam delete-role-policy \
132+
--role-name ${SCHEDULER_ROLE} \
133+
--policy-name InvokeLambda
134+
```
135+
136+
Wait up to 5 minutes for the next scheduled execution. After scheduler retries are exhausted, check the Scheduler DLQ:
137+
138+
```bash
139+
SCHEDULER_DLQ_URL=$(aws cloudformation describe-stacks \
140+
--stack-name <your-stack-name> \
141+
--query 'Stacks[0].Outputs[?OutputKey==`SchedulerDLQUrl`].OutputValue' \
142+
--output text)
143+
144+
aws sqs receive-message --queue-url ${SCHEDULER_DLQ_URL}
145+
```
146+
147+
Restore permissions by redeploying:
148+
149+
```bash
150+
sam deploy
151+
```
152+
153+
## Cleanup
154+
155+
1. Delete the stack
156+
```bash
157+
sam delete --stack-name <your-stack-name>
158+
```
159+
1. Confirm the stack has been deleted
160+
```bash
161+
aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'<your-stack-name>')].StackStatus"
162+
```
163+
----
164+
Copyright 2026 Amazon.com, Inc. or its affiliates. All Rights Reserved.
165+
166+
SPDX-License-Identifier: MIT-0
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
{
2+
"title": "Amazon EventBridge Scheduler to AWS Lambda with Dual Dead Letter Queues",
3+
"description": "Creates an EventBridge schedule to invoke a Lambda function with dual DLQs for comprehensive failure handling",
4+
"language": "Python",
5+
"level": "200",
6+
"framework": "AWS SAM",
7+
"patternType": "Serverless",
8+
"patternArch": {
9+
"icon1": {
10+
"x": 10,
11+
"y": 50,
12+
"service": "eventbridge",
13+
"label": "EventBridge Scheduler"
14+
},
15+
"icon2": {
16+
"x": 45,
17+
"y": 50,
18+
"service": "lambda",
19+
"label": "AWS Lambda"
20+
},
21+
"icon3": {
22+
"x": 80,
23+
"y": 20,
24+
"service": "sqs",
25+
"label": "Scheduler DLQ"
26+
},
27+
"icon4": {
28+
"x": 80,
29+
"y": 80,
30+
"service": "sqs",
31+
"label": "Lambda Execution DLQ"
32+
},
33+
"line1": {
34+
"from": "icon1",
35+
"to": "icon2",
36+
"label": "invokes"
37+
},
38+
"line2": {
39+
"from": "icon1",
40+
"to": "icon3",
41+
"label": "invocation failures"
42+
},
43+
"line3": {
44+
"from": "icon2",
45+
"to": "icon4",
46+
"label": "execution failures"
47+
}
48+
},
49+
"introBox": {
50+
"headline": "How it works",
51+
"text": [
52+
"This pattern demonstrates EventBridge Scheduler's failure handling capabilities through dual Dead Letter Queues. One DLQ captures Lambda execution failures (code errors, timeouts), while the other captures scheduler invocation failures (permissions, throttling, resource not found).",
53+
"The pattern is deployed using the AWS Serverless Application Model (SAM) and includes a Python-based Lambda function that can simulate failures for testing both DLQ paths."
54+
]
55+
},
56+
"gitHub": {
57+
"template": {
58+
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/eventbridge-schedule-to-lambda-dlq-sam-python",
59+
"templateURL": "serverless-patterns/eventbridge-schedule-to-lambda-dlq-sam-python",
60+
"projectFolder": "eventbridge-schedule-to-lambda-dlq-sam-python",
61+
"templateFile": "template.yaml"
62+
}
63+
},
64+
"resources": {
65+
"bullets": [
66+
{
67+
"text": "Getting Started with EventBridge Scheduler",
68+
"link": "https://docs.aws.amazon.com/scheduler/latest/UserGuide/getting-started.html"
69+
},
70+
{
71+
"text": "EventBridge Scheduler Retry Policies",
72+
"link": "https://docs.aws.amazon.com/scheduler/latest/UserGuide/managing-schedule-retry.html"
73+
},
74+
{
75+
"text": "EventBridge Scheduler Dead Letter Queues",
76+
"link": "https://docs.aws.amazon.com/scheduler/latest/UserGuide/configuring-schedule-dlq.html"
77+
},
78+
{
79+
"text": "Lambda Asynchronous Invocation",
80+
"link": "https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html"
81+
},
82+
{
83+
"text": "SQS Dead Letter Queues",
84+
"link": "https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-dead-letter-queues.html"
85+
}
86+
]
87+
},
88+
"deploy": {
89+
"text": [
90+
"See the GitHub repo for detailed deployment instructions."
91+
]
92+
},
93+
"testing": {
94+
"text": [
95+
"See the GitHub repo for detailed testing instructions."
96+
]
97+
},
98+
"cleanup": {
99+
"text": [
100+
"Delete the stack: <code>sam delete --stack-name STACK_NAME</code>"
101+
]
102+
},
103+
"authors": [
104+
{
105+
"name": "Sasidharan Ramasamy",
106+
"bio": "Technical Account Manager @ AWS with over 10 years of industry experience",
107+
"linkedin": "https://www.linkedin.com/in/sasidharan-ramasamy/"
108+
}
109+
]
110+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"title": "Amazon EventBridge Scheduler to AWS Lambda with Dual Dead Letter Queues",
3+
"description": "Creates an EventBridge schedule to invoke a Lambda function with dual DLQs for comprehensive failure handling",
4+
"language": "Python",
5+
"level": "200",
6+
"framework": "AWS SAM",
7+
"introBox": {
8+
"headline": "How it works",
9+
"text": [
10+
"This pattern demonstrates EventBridge Scheduler's failure handling capabilities through dual Dead Letter Queues. One DLQ captures Lambda execution failures (code errors, timeouts), while the other captures scheduler invocation failures (permissions, throttling, resource not found).",
11+
"The pattern is deployed using the AWS Serverless Application Model (SAM) and includes a Python-based Lambda function that can simulate failures for testing both DLQ paths."
12+
]
13+
},
14+
"gitHub": {
15+
"template": {
16+
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/eventbridge-schedule-to-lambda-dlq-sam-python",
17+
"templateURL": "serverless-patterns/eventbridge-schedule-to-lambda-dlq-sam-python",
18+
"projectFolder": "eventbridge-schedule-to-lambda-dlq-sam-python",
19+
"templateFile": "template.yaml"
20+
}
21+
},
22+
"resources": {
23+
"bullets": [
24+
{
25+
"text": "Getting Started with EventBridge Scheduler",
26+
"link": "https://docs.aws.amazon.com/scheduler/latest/UserGuide/getting-started.html"
27+
},
28+
{
29+
"text": "EventBridge Scheduler Retry Policies",
30+
"link": "https://docs.aws.amazon.com/scheduler/latest/UserGuide/managing-schedule-retry.html"
31+
},
32+
{
33+
"text": "EventBridge Scheduler Dead Letter Queues",
34+
"link": "https://docs.aws.amazon.com/scheduler/latest/UserGuide/configuring-schedule-dlq.html"
35+
},
36+
{
37+
"text": "Lambda Asynchronous Invocation",
38+
"link": "https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html"
39+
},
40+
{
41+
"text": "SQS Dead Letter Queues",
42+
"link": "https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-dead-letter-queues.html"
43+
}
44+
]
45+
},
46+
"deploy": {
47+
"text": [
48+
"See the GitHub repo for detailed deployment instructions."
49+
]
50+
},
51+
"testing": {
52+
"text": [
53+
"See the GitHub repo for detailed testing instructions."
54+
]
55+
},
56+
"cleanup": {
57+
"text": [
58+
"Delete the stack: <code>sam delete --stack-name STACK_NAME</code>"
59+
]
60+
},
61+
"authors": [
62+
{
63+
"name": "Sasidharan Ramasamy",
64+
"bio": "Technical Account Manager @ AWS with over 10 years of industry experience",
65+
"linkedin": "https://www.linkedin.com/in/sasidharan-ramasamy/"
66+
}
67+
]
68+
}

0 commit comments

Comments
 (0)