Skip to content

CloudWatch & SNS Integration for Real-Time Error Alerts in Dev and Prod Environments #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

git-user-9
Copy link
Owner

@git-user-9 git-user-9 commented Jul 24, 2025

This pull request implements centralized logging, monitoring, and alerting for EC2-based deployments using AWS CloudWatch and SNS, fulfilling the requirements of Assignment 5.


CloudWatch Logs and Metrics

  • Application logs are collected and pushed to CloudWatch under stage-specific log groups such as:

    /aws/ec2/dev-app-logs
    /aws/ec2/prod-app-logs
    
  • A CloudWatch Log Metric Filter tracks error-level log entries:

    Filter Pattern: "Error"
    Filter Pattern: "Exception"
    
  • Corresponding CloudWatch Alarms are configured to trigger based on the above metric.


🔔 SNS-Based Alerting

  • An SNS Topic is created to dispatch notifications when alarms are triggered.
  • An email subscription is attached, which receives alerts for error logs.
  • Email endpoint is passed via Terraform variable and stored securely.

☁️ Free Tier Optimization

  • The solution uses:

    • Only 1 log group per environment.
    • 2 alarm, within the AWS Free Tier limit of 3 CloudWatch alarms per month.
  • Log data is kept minimal (few KBs) and uses short retention to avoid costs.


📥 Example Outputs and Alerts

Below is a screenshot of the email alert received via SNS when an Error log is detected:
image

Below is screenshot of AWS CloudWatch alarms
SCR-20250725-edzs

CloudWatch log groups showing stage-specific separation:

dev log group:
image

prod log group:

image

Below is AWS SNS topic:
image


🔍 Validation

  • Verified that a test echo "Error" or `echo "Exception"' in EC2 logs correctly triggers the alarm and sends the email.
  • CloudWatch insights confirm metric filter accuracy.

This feature/assignment [devops/a5] continues from [devops/a4] and has been raised on [main] to maintain a clear history of each assignment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant