Key concepts that we are going to explore

  • AWS Cost Tools - Cost Explorer, Budgets, Trusted Advisor, Compute Optimizer
  • EventBridge - Rule-based automation, Event pattern filtering
  • Bedrock + LangChain (light) - Trigger LLM to explain cost anomalies
  • Lambda - Glue logic between AWS services
  • SNS - Cost alerts via email/SMS are going to explore.

🛠️ Architecture:

Image description

Step 1:

Enable AWS Cost Explorer

Image description

Image description

Step 2:

Configure AWS Budgets for service cost threshold (e.g., EC2 > $20/day)

Image description

Step 3:

Create an SNS Topic (e.g., CostAlertsTopic) and subscribe via email

Image description

Step 4:

Enable Amazon Bedrock which is available in:

  • us-east-1 (N. Virginia)
  • us-west-2 (Oregon)
  • eu-central-1 (Frankfurt)
  • ap-southeast-1 (Singapore)

Recommended Model: Anthropic Claude v2 (via Amazon Bedrock)

Why Claude v2?

  • Excellent at summarization and natural explanations
  • Fast and reliable via Bedrock API
  • Supports secure inference with no fine-tuning needed
  • Default model in many Bedrock-based examples

Model Details for Bedrock Invocation

  • Model ID: "anthropic.claude-v2"
  • Provider: Anthropic
  • API Method: InvokeModel
  • Region: us-east-1 or other supported region
  • Input format: Anthropic-specific prompt (not plain OpenAI style)

Image description

Step 5:

Setup Event bridge rule - Target Lambda Function

{
  "source": ["aws.budgets"],
  "detail-type": ["Budget Threshold Breached"]
}

Image description

Image description

Step 6:

Lambda Function: Analyze & Explain Cost Spike

import boto3
import json
import os

def lambda_handler(event, context):
    bedrock_runtime = boto3.client("bedrock-runtime", region_name="us-east-1")

    anomaly_detail = json.dumps(event['detail'], indent=2)
    prompt = f"Explain the following AWS cost anomaly in plain English:\n\n{anomaly_detail}"

    response = bedrock_runtime.invoke_model(
        modelId="anthropic.claude-v2",  # or other Bedrock-supported LLM
        body=json.dumps({"prompt": prompt, "max_tokens_to_sample": 500}),
        contentType="application/json"
    )

    output = json.loads(response['body'].read())
    explanation = output.get("completion", "No explanation generated.")

    sns = boto3.client('sns')
    sns.publish(
        TopicArn=os.environ["SNS_TOPIC_ARN"],
        Subject="AWS Cost Alert 📈",
        Message=explanation
    )

    return {"statusCode": 200, "body": explanation}

Note - Set SNS_TOPIC_ARN as an environment variable in Lambda

Image description

Image description

In this hands-on project, we combined the power of AWS automation and Generative AI to create an intelligent, event-driven cost monitoring system.
By leveraging AWS Budgets, EventBridge, Lambda, and Amazon Bedrock, we not only detected cost anomalies in real-time but also generated human-readable explanations using LLMs — making cloud spend analysis more accessible and actionable.

This is just the beginning of what’s possible when AI meets Cloud FinOps.
Imagine extending this to proactive optimization suggestions, ticket creation, or even Slack alerts — all powered by serverless workflows and GenAI.