Script icon
Docker icon
If icon
SlackIncomingWebhook icon
Log icon
Return icon
Schedule icon

AWS API Gateway Endpoint Latency and 5XX Spike Sentinel

Audits AWS API Gateway stages to detect 5XX server error surges and p99 integration latency breaches, dispatching diagnostic incident alerts to DevOps teams.

Categories
CloudInfrastructure

Modern cloud architectures rely on AWS API Gateway to route client traffic to Lambda functions, ECS microservices, and VPC internal backends. When downstream services encounter memory pressure, database connection pool exhaustion, or unhandled exceptions, API Gateway responds with HTTP 5XX status codes and surging integration latencies. If undetected, client applications fail silently and service-level objectives (SLOs) degrade. This sentinel interrogates AWS API Gateway and CloudWatch metrics on a scheduled interval, detects 5XX error rate anomalies and p99 latency breaches, and notifies incident engineering teams on Slack with actionable diagnostic commands.

How it works

  1. Scheduled triggering: Executes every 15 minutes via automated cron trigger (*/15 * * * *) or runs on-demand via manual API triggers.
  2. Resource enumeration: Queries the AWS API Gateway REST API (get_rest_apis) to discover all active regional APIs matching the configured name filter.
  3. CloudWatch telemetry analysis: Fetches CloudWatch MetricData queries for Count, 5XXError, and IntegrationLatency across a 15-minute rolling window.
  4. Threshold evaluation: Computes the percentage of 5XX responses relative to total requests and compares p99 integration latency against operational SLAs.
  5. Conditional branching: An io.kestra.plugin.core.flow.If task evaluates whether any API stage exceeds the error rate or latency threshold.
  6. Slack incident dispatch: Emits a priority incident payload to the #devops-incidents channel with API identifiers, request counts, and CLI diagnosis commands.
  7. Audit trail logging and return: Logs operational telemetry and outputs a structured compliance manifest for long-term audit tracking.

Architecture diagram

flowchart TD
  A[scheduled_apigateway_audit Schedule Trigger] --> B[scan_apigateway_telemetry Python Script]
  B --> C[check_degraded_api_routes Flowable If]
  C -- Degraded APIs Detected --> D[notify_slack_api_incident Webhook]
  C -- All APIs Healthy --> E[log_telemetry_status Log]
  D --> E
  E --> F[export_audit_manifest Return]

Use cases

  • Microservice dependency degradation: Detect failing downstream Lambda or container backends before cascading HTTP 504 timeouts impact mobile and web clients.
  • SLA and SLO compliance tracking: Continuously monitor API integration latencies to ensure p99 thresholds remain within contractual client SLAs.
  • Automated incident escalation: Provide on-call site reliability engineers with immediate visibility into affected API Gateway stages and error frequencies.

Inputs

Name Type Default Description
aws_region STRING us-east-1 Target AWS region where API Gateway instances and CloudWatch metrics reside.
api_name_filter STRING all Name or prefix of target API Gateway APIs to audit, or all to scan all regional APIs.
error_5xx_rate_threshold_percent FLOAT 2.0 Percentage threshold of 5XX responses relative to total requests that triggers incident alerting.
p99_latency_threshold_ms INT 1500 Maximum allowable p99 integration latency in milliseconds before flagging degraded performance.
alert_on_degraded BOOL true Whether to dispatch automated Slack incident notifications when threshold breaches are detected.

Expected outputs

  • {{ outputs.scan_apigateway_telemetry.vars.total_apis_audited }}: Total number of API Gateway APIs evaluated during the execution.
  • {{ outputs.scan_apigateway_telemetry.vars.degraded_apis_count }}: Number of API stages exceeding error rate or latency thresholds.
  • {{ outputs.scan_apigateway_telemetry.vars.degraded_apis_details }}: JSON string listing degraded APIs with exact error rates and latency percentiles.
  • {{ outputs.export_audit_manifest.value }}: Structured dictionary containing the consolidated audit summary.

Prerequisites

  • Outbound HTTPS network access from Kestra execution workers to AWS STS, API Gateway, and CloudWatch endpoints.
  • AWS IAM credentials configured with apigateway:GET and cloudwatch:GetMetricData permissions.
  • Slack incoming webhook endpoint configured for operational incident alerting.

Secrets

  • AWS_ACCESS_KEY_ID: AWS IAM access key with permissions to read API Gateway and CloudWatch metrics.
  • AWS_SECRET_ACCESS_KEY: AWS IAM secret key corresponding to the access key.
  • SLACK_WEBHOOK_URL: Slack Incoming Webhook URL used to dispatch incident notifications.

Quick start

  1. Configure AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and SLACK_WEBHOOK_URL in your Kestra secret storage.
  2. Import this blueprint into your Kestra instance under the company.cloud namespace.
  3. Configure aws_region and api_name_filter to target your production API stages.
  4. Run a manual execution to verify CloudWatch metric discovery and confirm notification delivery.

Common pitfalls and troubleshooting

  • CloudWatch metric delay: CloudWatch metrics for API Gateway can experience 1 to 2 minutes of ingestion delay; ensure evaluation windows cover at least 15 minutes.
  • Detailed metrics enabled: By default, API Gateway provides stage-level metrics; ensure detailed CloudWatch metrics are enabled if method-level granularity is required.
  • IAM permission boundaries: Ensure the IAM role has cloudwatch:GetMetricData across AWS/ApiGateway namespaces; missing permissions yield empty metric arrays.

How to extend

  • Automated canary rollback: Trigger an automated AWS CodeDeploy or API Gateway canary traffic shift rollback when 5XX rates exceed 5%.
  • PagerDuty on-call escalation: Route critical API Gateway degradations directly to the on-call platform engineer via PagerDuty webhook.
  • Distributed trace linking: Attach AWS X-Ray trace search URLs to the Slack incident card to allow instant root-cause inspection.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.