🚨 Send AWS Health Notifications to Slack Using Lambda and EventBridge

Getting alerts when something is wrong with your AWS services is important—especially if you’re running production systems. In this guide, you’ll learn how to automatically send AWS Health notifications to Slack using AWS Lambda and EventBridge.


đź”— Step 1: Create a Slack Webhook

  1. Go to your Slack channel.

  2. Search for "Incoming Webhooks" in the Slack App Directory.

  3. Add it and choose the channel to post messages to.

  4. Copy the Webhook URL (you’ll need this for Lambda).

🖥️ Step 2: Create the Lambda Function

Go to the AWS Lambda console and create a new function. Use Python and paste the following code:

import json
import logging
from urllib.request import Request, urlopen, URLError, HTTPError
logger = logging.getLogger()
logger.setLevel(logging.INFO)
# Replace this with your Slack webhook URL
slack_webhook_url = "https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
def lambda_handler(event, context):
description = event['detail']['eventDescription'][0]['latestDescription']
eventArn = event['detail']['eventArn']
dashboard_url = f"https://phd.aws.amazon.com/phd/home?region=us-east-1#/event-log?eventID={eventArn}"
message = {
"attachments": [
{
"color": "#E01E5A",
"blocks": [
{
"type": "header",
"text": {"type": "plain_text", "text": "🚨 AWS Health Alert", "emoji": True}
},
{
"type": "section",
"text": {"type": "mrkdwn", "text": f"*Description:*\n{description}"}
},
{
"type": "context",
"elements": [
{"type": "mrkdwn", "text": f"đź”— <{dashboard_url}|View in AWS Health Dashboard>"}
]
}
]
}
]
}
req = Request(slack_webhook_url, data=json.dumps(message).encode("utf-8"), headers={"Content-Type": "application/json"})
try:
urlopen(req)
logger.info("Notification sent to Slack")
except HTTPError as e:
logger.error("HTTPError: %d %s", e.code, e.reason)
except URLError as e:
logger.error("URLError: %s", e.reason)

🎯 Step 3: Create an EventBridge Rule

  1. Go to Amazon EventBridge.

  2. Create a new rule.

  3. Choose Event Source: AWS services.

  4. Pick AWS Health.

  5. For event pattern, use:



OutPut: 



Comments

Popular posts from this blog

Introduction to Istio, Kiali, Jaeger, Grafana, and Prometheus

Docker Image Vulnerabilities and Scanner Guide: A Quick Overview

Remote Friendly Companies