
Table of Contents
Need Help? Get in Touch!
1. Introduction
Weather alerts are time-sensitive and can impact team operations and safety. To ensure immediate awareness, we built an automated Slack bot that fetches severe weather alerts from the National Weather Service (NWS) and posts them to a designated Slack channel. The solution uses Python, Docker, AWS Lambda, and other AWS services to deliver alerts in near real-time with zero manual intervention.
This system follows a typical ETL (Extract, Transform, Load) pattern:
-
Extract: Alerts are pulled from the NWS public API.
-
Transform: The alert data is filtered and formatted.
-
Load: The final message is delivered to a Slack channel.
The following architecture diagram provides a high-level overview of the workflow:
2. Architecture Overview
The system architecture consists of the following flow:
-
NWS API provides weather alerts in JSON format.
-
Python Bot processes and filters alerts based on severity.
-
Docker packages the bot for consistent deployment across local and cloud environments.
-
Amazon ECR (Elastic Container Registry) stores the container image used by Lambda.
-
AWS Lambda runs the Docker container serverlessly.
-
Amazon S3 stores the last known alert state to avoid duplicate postings.
-
Amazon EventBridge triggers Lambda execution every hour from 7 AM to 9 PM based on a cron schedule.
-
Slack Bot sends formatted alert messages to a Slack channel using Slack's Web API.
3. Alert Filtering Logic
The bot only processes alerts that meet all of the following conditions:
-
Severity: Severe, Moderate, or Extreme
-
Urgency: Immediate, Expected, or Future
-
Certainty: Likely, Possible, or Observed
-
Not Expired: Checks the expires timestamp
To prevent duplicate messages, it compares the incoming alert's sent timestamp to a previously stored state in S3 (current_alert.json).
4. Codebase Deep Dive
4.1 slack_weather.py
This is the main script responsible for orchestrating the entire alert detection and delivery process. It performs the following critical functions:
-
Configuration Loading: Reads Slack credentials, time window limits, and S3 parameters from ### 4.2 config.json.
-
Logging Setup: Initializes structured logging with timestamps.
-
Client Initialization: Sets up boto3 (AWS SDK) for S3 interaction and Slack WebClient for messaging.
-
Datetime Utilities: Includes functions to format ISO timestamps and determine allowed alert windows (Eastern Time).
-
Slack Message Building: Formats incoming alert data into readable, emoji-enhanced Slack messages, respecting Slack's character limits.
-
NWS Alert Fetching: Retrieves weather alerts from the public NWS API using geographic coordinates or region codes.
-
Alert Filtering: Applies severity, urgency, certainty, and expiry rules to identify actionable alerts.
-
S3 State Management: Loads prior alert state from S3, identifies new alerts, updates state post-processing.
-
Slack Posting: Posts new alerts to the configured Slack channel (#weather-alerts) using the Slack API.
-
Lambda Compatibility: Exposes a lambda_handler for cloud execution and a __main__ block for local testing.
The script uses helper functions such as get_event_icon() for icon selection, parse_and_format_description() for rich text rendering, and filter_out_expired_alerts() to ensure stale data is ignored. The logic is designed to be idempotent and efficient, processing multiple locations with retry logic and a safe state update back to S3.
Example: Posting a New Alert to SlackExample: Filtering Expired Alerts
These patterns ensure robust behavior across varying alert formats and conditions.
4.2 config.json
Stores configuration values such as the Slack bot token, alert time window, and S3 storage parameters.
4.3 run_slack_bot.sh
A bash wrapper script triggers the Python bot and logs execution, useful for both local and Docker container runs
4.4 requirements.txt
Defines Python Package Dependencies needed for the bot: slack_sdk for Slack integration and requests for HTTP API Calls
4.5 Dockerfile
Builds the project container using the AWS Lambda Python 3.12 image base. It installs dependencies and prepares the bot for serverless execution
4.6 openapi(weather).json
An optional OpenAI schema definition file that helps validate or understand the structure of weather alert data coming from the NWS.
5. Detailed Setup & Local Testing
Prerequisites
-
Docker: Required for building and testing the bot container locally.
-
Slack App: A bot app installed in your Slack workspace with proper OAuth scopes.
-
AWS Credentials: Stored in ~/.aws/credentials, used for accessing S3 and deploying Lambda.
-
GitHub: Tool for cloning the source repository
Local Test Setup
1) Clone the Repository:2) Create config.json
Stores configuration values such as the Slack bot token, alert time window, and S3 storage parameters.
3) Run via VS Code:This command triggers the bot, checks NWS, compares state from S3, and posts to Slack.
6. Dockerization
Docker enables portable packaging and reproducibility across cloud environments. The Dockerfile builds a Lambda-compatible image with all necessary dependencies.
This container is pushed to:
-
ECR Repository: slack_weather_bot_rk
-
Image Digest: sha256:61e66b235a885417c7b543621d64044eee11e387c247cdc0b3c471a28bf894ca
7. AWS Cloud Setup
7.1 Amazon ECR
A fully managed Docker container registry used to store the image built from the weather bot project.
7.2 AWS Lambda
A serverless compute service that pulls the Docker image from ECR and runs the bot in an isolated runtime.
7.3 Amazon S3
Simple Storage Service used to persist the state file current_alert.json which tracks the latest processed alert.
7.4 Amazon EventBridge
A scheduler service that triggers the Lambda function based on a cron expression:This ensures the bot runs hourly from 7 AM to 9 PM EST local time.
8. Slack Integration
The bot uses Slack's Web API via the slack_sdk Python package to send messages to a specific channel. Messages are posted only if a new, qualifying alert is detected.
-
Channel: #weather-alerts
-
Visibility: Anyone in the firm can subscribe to this channel to receive updates.
-
Bot Behavior: The bot runs hourly, checks for changes, and posts the alert if it's new.
Example: Slack Weather Alert
9. AWS Backend & Security Services
10. Conclusion & Impact
This weather alert system exemplifies a modern, scalable solution for real-time communication of high-impact information. By leveraging a lightweight, serverless, and containerized architecture, it eliminates the need for manual monitoring while ensuring that critical weather alerts are promptly shared with relevant stakeholders.
Built entirely using open-source tools and AWS cloud services, the bot delivers alerts to the dedicated Slack channel #weather-alerts, where any employee can subscribe and stay informed. The filtering logic ensures that only meaningful and non-expired alerts are surfaced, while the S3-backed alert state tracking prevents duplicate messages and supports a clean, idempotent workflow.
In practice, this system helps teams make quicker, safer decisions, whether that means avoiding commute disruptions, protecting physical infrastructure, or escalating emergency preparedness protocols. The hourly cadence ensures no critical events are missed during working hours, and the design is extensible to support additional channels, custom alert types, or geolocation groups in the future.
Furthermore, this project demonstrates the real-world value of event-driven architectures combined with collaborative platforms, streamlining awareness and readiness across an organization.
Contact Red Oak Strategic
From cloud migrations to machine learning & AI - maximize your data and analytics capabilities with support from an AWS Advanced Tier consulting partner.
Related Posts
Business Intelligence

Tyler Sanders
Ready to get started?
Kickstart your cloud and data transformation journey with a complimentary conversation with the Red Oak team.