Skip to content

Commit d48a2e1

Browse files
author
Luigi Napoleone Capasso
committed
Address PR feedback and fix issues
1 parent 6c8b87f commit d48a2e1

3 files changed

Lines changed: 45 additions & 22 deletions

File tree

dynamodb-eventbridge-scheduler/README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Dynamic EventBridge Scheduler from DynamoDB Streams
1+
# Dynamic Amazon EventBridge Scheduler from Amazon DynamoDB Streams
22

33
This pattern demonstrates how to dynamically create, update, and delete Amazon EventBridge Scheduler schedules based on changes in a DynamoDB table using DynamoDB Streams.
44

@@ -21,7 +21,7 @@ Important: this application uses various AWS services and there are costs associ
2121
```
2222
2. Change directory to the pattern directory:
2323
```
24-
cd dynamodb-eventbridge-scheduler
24+
cd serverless-patterns/dynamodb-eventbridge-scheduler
2525
```
2626
3. From the command line, use AWS SAM to build and deploy the AWS resources for the pattern as specified in the template.yml file:
2727
```
@@ -87,7 +87,7 @@ EventBridge Scheduler invokes TargetLambdaFunction at scheduled time
8787

8888
### Verify Auto-Created Test Schedule
8989

90-
After deployment, a test schedule is automatically created that fires 2 minutes later:
90+
After deployment, a test schedule is automatically created that fires 5 minutes later (UTC time):
9191

9292
1. Check if the schedule was created:
9393
```bash
@@ -97,12 +97,15 @@ aws scheduler get-schedule --name auto-test-schedule
9797
2. View the schedule in EventBridge Console:
9898
- Navigate to EventBridge → Scheduler → Schedules
9999
- Look for `auto-test-schedule`
100+
- Note the "Next invocation" time (displayed in your local timezone)
100101

101-
3. After 2 minutes, check the Target Lambda logs:
102+
3. After 5 minutes, check the Target Lambda logs:
102103
```bash
103104
aws logs tail /aws/lambda/ScheduledTaskExecutor --follow
104105
```
105106

107+
**Note:** All schedule times use UTC timezone. EventBridge Scheduler expressions use the format `at(YYYY-MM-DDTHH:MM:SS)` in UTC.
108+
106109
### Create Your Own Schedule
107110

108111
1. Get the DynamoDB table name from the stack outputs:
@@ -112,18 +115,23 @@ aws cloudformation describe-stacks --stack-name <your-stack-name> \
112115
--output text
113116
```
114117

115-
2. Insert a new schedule (set time to a few minutes in the future):
118+
2. Insert a new schedule (set time to a few minutes in the future in UTC):
116119
```bash
117120
aws dynamodb put-item \
118121
--table-name ScheduleConfigs \
119122
--item '{
120123
"scheduleId": {"S": "my-test-schedule"},
121-
"scheduleExpression": {"S": "at(2026-02-12T15:30:00)"},
124+
"scheduleExpression": {"S": "at(2026-02-12T20:00:00)"},
122125
"payload": {"S": "{\"message\": \"Hello from my schedule\"}"},
123126
"enabled": {"BOOL": true}
124127
}'
125128
```
126129

130+
**Important:** The time must be in UTC and in the future. To get current UTC time:
131+
```bash
132+
date -u +"%Y-%m-%dT%H:%M:%S"
133+
```
134+
127135
3. Verify the schedule was created:
128136
```bash
129137
aws scheduler get-schedule --name my-test-schedule
@@ -141,9 +149,11 @@ aws dynamodb update-item \
141149
--table-name ScheduleConfigs \
142150
--key '{"scheduleId": {"S": "my-test-schedule"}}' \
143151
--update-expression "SET scheduleExpression = :expr" \
144-
--expression-attribute-values '{":expr": {"S": "at(2026-02-12T16:00:00)"}}'
152+
--expression-attribute-values '{":expr": {"S": "at(2026-02-12T21:00:00)"}}'
145153
```
146154

155+
**Note:** Time must be in UTC and in the future.
156+
147157
### Delete a Schedule
148158

149159
```bash

dynamodb-eventbridge-scheduler/example-pattern.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"title": "Dynamic EventBridge Scheduler from DynamoDB Streams",
2+
"title": "Dynamic Amazon EventBridge Scheduler from Amazon DynamoDB Streams",
33
"description": "Automatically create, update, and delete EventBridge Scheduler schedules based on DynamoDB table changes using DynamoDB Streams.",
44
"language": "Python",
55
"level": "200",
6-
"framework": "SAM",
6+
"framework": "AWS SAM",
77
"introBox": {
88
"headline": "How it works",
99
"text": [
@@ -60,11 +60,9 @@
6060
},
6161
"authors": [
6262
{
63-
"name": "Your Name",
64-
"image": "",
65-
"bio": "Solutions Architect @ AWS",
66-
"linkedin": "",
67-
"twitter": ""
63+
"name": "Luigi Napoleone Capasso",
64+
"bio": "Technical Account Manager @ AWS",
65+
"linkedin": ""
6866
}
6967
],
7068
"patternArch": {

dynamodb-eventbridge-scheduler/template.yaml

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
AWSTemplateFormatVersion: '2010-09-09'
22
Transform: AWS::Serverless-2016-10-31
3-
Description: 'Dynamic EventBridge Scheduler creation from DynamoDB Streams'
3+
Description: 'Dynamic Amazon EventBridge Scheduler creation from Amazon DynamoDB Streams'
44

55
Resources:
66
# DynamoDB Table with Streams enabled
@@ -176,7 +176,7 @@ Resources:
176176
import boto3
177177
import json
178178
import cfnresponse
179-
from datetime import datetime, timedelta
179+
from datetime import datetime, timedelta, timezone
180180
181181
dynamodb = boto3.resource('dynamodb')
182182
@@ -185,25 +185,36 @@ Resources:
185185
if event['RequestType'] == 'Create':
186186
table = dynamodb.Table(event['ResourceProperties']['TableName'])
187187
188-
# Create a schedule 2 minutes from now
189-
schedule_time = datetime.utcnow() + timedelta(minutes=2)
188+
# Create a schedule 5 minutes from now (UTC)
189+
schedule_time = datetime.now(timezone.utc) + timedelta(minutes=5)
190190
schedule_expression = schedule_time.strftime('at(%Y-%m-%dT%H:%M:%S)')
191191
192+
print(f"Current UTC time: {datetime.now(timezone.utc)}")
193+
print(f"Schedule will fire at: {schedule_time} UTC")
194+
print(f"Schedule expression: {schedule_expression}")
195+
192196
table.put_item(Item={
193197
'scheduleId': 'auto-test-schedule',
194198
'scheduleExpression': schedule_expression,
195-
'payload': json.dumps({'message': 'Auto-created test schedule', 'timestamp': str(schedule_time)}),
199+
'payload': json.dumps({
200+
'message': 'Auto-created test schedule',
201+
'scheduledTime': schedule_time.isoformat(),
202+
'createdAt': datetime.now(timezone.utc).isoformat()
203+
}),
196204
'enabled': True
197205
})
198206
199-
print(f"Created test schedule for: {schedule_time}")
207+
print(f"Successfully created test schedule in DynamoDB")
200208
cfnresponse.send(event, context, cfnresponse.SUCCESS, {
201-
'ScheduleTime': str(schedule_time)
209+
'ScheduleTime': schedule_time.isoformat(),
210+
'ScheduleExpression': schedule_expression
202211
})
203212
else:
204213
cfnresponse.send(event, context, cfnresponse.SUCCESS, {})
205214
except Exception as e:
206-
print(f"Error: {e}")
215+
print(f"Error creating test schedule: {e}")
216+
import traceback
217+
traceback.print_exc()
207218
cfnresponse.send(event, context, cfnresponse.FAILED, {'Error': str(e)})
208219
209220
TriggerTestSchedule:
@@ -229,6 +240,10 @@ Outputs:
229240
Description: Auto-created test schedule ID
230241
Value: auto-test-schedule
231242

243+
TestScheduleNote:
244+
Description: Important timing information
245+
Value: "The test schedule fires 5 minutes after deployment in UTC timezone. Check EventBridge Scheduler console for exact time."
246+
232247
ExampleDynamoDBItem:
233248
Description: Example item to insert into DynamoDB
234249
Value: !Sub |

0 commit comments

Comments
 (0)