Cloudwatch Monitoring
muhirwaJD

muhirwaJD @muhirwajd

About: Hello Chat

Joined:
May 28, 2025

Cloudwatch Monitoring

Publish Date: Jul 2 '25
-1 0

🛠️ Node.js Logging to CloudWatch from Dockerized EC2 App

🧩 Project Overview

In this project, I built a lightweight Node.js web server using Morgan middleware to log HTTP requests. I deployed it on an EC2 instance, containerized the app with Docker, and then configured AWS CloudWatch to stream logs both from a file (for traditional deployment) and directly from Docker (for container-based monitoring).

This dual setup gave me deep visibility into application traffic using two popular logging strategies—and helped me better understand how to monitor apps in cloud-native environments.


🚀 What I Built

  • ✅ A Node.js app with HTTP request logging using Morgan
  • ✅ Dockerized version of the app using a custom Dockerfile
  • ✅ Deployed on an Ubuntu EC2 instance
  • ✅ Implemented two types of logging to CloudWatch:
    • File-based logging with CloudWatch Agent (for non-containerized apps)
    • Docker log driver for real-time streaming (for containerized apps)

💡 Why This Matters

Logging is critical for:

  • 📈 Monitoring traffic and diagnosing issues
  • 🔒 Ensuring app health and security
  • 🔍 Auditing activity for compliance or troubleshooting

This project taught me:

  • How to configure IAM roles securely for EC2 and CloudWatch
  • How to write logs to both file and console for hybrid observability
  • How to use Docker's native log drivers to stream data to AWS CloudWatch
  • The differences and use cases between classic agent-based logging vs container-native logging

🧠 Key Learnings

  • Docker logs can be streamed directly to CloudWatch without writing to disk
  • Morgan allows dual streaming (file + console), which is perfect for hybrid setups
  • CloudWatch Agent requires precise file paths and log group names to function
  • IAM roles must be attached to EC2 instances with the correct policies (CloudWatchAgentServerPolicy, AmazonSSMManagedInstanceCore)
  • Real-time log monitoring helps identify traffic patterns and potential issues instantly

🛠️ Tech Stack

  • Node.js
  • Express / Morgan middleware
  • Docker
  • AWS EC2 (Ubuntu)
  • AWS CloudWatch Logs
  • AWS IAM Roles
  • CloudWatch Agent

🔍 How to Try It Yourself

  1. Clone the Node.js app with Morgan logging
  2. Build the Docker image and run it
  3. Either:
    • Use CloudWatch Agent to stream from a file, or
    • Use Docker's awslogs driver for direct streaming
  4. Monitor traffic logs in CloudWatch in real time!

📸 Screenshots

  • Terminal output

Logs sent to terminal

  • CloudWatch Log Group + Stream

Logs sent to cloudwatch

Note: You'll see the IPs hidden ofc. Sorry hackers, these IPs are not for you 🙃

Comments 0 total

Загрузка комментариев...
Add comment