Database
November 9, 2026
2 views
2 min read

Automated blocking and query alerts for Amazon RDS for SQL Server

Curated by Patrick
Source: AWS Database Blog
Automated blocking and query alerts for Amazon RDS for SQL Server
Tech Daily Byte Analysis

The blog post walks readers through a DIY alerting pipeline for Amazon RDS for SQL Server. Because the managed service does not emit blocking or long‑running‑query metrics to CloudWatch, the authors create a Python‑3.12 Lambda that runs every minute via EventBridge, connects to the RDS instance with the lightweight pytds driver, and queries sys.dm_exec_requests, sys.dm_exec_sessions and related DMVs. A recursive common table expression walks the blocking_session_id chain to surface the root blocker, while filters on is_user_process and known system commands keep noise down. When the Lambda spots a session blocked longer than the 60‑second poll interval or a user query exceeding 300 seconds, it pushes a custom metric to CloudWatch and fires an HTML email through Amazon SES containing session IDs, host names, and the offending SQL text. The guide also stresses security: a dedicated “rds_monitor” login with only VIEW SERVER STATE and VIEW ANY DEFINITION rights stores its credentials in Secrets Manager, avoiding the use of the master account.

This approach reflects a broader AWS pattern of augmenting native service gaps with serverless glue. RDS for SQL Server historically lags behind its Azure counterpart, which offers built‑in Query Store insights and automatic alerting. By leveraging EventBridge‑driven Lambdas, AWS enables customers to replicate similar visibility without purchasing third‑party APM tools that often carry per‑core licensing fees. The solution also showcases the growing preference for “infrastructure‑as‑code” monitoring stacks that combine managed services (Secrets Manager, SES) with minimal custom code, aligning with the industry’s shift toward cost‑effective, observable cloud databases.

Looking ahead, the reliance on a one‑minute Lambda schedule introduces a trade‑off between detection latency and Lambda invocations; workloads with sub‑minute blocking could still slip through. Maintaining the pytds package and the SQL queries adds operational debt, especially as new SQL Server versions or RDS engine updates arrive. Organizations should monitor AWS announcements for native CloudWatch metric extensions for RDS SQL Server, which could render the custom Lambda redundant. In the meantime, teams must secure SES sending limits, guard against email fatigue, and ensure the monitoring user’s permissions stay tightly scoped to prevent privilege creep.

Key Takeaways

The solution fills a native‑monitoring void in RDS for SQL Server by exporting blocking and long‑running‑query data to CloudWatch via a minute‑interval Lambda.

Using a least‑privilege “rds_monitor” login with VIEW SERVER STATE and VIEW ANY DEFINITION limits exposure while still accessing required DMVs.

The architecture leverages only AWS‑managed services, avoiding extra licensing costs of traditional database performance tools.

Future AWS enhancements to RDS SQL Server observability could supersede the custom Lambda, so teams should track related service updates.

About the Source

This analysis is based on reporting by AWS Database Blog. Here is a short excerpt for context:

Learn how to build automated email alerts for blocking chains and long-running queries on Amazon RDS for SQL Server. This serverless solution uses AWS Lambda, Amazon CloudWatch, and Amazon SES to detect blocking, identify the root blocker, and send HTML email alerts for approximately $2.57 per month.
Read the original at AWS Database Blog

More in Database