Skip to content

Commit c64cf0f

Browse files
authored
Merge pull request #2375 from farrjam/farrjam-feature-delayed-eventbridge-events-terraform
Terraform serverless pattern - delayed-eventbridge-events
2 parents 67213bc + 5b199e9 commit c64cf0f

File tree

6 files changed

+502
-0
lines changed

6 files changed

+502
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Delayed EventBridge events with EventBridge Scheduler
2+
3+
This pattern listens for EventBridge events, processes them and creates schedules for every user. 24 hours after user has been created a schedule is run that publishes events directly into EventBridge. The pattern is deployed using Terraform.
4+
5+
Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/delayed-eventbridge-events-terraform.
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+
* [Terraform](https://learn.hashicorp.com/tutorials/terraform/install-cli?in=terraform/aws-get-started) 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 delayed-eventbridge-events-terraform
25+
```
26+
1. From the command line, initialize Terraform:
27+
```
28+
terraform init
29+
```
30+
1. From the commend line, apply the configuration in the main.tf file and follow the prompts:
31+
```
32+
terraform apply
33+
```
34+
35+
## How it works
36+
37+
We assume we have a business requirement to email a customer 24 hours after they have signed up.
38+
39+
1. `UserCreated` event is triggered. In this example we assume a `UserCreated` event is triggered into our event bus.
40+
2. EventBridge Rule setup to listen to the `UserCreated` event.
41+
3. Lambda function listens to `UserCreated` event and creates an Amazon EventBridge Schedule for 24 hours in the future (2 mins for development mode).
42+
4. 24 hours pass, and schedule is triggered and raises `UserCreated24HoursAgo` event directly into EventBridge..
43+
5. Consumers listen for event and process it. An example would be email a welcome message to customers or an offer etc.
44+
45+
## Testing
46+
47+
Use the [AWS CLI](https://aws.amazon.com/cli/) to send a test event to EventBridge:
48+
49+
1. Send an event to EventBridge:
50+
```bash
51+
aws events put-events --entries "Source='myapp.users',DetailType='UserCreated',Detail='{\"id\": \"test-customer-id\", \"firstName\": \"FirstName\", \"lastName\": \"LastName\"}',EventBusName='<custom-event-bus-ARN>'"
52+
```
53+
54+
2. Check the CloudWatch metrics of `UserCreatedRule` and `UserCreated24HoursAgoRule` EventBridge rule and `SchedulesForUsers24HoursAfterCreation` EventBridge Scheduler Group. Also, check the CloudWatch Logs of Lambda Functions which are targets of corresponding `UserCreatedRule` and `UserCreated24HoursAgoRule` EventBridge rules within CloudWatch Logs Console or via `aws logs start-live-tail --log-group-identifiers <Lambda Function LogGroup ARN>` CLI command.
55+
56+
## Cleanup
57+
58+
1. Delete all created resources and follow prompts:
59+
```
60+
terraform destroy
61+
```
62+
----
63+
Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
64+
65+
SPDX-License-Identifier: MIT-0
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{
2+
"title": "Delayed Amazon EventBridge events with Amazon EventBridge Scheduler",
3+
"description": "Setup future Amazon EventBridge events with Amazon EventBridge Scheduler",
4+
"language": "Node.js",
5+
"level": "200",
6+
"framework": "Terraform",
7+
"introBox": {
8+
"headline": "How it works",
9+
"text": [
10+
"This pattern listens for Amazon EventBridge events, processes them and creates schedules for every user. 24 hours after user has been created a schedule is run that publishes events directly into Amazon EventBridge."
11+
]
12+
},
13+
"gitHub": {
14+
"template": {
15+
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/delayed-eventbridge-events-terraform",
16+
"projectFolder": "delayed-eventbridge-events-terraform",
17+
"templateURL": "serverless-patterns/delayed-eventbridge-events-terraform",
18+
"templateFile": "main.tf"
19+
}
20+
},
21+
"resources": {
22+
"bullets": [
23+
{
24+
"text": "What is Amazon EventBridge Scheduler?",
25+
"link": "https://docs.aws.amazon.com/scheduler/latest/UserGuide/what-is-scheduler.html"
26+
}
27+
]
28+
},
29+
"deploy": {
30+
"text": [
31+
"terraform apply"
32+
]
33+
},
34+
"testing": {
35+
"text": [
36+
"See the GitHub repo for detailed testing instructions."
37+
]
38+
},
39+
"cleanup": {
40+
"text": [
41+
"Delete the stack: <code>terraform destroy</code>."
42+
]
43+
},
44+
"authors": [
45+
{
46+
"name": "Farrukh Jamal",
47+
"image": "https://media.licdn.com/dms/image/C5103AQHH_uSeGxOlZw/profile-displayphoto-shrink_400_400/0/1570698220038?e=1726099200&v=beta&t=7HUDKvPyM5GbBA1eOhVGB9POwFhXC3v87-vrqCIk1d0",
48+
"bio": "Cloud Engineer at AWS based in the Australia.",
49+
"linkedin": "farrukhjamal"
50+
}
51+
],
52+
"patternArch": {
53+
"icon1": {
54+
"x": 15,
55+
"y": 50,
56+
"service": "eventbridge",
57+
"label": "Amazon EventBridge"
58+
},
59+
"icon2": {
60+
"x": 42,
61+
"y": 50,
62+
"service": "lambda",
63+
"label": "AWS Lambda"
64+
},
65+
"icon3": {
66+
"x": 60,
67+
"y": 50,
68+
"service": "eventbridge-scheduler",
69+
"label": "Schedule"
70+
},
71+
"icon4": {
72+
"x": 87,
73+
"y": 50,
74+
"service": "eventbridge",
75+
"label": "Amazon EventBridge"
76+
},
77+
"line1": {
78+
"from": "icon1",
79+
"to": "icon2",
80+
"label": "UserCreated"
81+
},
82+
"line2": {
83+
"from": "icon3",
84+
"to": "icon4",
85+
"label": "24 Hours Later"
86+
}
87+
}
88+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"title": "Delayed EventBridge events with EventBridge Scheduler",
3+
"description": "Setup future EventBridge events with EventBridge Scheduler",
4+
"language": "Node.js",
5+
"level": "200",
6+
"framework": "Terraform",
7+
"introBox": {
8+
"headline": "How it works",
9+
"text": [
10+
"This pattern listens for EventBridge events, processes them and creates schedules for every user. 24 hours after user has been created a schedule is run that publishes events directly into EventBridge."
11+
]
12+
},
13+
"gitHub": {
14+
"template": {
15+
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/delayed-eventbridge-events-terraform",
16+
"templateURL": "serverless-patterns/delayed-eventbridge-events-terraform",
17+
"templateFile": "delayed-eventbridge-events-terraform/main.tf"
18+
}
19+
},
20+
"resources": {
21+
"bullets": [
22+
{
23+
"text": "What is Amazon EventBridge Scheduler?",
24+
"link": "https://docs.aws.amazon.com/scheduler/latest/UserGuide/what-is-scheduler.html"
25+
}
26+
]
27+
},
28+
"deploy": {
29+
"text": [
30+
"terraform apply"
31+
]
32+
},
33+
"testing": {
34+
"text": [
35+
"See the GitHub repo for detailed testing instructions."
36+
]
37+
},
38+
"cleanup": {
39+
"text": [
40+
"Delete the stack: <code>terraform destroy</code>."
41+
]
42+
},
43+
"authors": [
44+
{
45+
"name": "Farrukh Jamal",
46+
"image": "https://media.licdn.com/dms/image/C5103AQHH_uSeGxOlZw/profile-displayphoto-shrink_400_400/0/1570698220038?e=1726099200&v=beta&t=7HUDKvPyM5GbBA1eOhVGB9POwFhXC3v87-vrqCIk1d0",
47+
"bio": "Cloud Engineer at AWS based in the Australia.",
48+
"linkedin": "farrukhjamal"
49+
}
50+
]
51+
}

0 commit comments

Comments
 (0)