Set up CloudWatch alarms and SNS topic in AWS

Set up CloudWatch alarms and SNS topic in AWS

ยท

7 min read

Introduction:)

On day46 of 90daysofdevops, we explore and continue on this journey with a new topic. We will learn about Amazon CloudWatch and Amazon SNS today.

What is Amazon CloudWatch?

Amazon CloudWatch is a monitoring and observability service provided by Amazon Web Services (AWS). It is designed to collect and track metrics, collect and monitor log files, and set alarms. CloudWatch provides you with data and operational insights for your AWS resources, applications, and services, allowing you to monitor, troubleshoot, and optimize performance.

Key features of Amazon CloudWatch

  1. Metric Collection and Tracking: Monitors an extensive range of metrics from AWS resources, serving as the cornerstone for assessing system health and performance.

  2. Log Management: Tracks, stores, and analyzes log files, providing insights into application behavior.

  3. Alerting and Alarming: Set up custom alarms based on thresholds for timely notifications of metric changes.

  4. Real-time Dashboards: Creates custom real-time dashboards for a holistic view of system performance.

  5. Granular Data Retrieval: Retrieves metrics with precision, ranging from one-second to one-day intervals.

  6. Integration with AWS Services: Seamlessly integrates with AWS resources for comprehensive monitoring and optimization.

  7. Custom Metrics Support: Publishes custom metrics to monitor specific aspects of applications and services.

What is Amazon SNS?

How Does Amazon SNS Work? - Analytics Vidhya

Amazon Simple Notification Service (SNS) is a fully managed messaging service provided by Amazon Web Services (AWS). It enables the distribution of messages to many recipients through various delivery methods like SMS, email, application endpoints, and more. SNS is designed to facilitate the creation of applications that can deliver notifications, alerts, or updates to users or systems. It's a versatile tool that helps build event-driven and distributed systems in the AWS environment.

Key features of Amazon SNS

  1. Multi-Platform Notifications: Allows sending messages via various channels like SMS, email, mobile push, etc., providing flexibility in communication.

  2. Message Filtering: Deliver specific messages to particular subscribers, reducing redundancy.

  3. Message Attributes: You can attach custom message attributes to messages, providing additional context or metadata. This is valuable for filtering and routing messages based on specific criteria.

  4. Security and IAM Integration: Fine-grained control over permissions.

  5. Scalability and Auto-Scaling: Easily handles varying message volumes.

  6. SNS Mobile Push Notifications: SNS provides a streamlined way to send mobile push notifications to Apple, Google, and other platforms, simplifying the process of notifying mobile app users.

  7. Billing and Usage Reports: AWS provides detailed billing and usage reports for SNS, helping you monitor costs and optimize your messaging solutions.

  8. Global Reach: SNS can deliver messages globally, making it suitable for applications with a worldwide user base.

  9. Message Size Flexibility: SNS supports different message sizes, accommodating both small and large messages for various use cases.

What are the pricing details for Amazon CloudWatch and Amazon SNS?

Amazon CloudWatch:

  1. Metrics:

    • Custom Metrics: $0.30 per metric per month.

    • Free Tier: 10 custom metrics and 10 alarms per month are included for free.

  2. Logs:

    • Log Ingestion: Paid based on the volume of log data ingested.

    • Log Storage: Paid based on the volume of log data stored.

  3. Alarms:

    • $0.10 per alarm per month (beyond the 10 free alarms in the free tier).
  4. Dashboards:

    • $3.00 per dashboard per month (the first three are free).
  5. Synthetics:

    • Paid based on the number of canaries run and the frequency of runs.
  6. Anomaly Detection:

    • Paid based on the number of detectors.

Amazon SNS:

  1. Publishing:

    • $0.50 per 1 million publishes.
  2. SMS Messaging:

    • Varies by destination country. Prices are available on the AWS SNS pricing page.
  3. Voice Messaging:

    • Varies by destination country. Prices are available on the AWS SNS pricing page.
  4. Push Notifications:

    • Free tier includes one million pushes per month for mobile endpoints.

What is the difference between Amazon CloudWatch and Amazon SNS?

FeatureAmazon CloudWatchAmazon SNS
Primary UseMonitoring and ObservabilityNotification and Messaging Service
MetricsCollects and tracks metrics from AWS resources and applications.N/A
LogsCollects, monitors, and analyzes log data from AWS resources and applications.N/A
Alerting/AlarmsAllows users to set up custom alarms based on predefined thresholds for metrics.Sends notifications based on events or thresholds being met.
DashboardsProvides real-time customizable dashboards for visualizing metrics.N/A
Custom MetricsAllows users to publish their own custom metrics for monitoring specific aspects.N/A
IntegrationIntegrates with various AWS resources, providing insights into instances, databases, storage, etc.Can be integrated with various AWS services, including CloudWatch for alerting.
Use CaseBest suited for monitoring and troubleshooting the performance and health of AWS resources and applications.Best suited for sending notifications and alerts for events or thresholds being met.
Cost StructurePay-as-you-go model based on usage and additional features like custom metrics, logs, etc.Pay-as-you-go model based on the number of messages sent or published.
Real-timeProvides real-time monitoring and observability of metrics.Provides real-time notifications for events.

Tasks :)

Task 1: Create a CloudWatch alarm that monitors your billing and sends an email to you when it reaches $2.

  1. Sign in to AWS Management Console:

    • Go to the AWS Management Console and sign in with your AWS account.

  2. Navigate to CloudWatch:

    • In the AWS Console, search for and select "CloudWatch".

  3. Set Up Billing Alarm:

    • In the CloudWatch Dashboard, click on "Alarms" from the left-hand menu.

  4. Create Alarm:

    • Click "Create Alarm".

      You get 10 free alarms and 1,000 free e-mail notifications each month as part of the AWS Free Tier

  5. Select Metric:

    • Under "Select metric", search for "EstimatedCharges" and select it.
  6. Choose Conditions:

    • Define the conditions for the alarm:

      • For example, choose "Threshold type" as static and set the threshold to $2.

      • Select the statistic (e.g., maximum).

      • Set the period (e.g., 6 hrs).

      • Define actions for whenever the threshold is breached.

  7. Set Actions:

    • Click on "Actions" and select "Create a new topic" under the "Actions" dropdown.

    • Provide a name for the SNS topic (e.g., BillingAlerts) and your email address.

  8. Create SNS Topic:

    • Click "Create topic" to create a new SNS topic. Provide a name and display name.

  9. Add Email Subscriptions:

    • Once the SNS topic is created, select it and click "Create subscription".

    • Choose "Email" as the protocol and enter your email address.

  10. Confirm Subscription:

    • You will receive a confirmation email. Confirm the subscription to start receiving notifications.

  11. Set Alarm Name and Description:

    • Provide a name and description for your CloudWatch alarm.

  12. Create Alarm:

    • Review the alarm configuration and click "Create Alarm".


Task 2: Delete the billing Alarm that you created now

  1. Sign in to AWS Management Console:

    • Go to the AWS Management Console and sign in with your AWS account.
  2. Navigate to CloudWatch:

    • In the AWS Console, search for and select "CloudWatch".
  3. Manage Alarms:

    • In the CloudWatch Dashboard, click on "Alarms > All alarms" from the left-hand menu.

  4. Select Alarm:

    • Find the alarm you want to delete in the list, and select it.

  5. Delete Alarm:

    • Click on the "Actions" button and select "Delete" from the dropdown menu.

  6. Confirm Deletion:

    • Confirm the deletion when prompted.

  7. Successfully Deleted:


Conclusion:)

In this blog post, we have learned about Amazon CloudWatch and Amazon SNS, two powerful AWS services that can be used to monitor and manage your AWS resources. We have also seen how to create and delete a CloudWatch billing alarm.

Successfully completed the task! I have learned about Amazon CloudWatch and Amazon SNS, and I am now able to create and delete a CloudWatch billing alarm. I am excited to continue learning about DevOps and to use these new skills to improve my work as a software engineer.


Thank you for diving into this blog with me! I trust you found the information both helpful and enlightening. To stay updated on the latest in DevOps ๐Ÿš€, make sure to follow me. Remember, staying informed means staying ahead in the dynamic world of DevOps!

Feel free to connect with me on:

LinkedIn

Twitter

GitHub

For more updates and engaging discussions on DevOps, let's connect! ๐Ÿš€ #DevOpsCommunity

Happy Learning! Keep pushing those boundaries! ๐Ÿ˜Š

ย