You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何检测AWS EC2上Web服务器宕机并配置SNS告警通知

Hey there! Let's walk through how to set up detection for your EC2-hosted web server downtime and get alerts via SNS. Here's a reliable AWS-native solution that covers both needs:

1. Detect Web Server Downtime

We need to cover two layers of checks—the underlying EC2 instance health and the web application's availability—to make sure we don't miss any downtime scenarios:

1.1 Application-Level Availability Check (Critical)

Use CloudWatch Synthetics Canaries to simulate real user requests to your web server:

  • Head to the AWS Console, navigate to CloudWatch > Synthetics > Canaries
  • Create a new Canary, pick a template that matches your setup (e.g., "Browser canary" for a web page, "API canary" for a backend endpoint)
  • Configure your web server's public URL (like http://your-ec2-public-ip:80 or your custom domain) and set a check frequency (start with every 5 minutes, adjust based on your needs)
  • The Canary will regularly send requests and validate responses (e.g., checking for a 200 OK status code, response time limits). If requests fail or time out, it'll flag the downtime.

1.2 EC2 Instance Health Check

Pair this with EC2's built-in status checks to catch cases where the instance itself goes down:

  • In CloudWatch, create an alarm monitoring the EC2 StatusCheckFailed metric
  • Set the threshold to trigger when the metric equals 1 (this means either the system or instance status check has failed)
2. Set Up SNS Alerts for Downtime

Once we have detection in place, let's route those alerts to you via SNS:

2.1 Create an SNS Topic

  • Go to the SNS Console > Topics > Create topic
  • Choose a Standard topic (ideal for alerting), name it something like WebServer-Downtime-Alerts
  • Add a subscription: Pick your preferred protocol (Email, SMS, etc.), enter your contact details, and confirm the subscription (you'll get a verification link/code for email/SMS)

For CloudWatch Synthetics Canary Alarms

  • From your Canary page in CloudWatch, click "Create alarm"
  • Select the SuccessPercent metric, set the threshold to "Less than 100%" (triggers when any request fails)
  • Under "Alarm actions", choose "Send notification to an SNS topic" and select your newly created topic
  • Add a clear alarm name and description, then save

For EC2 Status Check Alarms

  • In CloudWatch > Alarms > Create alarm
  • Select the EC2 StatusCheckFailed metric, set the threshold to "Equals 1"
  • Repeat the alarm action setup to link it to your SNS topic

2.3 Bonus: Customize Alert Content

You can tweak the alarm notification to include details like the EC2 instance ID, downtime start time, and which check failed—this helps you diagnose issues faster without jumping into the console.

Quick Tips to Avoid Headaches

  • Test the flow: Manually stop your web server or EC2 instance to confirm you get the SNS alert
  • Reduce false positives: Set the alarm to trigger only after 2 consecutive failures (adjust in the alarm's "Additional configuration" section)
  • Expand notification channels: Use SNS with Lambda to send alerts to Slack, Microsoft Teams, or even trigger auto-recovery actions for your EC2 instance

内容的提问来源于stack exchange,提问作者Nouman Altaf

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:56:08