AWS CloudFormation -Deploys Amazon RDS Instance And Sets Up Monitoring Alarms

AWS CloudFormation -Deploys Amazon RDS Instance And Sets Up Monitoring Alarms

Introduction :-

The provided AWS #CloudFormation template is a robust and configurable solution for deploying an #AmazonWebServices (AWS) Amazon RDS (Relational Database Service) instance and implementing comprehensive monitoring for that instance. In modern #Infrastructureascode infrastructure, it’s essential to maintain the performance and reliability of database services, and this template streamlines the process of creating a monitoring infrastructure for RDS instances. By defining parameters for customizability and utilizing AWS services like #SimpleNotificationService (SNS) and #CloudWatchAlarms, this template equips users with the tools needed to proactively manage and monitor their #RDS databases. This introduction serves as a precursor to the template’s description, highlighting its significance in ensuring the optimal operation of #RDS instances in various environments.

This is an AWS CloudFormation template written in YAML that deploys an Amazon RDS (Relational Database Service) instance and sets up monitoring alarms for that instance. Here’s a breakdown of the key components of this CloudFormation template:

  1. AWSTemplateFormatVersion: The version of the CloudFormation template being used.

  2. Description: A description of what the CloudFormation stack does.

  3. Parameters: This section defines the input parameters that users can specify when creating the stack. In this template, there are three parameters:

  • EnvironmentName: A string parameter for the environment name.

  • DBInstanceIdentifier: A string parameter for the name of the DB instance.

  • EmailAddressParam: A string parameter for the email address for sending RDS-related notifications.

4. Resources: This section defines the AWS resources that will be created when the stack is launched. In this template, the following resources are defined:

  • RDSMonitoring#SNSTopic: An Amazon Simple Notification Service (SNS) topic for RDS monitoring notifications. It is created with a display name and an email subscription that will send notifications to the specified email address.

  • RDSMonitoringSNSTopicPolicy: A policy attached to the SNS topic, allowing any AWS principal to publish messages to the topic. This policy ensures that the alarms can send notifications to the SNS topic.

  • RDSCPUUtilizationAlarm: A CloudWatch alarm for monitoring CPU utilization of the RDS instance. When CPU utilization exceeds 60% for one 5-minute period, the alarm will trigger and send notifications to the SNS topic. The alarm has a name, a description, and several settings for its behavior.

  • RDSDBConnectionAlarm: Another #CloudWatch alarm, this time for monitoring the database connection count. It triggers when the connection count exceeds 500 for one 5-minute period and sends notifications to the same SNS topic.

5. Outputs: This section defines the outputs of the CloudFormation stack. In this case, it exports the ARN (Amazon Resource Name) of the RDSMonitoringSNSTopic so that it can be used in other stacks or services. The exported name is a combination of the stack name and "RDSMonitoringSNSTopicArn."

This template can be used to create a CloudFormation stack that sets up monitoring for an Amazon RDS instance, including alarms for CPU utilization and database connection count. When you create the stack, you would provide values for the EnvironmentName, DBInstanceIdentifier, and EmailAddressParam parameters. The alarms will be associated with the specified RDS instance, and notifications will be sent to the specified email address when the defined thresholds are breached.

Deployment Steps

Follow these steps to upload and create the #CloudFormation stack using the AWS Management Console:

  1. Sign in to the #AWSManagementConsole: Log in to your AWS account if you haven’t already.

2. Navigate to CloudFormation: Go to the AWS CloudFormation service from the AWS Management Console.

3. Click the “Create stack” button.

4. Upload the #CloudFormation template file (YAML).

#Yaml File :

AWSTemplateFormatVersion: '2010-09-09'
Description: This stack deploys a RDS instance.
Parameters:
  EnvironmentName:
    Description: Environment name for the application
    Type: String
  DBInstanceIdentifier:
    Description: Name of DB instance
    Type: String
  EmailAddressParam:
    Description: Email Address for sending RDS related notifications
    Type: String
Resources:
  RDSMonitoringSNSTopic:
    Type: AWS::SNS::Topic
    Properties: 
      DisplayName: !Sub "${EnvironmentName}-rds-notification-topic"
      Tags: 
      - Key: "Project"
        Value: "DataPipeline"
      Subscription: 
      - Endpoint: !Ref EmailAddressParam
        Protocol: email
  RDSMonitoringSNSTopicPolicy:
    Type: AWS::SNS::TopicPolicy
    Properties:
      Topics:
        - !Ref RDSMonitoringSNSTopic
      PolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Effect: Allow
            Principal:
              AWS: '*'
            Action:
              - "SNS:Publish"
            Resource: '*'
  RDSCPUUtilizaionAlarm:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmName: !Sub '${EnvironmentName}-${DBInstanceIdentifier} CPUUtilization Alarm'
      AlarmActions:
        - !Ref RDSMonitoringSNSTopic
      AlarmDescription: !Sub '${EnvironmentName}-${DBInstanceIdentifier} CPUUtilization Alarm spiked above 60%'
      ComparisonOperator: GreaterThanThreshold
      DatapointsToAlarm: 1
      Dimensions:
      - Name: DBInstanceIdentifier
        Value: !Ref DBInstanceIdentifier
      EvaluationPeriods: 1
      MetricName: CPUUtilization
      Namespace: AWS/RDS
      OKActions:
        - !Ref RDSMonitoringSNSTopic
      Period: 300
      Statistic: Average
      Threshold: 60
      TreatMissingData: notBreaching
  RDSDBConnectionAlarm:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmName: !Sub '${EnvironmentName}-${DBInstanceIdentifier} DBConnection Count Alarm'
      AlarmActions:
        - !Ref RDSMonitoringSNSTopic
      AlarmDescription: !Sub '${EnvironmentName}-${DBInstanceIdentifier} DB Connection Count spiked above the allowed threshold'
      ComparisonOperator: GreaterThanThreshold
      DatapointsToAlarm: 1
      Dimensions:
      - Name: DBInstanceIdentifier
        Value: !Ref DBInstanceIdentifier
      EvaluationPeriods: 1
      MetricName: DatabaseConnections
      Namespace: AWS/RDS
      OKActions:
        - !Ref RDSMonitoringSNSTopic
      Period: 300
      Statistic: Sum
      Threshold: 500
      TreatMissingData: notBreaching
Outputs: 
  RDSMonitoringSNSTopicArn:
    Description: 'Sns ARN RDS Monitoring Topic'
    Value: !Ref RDSMonitoringSNSTopic
    Export:
      Name: !Join ["-", [!Ref "AWS::StackName", "RDSMonitoringSNSTopicArn"]]

5. Specify Stack Details:

  • Enter a Stack name for your deployment.

  • Provide parameter values as needed.

  • Review and acknowledge the capabilities .

  • You can set additional stack options or tags if necessary.

6. Review and Create:

  • Review the stack details and configuration.

  • Click “Create stack” to initiate the deployment.

7. Monitor Stack Creation:

  • The #CloudFormation stack creation process will begin.

  • Monitor the stack events in the AWS Management Console.

Conclusion :-

AWS CloudFormation template presents a robust framework for deploying and monitoring #AmazonWebServices (AWS) Amazon RDS instances with ease. By offering configurable parameters, it adapts to diverse use cases and environments. The template efficiently leverages AWS services like #SimpleNotificationService (SNS) and #CloudWatchAlarms to notify stakeholders when critical thresholds are exceeded. This empowers AWS users to maintain the performance, availability, and security of their RDS instances, enhancing the overall reliability of their applications. As organizations increasingly rely on #CloudServices, having a comprehensive monitoring solution is paramount, and this CloudFormation template is a valuable tool for achieving that goal. Whether in development, staging, or production, this template can be instrumental in safeguarding the health of RDS databases and the applications they support.