AWS Builder Center
Weekend Agent Challenge: My Courier – An Autonomous AI Email Notification Agent on AWS
#agents

Weekend Agent Challenge: My Courier – An Autonomous AI Email Notification Agent on AWS #agents

An AI agent, fully serverless, event-driven application. Its primary goal is to autonomously monitor a specific Gmail inbox, filter incoming emails based on a strict allowed senders list, use Generative AI to extract and summarize key metadata (priority, deadlines, action items), and notify the user across multiple channels (Slack and WhatsApp) while ensuring zero duplicate notifications

CHALLENGE COMPLETED!

Vision & What the Agent Does
Email remains one of the most important communication channels for developers, students, founders, and professionals. However, many important emails are often buried under newsletters, promotional messages, and notifications, causing users to miss deadlines, interview invitations, hackathon updates, internship offers, and action items.
To solve this problem, I built My Courier, an autonomous, AI-powered serverless email notification agent running on AWS.
Unlike a traditional notification system that simply forwards every email, My Courier intelligently analyzes incoming emails, identifies the email realted to this AWS program(from selective mail id) extracts meaningful information using Generative AI, and delivers concise, actionable summaries through Slack and WhatsApp.
The agent works completely autonomously once configured.
Whenever a new email arrives from an approved sender:
  • Gmail automatically detects the new email.
  • Google Cloud Pub/Sub forwards the event.
  • AWS Lambda processes the email.
  • Amazon Bedrock generates an AI summary.
  • Slack and WhatsApp receive a beautifully formatted notification.
The user never needs to manually refresh Gmail or check their inbox.
The system continuously renews Gmail's Push Watch subscription using Amazon EventBridge, ensuring uninterrupted monitoring without manual intervention.
How I Built It !!
The entire project follows an event-driven serverless architecture that combines Google Cloud Platform with AWS.
Instead of polling Gmail every few seconds—which wastes API quota and compute resources—I used Gmail Push Notifications.
The workflow begins with Gmail's History API.
When Gmail detects a new email, it generates a history event and immediately publishes a notification to a Google Cloud Pub/Sub Topic.
That notification is then delivered through an HTTPS Push Subscription directly into an Amazon API Gateway endpoint.
API Gateway invokes the core Email Agent Lambda.
Inside Lambda:
  • Gmail OAuth tokens are securely retrieved from AWS Secrets Manager.
  • Gmail History API determines exactly which email is new.
  • The complete MIME email is downloaded.
  • The sender is validated against an allow-list.
  • HTML content is cleaned and converted into plain text.
  • Amazon Bedrock summarizes the email.
  • Structured metadata is generated.
  • Duplicate processing is prevented using DynamoDB conditional writes.
  • Notifications are simultaneously delivered to Slack and WhatsApp.
The entire architecture is completely serverless, meaning no EC2 instances or background servers need to remain running.
AWS Services Used / Architecture Overview
My Courier combines multiple AWS services into one event-driven architecture.

Amazon API Gateway

Acts as the public HTTPS webhook endpoint that receives Push Notifications from Google Cloud Pub/Sub and securely invokes the Lambda function.



AWS Lambda

The heart of the application.
Responsible for:
  • Processing Gmail events
  • Downloading emails
  • AI summarization
  • Deduplication
  • Notification delivery



Amazon Bedrock

Used for Generative AI.
The raw email body is sent to an LLM where it extracts:
  • Priority
  • Summary
  • Action Items
  • Deadlines
The output is forced into structured JSON for reliable downstream processing.



Amazon DynamoDB

Stores processed message IDs.
A conditional write ensures that duplicate Pub/Sub deliveries never generate duplicate notifications.
Records automatically expire after 30 days using DynamoDB TTL.



AWS Secrets Manager

Stores:
  • Gmail OAuth Credentials
  • Slack Webhook URL
  • Twilio Credentials
No secrets are hardcoded anywhere in the application.



Amazon EventBridge

A scheduled EventBridge rule automatically runs every day to renew Gmail's Push Watch before it expires.
This allows the system to monitor Gmail indefinitely without user intervention.



Amazon CloudWatch

Provides structured logging for:
  • Gmail events
  • Lambda execution
  • AI responses
  • Errors
  • Notification delivery
CloudWatch Logs Insights can then be used for debugging and monitoring.
End-to-End Workflow:

Phase A – Event Trigger

  1. A new email arrives.
  1. Gmail generates a history event.
  1. Google Cloud Pub/Sub receives the notification.
  1. Pub/Sub sends an HTTPS POST request to API Gateway.



Phase B – Email Processing

Lambda retrieves Gmail OAuth credentials from AWS Secrets Manager.
Using Gmail History API, it identifies the new email without scanning the entire inbox.
The complete MIME message is then downloaded.



Phase C – AI Processing

The email body is cleaned and sent to Amazon Bedrock.
The model extracts:
  • Priority
  • Summary
  • Action Items
  • Deadlines
The response is returned as structured JSON.



Phase D – Deduplication

Before any notification is sent, Lambda attempts a conditional write into DynamoDB.
If the message already exists, processing immediately stops.
This guarantees idempotency.



Phase E – Multi-Channel Notifications

Slack receives a rich Block Kit notification containing:
  • Sender
  • Subject
  • AI-generated summary
  • Priority
  • Deadline
Twilio simultaneously sends an optimized WhatsApp notification for quick mobile viewing.



Phase F – Autonomous Maintenance

Google's Gmail Watch expires approximately every seven days.
Amazon EventBridge automatically invokes a secondary Lambda function on a recurring schedule to renew the Gmail Watch before expiration.
This keeps the agent running continuously without manual maintenance.
Challenges Faced
Building a cross-cloud autonomous system introduced several interesting engineering challenges.

Gmail Push Notifications

Understanding Gmail History IDs, OAuth authentication, Push Watch registration, and Pub/Sub permissions required careful configuration.



Cross-Cloud Communication

Integrating Google Cloud Platform with AWS required secure webhook communication between Pub/Sub and Amazon API Gateway.



Duplicate Notifications

Google Cloud Pub/Sub may retry deliveries.
To avoid duplicate notifications, I implemented DynamoDB conditional writes, ensuring every email is processed exactly once.



Secure Secret Management

Instead of storing credentials inside the source code, all Gmail OAuth credentials, Slack Webhooks, and Twilio credentials are securely stored inside AWS Secrets Manager.



AI Prompt Engineering

Generating structured JSON consistently from an LLM required carefully engineered prompts rather than simple conversational prompts.
What I Learned
This challenge significantly improved my understanding of event-driven cloud-native architectures.
Some of the key learnings include:
  • Designing scalable serverless systems using AWS Lambda.
  • Building secure webhook-based integrations.
  • Working with Gmail Push Notifications instead of inefficient polling.
  • Using Amazon Bedrock within production workflows.
  • Implementing secure secret management using AWS Secrets Manager.
  • Preventing duplicate event processing using DynamoDB conditional writes.
  • Using Amazon EventBridge to automate recurring maintenance tasks.
  • Building resilient distributed systems with retries, structured logging, and fail-safe error handling.
  • Combining Google Cloud Platform and AWS into one seamless workflow.
Most importantly, I learned that autonomous AI agents are far more than conversational chatbots—they continuously monitor real-world events, make intelligent decisions, and take meaningful actions without requiring human intervention.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article