Serverless Reminders Application using direct integration of Amazon EventBridge Scheduler with Amazon SES
This pattern deploys a serverless reminder application comprising Amazon API Gateway, DynamoDB Streams, Lambda Function, Amazon Event Bridge Scheduler and Amazon SES services.
Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/apigw-dynamodb-lambda-scheduler-ses-auto-deletion-sam
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 for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.
- Create an AWS account 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.
- AWS CLI installed and configured
- Git Installed
- AWS Serverless Application Model (AWS SAM) installed
-
Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:
git clone https://github.com/aws-samples/serverless-patterns
-
Change directory to the pattern directory:
cd apigw-dynamodb-lambda-scheduler-ses-auto-deletion-sam
-
From the command line, use AWS SAM to deploy the AWS resources for the pattern as specified in the template.yml file:
sam deploy --guided
-
During the prompts:
- Enter a stack name
- Enter the desired AWS Region
- Specify value for SenderEmailAddress. The email address should be verified identity from Amazon SES.
- Allow SAM CLI to create IAM roles with the required permissions.
Once you have run
sam deploy --guided
mode once and saved arguments to a configuration file (samconfig.toml), you can usesam deploy
in future to use these defaults. -
Note the outputs from the SAM deployment process. These contain the resource names and/or ARNs which are used for testing.
- When a user creates/updates/deletes a reminder using REST API Gateway endpoint, the data is updated in DynamoDB Table.
- Scheduler Lambda function is triggered in response to event in DynamoDB table and then creates/updates/deletes one-time schedules using Amazon EventBridge Scheduler.
- Email reminders are sent to the specified email address before 10 minutes and at the scheduled time.
- Amazon EventBridge Scheduler is directly integrated with Amazon SES using Universal Targets.
- All schedules are removed once they run (auto deletion).
Once the application is deployed, use Postman to test the API using the following instructions.
-
Copy the API Gateway Stage Invoke URL from the SAM deployment output
-
In order to create a new reminder, specify the below values.
- HTTP Method: POST
- Endpoint: https://{ApiId}.execute-api.{Region}.amazonaws.com/v1/reminders
- Request Body (JSON)
{ "description": "Order Food", "datetime": "2023-11-10T05:40:00Z", "email": "youremail@verifieddomain.com" }
- Kindly note that all the three parameters are required and datetime parameter is of the format YYYY-MM-DDTHH:MM:SSZ in UTC. Email must be valid.
- The API response includes the unique id of the reminder and other attributes.
- One-time Event Bridge Schedules are created and auto-deleted upon event completion.
-
In order to update a reminder, specify the below values.
- HTTP Method: PUT
- Endpoint: https://{ApiId}.execute-api.{Region}.amazonaws.com/v1/reminders/{reminderid}
- Request Body (JSON)
{ "description": "Order Food", "datetime": "2023-11-10T05:40:00Z", "email": "youremail@verifieddomain.com" }
- Kindly note that all the three parameters are required and datetime parameter is of the format YYYY-MM-DDTHH:MM:SSZ in UTC.
- Existing One-time Event Bridge Schedules are updated and auto-deleted upon event completion.
-
In order to delete a specific reminder, specify the below values.
- HTTP Method: DELETE
- Endpoint: https://{ApiId}.execute-api.{Region}.amazonaws.com/v1/reminders/{reminderid}
- The records are deleted from DynamoDB and the corresponding One-time Event Bridge Schedules are deleted.
-
In order to list all reminders, specify the below values.
- HTTP Method: GET
- Endpoint: https://{ApiId}.execute-api.{Region}.amazonaws.com/v1/reminders
- The API response lists the active and expired reminders.
- Delete the stack
sam delete
Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: MIT-0