AWS Orphan Alarms Report Generation
Source: Dev.to
Pipeline Configuration
Options
- Build Discarder: Keeps the last 5 builds and artifacts.
- Timestamps: Adds timestamps to the build log.
Environment Variables
- DEFAULT_ENV – Default environment name.
- DEFAULT_BRANCH – Default Git branch name.
- GIT_URL – Git repository URL.
- GIT_PATH – Git repository path.
- REGION_NAME – AWS region name.
- REPOSITORY_NUMBER – AWS account repository number.
- PROJECT_NAME – Name of the project.
- SNS_TOPIC_NAME – SNS topic for alerts.
- S3_BUCKET_NAME – S3 bucket for configuration.
- S3_BUCKET_PATH – Path to the configuration file in S3.
Triggers
The pipeline runs weekly on Monday at 10:30 AM via a cron expression.
Pipeline Stages
- Setting Build – Configures build details, including display name and description.
- Cleaning the Workspace – Cleans the Jenkins workspace.
- Pulling the Repository – Checks out the Git repository using the specified branch.
- Download Artifacts from S3 – Retrieves artifacts from the configured S3 bucket and path.
- Execute Python Script –
- Sets up a Python virtual environment.
- Installs dependencies.
- Runs the main script
main.py.
- Post‑Build (Failure) – Sends an SNS notification if the build fails.
Python Script (main.py)
The script generates an AWS Resource Utilization report. It uses the boto3 library to interact with AWS services, gathers metrics for EC2 instances and RDS databases, and creates an Excel report with the collected data.
# Example snippet from main.py
import boto3
import xlsxwriter
import yaml
# Initialize AWS clients
ec2 = boto3.client('ec2', region_name='us-east-1')
rds = boto3.client('rds', region_name='us-east-1')
# ... rest of the script that builds the report ...
Dependencies
boto3XlsxWriterPyYAML
Report Structure
The generated Excel report includes alarms for the following services:
- EC2
- RDS
- Load Balancer
- Target Group
- ECS Cluster
- ECS Services
- Lambda
- SQS
Thresholds for highlighting values are configured in the pipeline based on service‑specific limits.
Usage
- Install the required Jenkins plugins and configure the Jenkins instance.
- Create a new pipeline job.
- Paste the provided pipeline script into the job configuration.
- Set the necessary parameters and environment variables.
- Save the configuration and trigger the pipeline manually or let the scheduled cron run.
The generated Excel report will be saved in the Jenkins workspace. Feel free to customize both the pipeline and Python scripts to suit your specific AWS environment.
GitHub Link
https://github.com/prashantgupta123/devops-automation/tree/main/aws-cw-orphan-alarms