Mastering AWS Monitoring: CloudWatch Metrics, Alarms, Logs, EventBridge & CloudTrail in One Go!
Burhan ????
Focused on building secure network and cloud infrastructure with expertise in Docker, Kubernetes, Ansible, Terraform, and CI/CD pipelines
CloudWatch Metrics (Performance Tracking)
Think of CloudWatch Metrics like a fitness tracker for your AWS services. Just like a fitness tracker measures your steps, heart rate, or sleep, CloudWatch Metrics measure things like
AWS collects this data and shows it in easy-to-read charts, so you can see how well your system is running
CloudWatch Alarms (Automatic Alerts & Actions)
Now, imagine your fitness tracker alerts you when your heart rate is too high. That’s exactly what CloudWatch Alarms do for your AWS services!
You can set an alarm to notify you or take action when something goes wrong. For example:
CloudWatch Metrics = Monitors AWS performance
CloudWatch Alarms = Sends alerts or takes action when something unusual happens
Cloud Watch Matrics
This image is from AWS CloudWatch Metrics, and it shows different AWS services being monitored. Here’s what it tells us in simple words
CloudWatch Alarms
You can directly create this alarm when ypu ec2 instance has launched i have gives you a short demo
If ypu want to enable billing alarm then visit on us-east-1 to check billing option
What is CloudWatch Logs
What are Logs ?
Logs are records of activities and events happening in a system. Every time something happens, the system writes a log entry to keep track of it.
Think of CloudWatch Logs as a notebook where AWS services write down everything they are doing. These logs help in troubleshooting, monitoring, and security analysis.
CloudWatch Logs with a Fitness Tracker Example
Imagine you have a smart fitness tracker that records your daily activities. It keeps track of :
Now, if one day you feel tired and want to know why, you can check your fitness logs to see if:
Similarly, in AWS CloudWatch Logs, services like EC2, Lambda, and RDS write logs about what is happening, such as
Note : EC2 Instance & ON - Premises need a CloudWatch Agent to Push a log's on cloud watch
Click on CloudWatch Logs create a Create log group
Log Generated We can also use Lambda function to create this log here we have use python code to create this log
If you want to use this code to practice with CloudWatch Logs, first configure AWS by running:
aws configure | Access key | Secret access key
Then, install Boto3 using the pip command:
pip install boto3
Finally, run the script. ??
import boto3
import time
# Initialize CloudWatch Logs client
client = boto3.client('logs', region_name="us-west-2") # Change region if needed
# Define Log Group & Log Stream
log_group_name = "Learning-logGroup"
log_stream_name = "learninglogstream"
# Step 1: Ensure Log Group Exists
try:
client.create_log_group(logGroupName=log_group_name)
print(f"? Log Group '{log_group_name}' created!")
except client.exceptions.ResourceAlreadyExistsException:
print(f"?? Log Group '{log_group_name}' already exists.")
# Step 2: Ensure Log Stream Exists
try:
client.create_log_stream(logGroupName=log_group_name, logStreamName=log_stream_name)
print(f"? Log Stream '{log_stream_name}' created!")
except client.exceptions.ResourceAlreadyExistsException:
print(f"?? Log Stream '{log_stream_name}' already exists.")
# Step 3: Get Upload Sequence Token (if required)
try:
response = client.describe_log_streams(logGroupName=log_group_name, logStreamNamePrefix=log_stream_name)
log_streams = response.get("logStreams", [])
sequence_token = log_streams[0].get("uploadSequenceToken") if log_streams else None
except Exception as e:
print(f"? Error getting sequence token: {e}")
sequence_token = None
# Step 4: Send Logs to CloudWatch
log_events = [
{
"timestamp": int(time.time() * 1000), # Current time in milliseconds
"message": "?? First log Send By linkedin burhankhan503: CloudWatch logging started! "
},
{
"timestamp": int(time.time() * 1000),
"message": "? Second log linkedin burhankhan503: Logs successfully sent!"
}
]
try:
put_log_args = {
"logGroupName": log_group_name,
"logStreamName": log_stream_name,
"logEvents": log_events
}
if sequence_token:
put_log_args["sequenceToken"] = sequence_token
response = client.put_log_events(**put_log_args)
print("?? Logs sent by linkedin burhankhan503 successfully!")
except Exception as e:
print(f"? Error sending logs: {e}")
What is EventBridge
AWS EventBridge is a serverless event bus that helps different AWS services and applications communicate with each other in real time. It works by routing events from sources (like AWS services or custom applications) to targets (like Lambda, SQS, SNS, etc.)
Example Using EventBridge
Imagine you have a fitness app that tracks users' workouts. You can use EventBridge to automate actions based on events
?? Scenario: Automated Workout Rewards
How It Works (Flow)
1?? User finishes a workout (event generated).
2?? EventBridge captures the event and matches it to a rule.
3?? EventBridge routes the event to multiple targets:
Example EventBridge Event (JSON Format)
{
"source": "fitness.app",
"detail-type": "WorkoutCompleted",
"detail": {
"user_id": "12345",
"workout_type": "Running",
"duration": "30 minutes",
"calories_burned": 250
}
}
? Benefits of EventBridge in Fitness Apps
Hands On CloudWatch EventBridge
What is AWS CloudTrail Explained with a Fitness App
AWS CloudTrail is a service that helps you track user activity and API calls in your AWS account. It records every action taken, whether by a user, service, or AWS itself, and stores the logs for auditing and security purposes
Imagine you have a Fitness App hosted on AWS. Users log in, track workouts, and store data on the cloud. AWS CloudTrail helps you monitor all activities and ensure security.
AWS CloudTrail - Key Features & Steps
AWS Cloud Health Dashboard
The AWS Cloud Health Dashboard helps you check if AWS services are working properly. It shows if there are any issues, outages, or maintenance happening
Types of AWS Health Dashboards
1?? AWS Service Health Dashboard
2?? AWS Personal Health Dashboard (PHD)
3?? AWS CloudWatch Dashboard
?? Simple Example: If AWS S3 is down, you can check the AWS Service Health Dashboard to confirm the issue. If only your EC2 instance is having trouble, the Personal Health Dashboard will notify you.
What is AWS SQS
AWS SQS (Simple Queue Service) is a service that helps different parts of an application communicate by sending, storing, and receiving messages in a queue. It ensures that messages are delivered even if one part of the system is slow or temporarily down
Example: Fitness App Using SQS ???♂???
Imagine you have a fitness app where users can request personalized workout plans
1?? User Requests a Workout Plan
2?? SQS Holds the Request in a Queue
3?? Backend System Processes Requests One by One
4?? User Gets the Workout Plan
?? Why Use SQS?
? Ensures requests don’t get lost.
? Handles high traffic smoothly.
? Prevents slow responses by allowing background processing.
Hands On
What is SNS (Simple Notification Service)
AWS SNS (Simple Notification Service) is a messaging service that sends notifications to users or systems. It helps apps communicate with people through SMS, email, or push notifications
?? Example: Fitness App
Imagine you have a Fitness App that tracks a user’s workouts
?? "Great job! You completed your workout. Keep going!"
?? "Hey! Time for your daily workout. Stay active!"
SNS helps the app automate notifications and keep users engaged! ??
Hands On
#AWSMonitoring #CloudWatch #CloudTrail #EventBridge #DevOps #AWSLogs #Observability #AWSTraining #CloudComputing #AWSAlarms #TechLearning ??
Digital Marketing Specialist
1 周Well done Burhan
?? Data Enthusiast | Storyteller through Data | Problem Solver ??
1 周Well done Burhan
DevOps Engineer EX Siemens Advanta || DevOps & Orchestration || Cloud || Terraform || Kubernetes || AWS || GCP || Docker || Ansible || Monitoring
1 周Congrats Burhan!
Aspiring Data Analyst | Power BI | SQL | Business Intelligence | Data Visualization
1 周For deployment are there any Free services apart from cloud