Schedule icon
Script icon
Create icon
If icon
SlackIncomingWebhook icon
Log icon

AWS EC2 Idle Cost Guardrail and Right-Sizing Sentinel

Automate AWS FinOps cost reduction with Kestra. Query CloudWatch CPU utilization, detect idle EC2 instances, sync GitHub audit issues, and alert Slack.

Categories
CloudInfrastructure

Idle cloud compute instances left running over weekends and off-peak hours generate significant unmonitored cloud waste. This blueprint provides an automated FinOps guardrail that queries Amazon CloudWatch for 24-hour average CPU utilization, identifies underutilized EC2 instances, generates an auditable tracking issue on GitHub, and alerts engineering teams via Slack.

How it works

  1. A Schedule trigger (io.kestra.plugin.core.trigger.Schedule) fires daily (e.g. at 18:00 UTC) at the end of business hours.
  2. The evaluate_cpu_utilization task (io.kestra.plugin.scripts.python.Script) connects to Amazon CloudWatch via boto3, pulls the 24-hour average CPU utilization metric for the specified instance, and evaluates if it falls below the idle threshold.
  3. The create_finops_audit_issue task (io.kestra.plugin.github.issues.Create) automatically creates a GitHub tracking issue recording the performance audit and right-sizing recommendations.
  4. The check_idle_state task (io.kestra.plugin.core.flow.If) evaluates the condition: if the instance is marked is_idle: true, it posts an alert to the FinOps Slack channel with the direct GitHub issue link. If healthy, it logs a compliant audit entry.

What you get

  • Automated CloudWatch metric auditing without manual console browsing.
  • Systematic detection of underutilized or orphaned compute instances.
  • Traceable GitHub documentation for every right-sizing recommendation.
  • Real-time Slack notifications alerting DevOps and platform teams to cost leaks.

Who it's for

  • FinOps teams auditing and optimizing multicloud infrastructure budgets.
  • Platform and DevOps engineers maintaining staging and development environments.
  • Cloud architects instituting continuous cost guardrails across AWS accounts.

Why orchestrate this with Kestra

Combining metric ingestion from AWS, mathematical thresholding in containerized Python, GitHub issue ticketing, and team notifications requires unifying separate vendor APIs into a reliable pipeline. Kestra manages secrets securely, logs detailed audit trails, handles transient cloud API retries, and executes scheduled checks reliably without external glue scripts.

Prerequisites

  • A running Kestra instance with the AWS, Python, GitHub, and Slack plugins.
  • An AWS IAM user or role with cloudwatch:GetMetricData and cloudwatch:ListMetrics permissions.
  • A GitHub Personal Access Token with repo issues scope.
  • A Slack incoming webhook URL for notifications.

Secrets

  • AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY: AWS credentials used by the CloudWatch metric analyzer.
  • GITHUB_TOKEN: GitHub OAuth/Personal Access Token for logging audit issues.
  • SLACK_WEBHOOK: Incoming Webhook URL for FinOps notifications.

Quick start

  1. Configure the three secrets in your Kestra namespace or instance settings.
  2. Import this flow into your target namespace (e.g., company.cloud).
  3. Set instance_id and region to target a development or staging EC2 instance.
  4. Execute the flow manually to verify metric retrieval, GitHub issue logging, and Slack alerts.
  5. Enable the schedule trigger for continuous off-hours FinOps protection.

How to extend

  • Add an automated io.kestra.plugin.aws.ec2.Stop task to power down non-production instances automatically after approval.
  • Extend the Python script to iterate over an array of instances or query by tag (e.g., Environment=staging).
  • Integrate AWS Cost Explorer API metrics alongside CloudWatch utilization data.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.