-
Notifications
You must be signed in to change notification settings - Fork 1k
New serverless pattern - eventbridge-scheduler-ai-agent-trigger #2992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ras-al-jil
wants to merge
1
commit into
aws-samples:main
Choose a base branch
from
ras-al-jil:ras-al-jil-feature-eventbridge-scheduler-ai-agent-trigger
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,89 @@ | ||||||
| # Amazon EventBridge Scheduler to Amazon Bedrock AI Agent | ||||||
|
|
||||||
| This pattern demonstrates how to trigger an Amazon Bedrock AI Agent on a recurring schedule using Amazon EventBridge Scheduler. An orchestrator Lambda function, invoked by the scheduler, sends a task payload to the Bedrock Agent, which processes the input, generates an execution summary, and persists the result to a DynamoDB table via an action group Lambda. | ||||||
|
|
||||||
| Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/eventbridge-scheduler-ai-agent-trigger | ||||||
|
|
||||||
| 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. | ||||||
|
|
||||||
| ## Requirements | ||||||
|
|
||||||
| * [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. | ||||||
| * [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured | ||||||
| * [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) | ||||||
| * [Terraform](https://www.terraform.io/downloads.html) >= 1.0 installed | ||||||
|
|
||||||
| ## Architecture | ||||||
|
|
||||||
|  | ||||||
|
|
||||||
| The pattern deploys the following resources: | ||||||
|
|
||||||
| 1. **Amazon EventBridge Scheduler** – Triggers the orchestrator Lambda on a recurring schedule (default: `rate(1 hour)`). | ||||||
| 2. **Orchestrator Lambda** (Python 3.14) – Receives the scheduler event and invokes the Bedrock Agent with a task payload. | ||||||
| 3. **Amazon Bedrock Agent** – Processes the task payload, generates an execution summary using a foundation model (default: Claude 3 Haiku), and calls the action group. | ||||||
| 4. **Action Group Lambda** (Python 3.14) – Persists execution records to DynamoDB. | ||||||
| 5. **Amazon DynamoDB Table** – Stores task execution records. | ||||||
| 6. **Amazon SQS Dead-Letter Queue** – Captures failed scheduler invocations after retries are exhausted. | ||||||
|
|
||||||
| ## Deployment Instructions | ||||||
|
|
||||||
| 1. Clone the repository: | ||||||
| ``` | ||||||
| git clone https://github.com/aws-samples/serverless-patterns | ||||||
| ``` | ||||||
| 1. Change directory to the pattern directory: | ||||||
| ``` | ||||||
| cd serverless-patterns/eventbridge-scheduler-ai-agent-trigger | ||||||
| ``` | ||||||
| 1. Initialize Terraform: | ||||||
| ``` | ||||||
| terraform init | ||||||
| ``` | ||||||
| 1. Deploy the infrastructure: | ||||||
| ``` | ||||||
| terraform apply -auto-approve | ||||||
| ``` | ||||||
| During the prompts, provide values for: | ||||||
| * `aws_region` – AWS region (e.g. `us-east-1`) | ||||||
| * `prefix` – Unique prefix for all resource names | ||||||
|
|
||||||
| 1. Note the outputs from the deployment. These contain the resource names and ARNs used for testing. | ||||||
|
|
||||||
| ## How it works | ||||||
|
|
||||||
| 1. EventBridge Scheduler fires on the configured schedule and invokes the orchestrator Lambda with a JSON payload containing `taskType`, `scheduleName`, and `scheduledTime`. | ||||||
| 2. The orchestrator Lambda calls `bedrock-agent-runtime:InvokeAgent` with the payload, targeting the agent alias. | ||||||
| 3. The Bedrock Agent parses the payload, generates an executive summary using the foundation model, and calls the `recordTaskExecution` action group. | ||||||
| 4. The action group Lambda writes the execution record (task ID, type, scheduled time, summary, and recorded timestamp) to the DynamoDB table. | ||||||
| 5. If the scheduler invocation fails after 3 retries, the event is sent to the SQS dead-letter queue. | ||||||
|
|
||||||
| ## Testing | ||||||
|
|
||||||
| 1. Invoke the orchestrator Lambda manually: | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| ``` | ||||||
| aws lambda invoke \ | ||||||
| --function-name <prefix>-agent-orchestrator \ | ||||||
| --payload '{"taskType":"scheduled-report","scheduleName":"manual-test","scheduledTime":"2026-03-13T10:00:00Z"}' \ | ||||||
| --cli-binary-format raw-in-base64-out \ | ||||||
| output.json | ||||||
| ``` | ||||||
| 2. Check the DynamoDB table for the new execution record: | ||||||
| ``` | ||||||
| aws dynamodb scan --table-name <prefix>-agent-task-executions | ||||||
| ``` | ||||||
|
|
||||||
| ## Cleanup | ||||||
|
|
||||||
| 1. Destroy the stack: | ||||||
| ``` | ||||||
| terraform destroy -auto-approve | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| ``` | ||||||
| 1. Confirm all resources have been removed: | ||||||
| ``` | ||||||
| terraform show | ||||||
| ``` | ||||||
| ---- | ||||||
| Copyright 2026 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||||||
|
|
||||||
| SPDX-License-Identifier: MIT-0 | ||||||
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| { | ||
| "openapi": "3.0.0", | ||
| "info": { | ||
| "title": "Scheduled Task Execution API", | ||
| "version": "1.0.0", | ||
| "description": "Actions for recording and retrieving scheduled AI agent task executions" | ||
| }, | ||
| "paths": { | ||
| "/record-task-execution": { | ||
| "post": { | ||
| "operationId": "recordTaskExecution", | ||
| "summary": "Record a scheduled task execution in the tracking database", | ||
| "description": "Persists a task execution record with task ID, type, timestamp, and an AI-generated summary to DynamoDB", | ||
| "requestBody": { | ||
| "required": true, | ||
| "content": { | ||
| "application/json": { | ||
| "schema": { | ||
| "type": "object", | ||
| "required": [ | ||
| "taskId", | ||
| "taskType", | ||
| "scheduledTime", | ||
| "executionSummary" | ||
| ], | ||
| "properties": { | ||
| "taskId": { | ||
| "type": "string", | ||
| "description": "Unique identifier for this task execution — combine scheduleName and scheduledTime" | ||
| }, | ||
| "taskType": { | ||
| "type": "string", | ||
| "description": "The category of the scheduled task (e.g. scheduled-report)" | ||
| }, | ||
| "scheduledTime": { | ||
| "type": "string", | ||
| "description": "ISO 8601 UTC timestamp when the task was scheduled to run" | ||
| }, | ||
| "executionSummary": { | ||
| "type": "string", | ||
| "description": "AI-generated summary describing the task execution and its outcome" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "responses": { | ||
| "200": { | ||
| "description": "Execution recorded successfully", | ||
| "content": { | ||
| "application/json": { | ||
| "schema": { | ||
| "type": "object", | ||
| "properties": { | ||
| "message": { "type": "string" }, | ||
| "taskId": { "type": "string" }, | ||
| "recordedAt": { "type": "string" } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "/get-last-execution": { | ||
| "get": { | ||
| "operationId": "getLastExecution", | ||
| "summary": "Get the most recent task execution for a given task type", | ||
| "description": "Retrieves the latest execution record from DynamoDB filtered by task type", | ||
| "parameters": [ | ||
| { | ||
| "name": "taskType", | ||
| "in": "query", | ||
| "required": true, | ||
| "schema": { "type": "string" }, | ||
| "description": "Task type to look up (e.g. scheduled-report)" | ||
| } | ||
| ], | ||
| "responses": { | ||
| "200": { | ||
| "description": "Last execution found", | ||
| "content": { | ||
| "application/json": { | ||
| "schema": { | ||
| "type": "object", | ||
| "properties": { | ||
| "taskId": { "type": "string" }, | ||
| "taskType": { "type": "string" }, | ||
| "scheduledTime": { "type": "string" }, | ||
| "executionSummary": { "type": "string" }, | ||
| "recordedAt": { "type": "string" } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "404": { | ||
| "description": "No executions found for the given task type" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
58 changes: 58 additions & 0 deletions
58
eventbridge-scheduler-ai-agent-trigger/example-pattern.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| { | ||
| "title": "Trigger AI Agent with Amazon EventBridge Scheduler", | ||
| "description": "Create a EventBridge scheduler which invokes a Bedrock Agent upon triggering.", | ||
| "language": "Python", | ||
| "level": "300", | ||
| "framework": "Terraform", | ||
| "introBox": { | ||
| "headline": "How it works", | ||
| "text": [ | ||
| "This pattern demonstrates how to trigger an Amazon Bedrock AI Agent on a recurring schedule using Amazon EventBridge Scheduler. An orchestrator AWS Lambda function, invoked by the scheduler, sends a task payload to the Bedrock Agent, which processes the input, generates an execution summary, and persists the result to a DynamoDB table via an action group Lambda. The pattern includes retry logic, a dead-letter queue for failed invocations, and least-privilege IAM policies scoped to the agent alias ARN." | ||
| ] | ||
| }, | ||
| "gitHub": { | ||
| "template": { | ||
| "repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/eventbridge-scheduler-ai-agent-trigger", | ||
| "templateURL": "serverless-patterns/eventbridge-scheduler-ai-agent-trigger", | ||
| "projectFolder": "eventbridge-scheduler-ai-agent-trigger", | ||
| "templateFile": "main.tf" | ||
| } | ||
| }, | ||
| "resources": { | ||
| "bullets": [ | ||
| { | ||
| "text": "Invoke a Lambda function on a schedule", | ||
| "link": "https://docs.aws.amazon.com/lambda/latest/dg/with-eventbridge-scheduler.html" | ||
| }, | ||
| { | ||
| "text": "Allow users to view information about and invoke an agent", | ||
| "link": "https://docs.aws.amazon.com/bedrock/latest/userguide/security_iam_id-based-policy-examples-agent.html#security_iam_id-based-policy-examples-perform-actions-agent" | ||
| } | ||
| ] | ||
| }, | ||
| "deploy": { | ||
| "text": [ | ||
| "terraform init", | ||
| "terraform apply" | ||
| ] | ||
| }, | ||
| "testing": { | ||
| "text": [ | ||
| "See the GitHub repo for detailed testing instructions." | ||
| ] | ||
| }, | ||
| "cleanup": { | ||
| "text": [ | ||
| "terraform destroy", | ||
| "terraform show" | ||
| ] | ||
| }, | ||
| "authors": [ | ||
| { | ||
| "name": "Rajil Paloth", | ||
| "image": "https://i.ibb.co/r2TsqGf6/Passport-size.jpg", | ||
| "bio": "ProServe Delivery Consultant at AWS", | ||
| "linkedin": "paloth" | ||
| } | ||
| ] | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.