Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

85 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌱 Automated Carbon Footprint Optimization on AWS

An automated system to track, analyze, and optimize cloud infrastructure's environmental impact using AWS Cost Explorer, EventBridge, Lambda, DynamoDB, and a real-time Dashboard.


πŸ“‹ Table of Contents


Quick Deploy (Terraform)

Want to skip the step-by-step sections? Deploy the entire stack in under 5 minutes:

git clone https://github.com/Atharva013/Carbon-Optimizer.git
cd Carbon-Optimizer/terraform
cp terraform.tfvars.example terraform.tfvars   # edit with your region/email
terraform init && terraform apply

After deployment, open the Dashboard URL shown in the output. For details, see the Terraform README.

⚠️ Requires Terraform β‰₯ 1.3 and AWS CLI v2 with configured credentials.


Project Overview

This project creates an automated carbon footprint optimization system by integrating AWS Cost Explorer insights with sustainability analysis through EventBridge and Lambda. The system:

  • πŸ“Š Analyzes monthly cost and usage patterns automatically
  • ♻️ Applies industry-standard carbon emission factors
  • πŸ’‘ Generates optimization recommendations to reduce environmental impact and costs
  • πŸ”” Sends real-time alerts when high-impact optimization opportunities are found
  • πŸ—„οΈ Stores historical sustainability metrics for trend analysis
  • πŸ–₯️ Visualizes all data through a real-time web dashboard hosted on S3

Estimated Monthly Cost: $15–25 USD (Lambda, DynamoDB, S3, SNS, API Gateway)


Architecture

The dashboard uses a cached billing snapshot architecture so regular page refreshes do not keep calling AWS Cost Explorer.

Carbon Optimizer Architecture

Flow summary:

  • EventBridge runs the analyzer Lambda on a schedule.
  • The analyzer reads AWS billing/config data, computes carbon insights, and stores a snapshot in DynamoDB.
  • SNS sends alert emails when the configured threshold or recommendation rules are triggered.
  • The dashboard API reads the cached DynamoDB snapshot, and S3/CloudFront serve the UI over HTTP/HTTPS.

Implementation Guide

Section Responsibility
Section 1 IAM Roles & DynamoDB Setup
Section 2 Lambda Function Development
Section 3 SNS Notifications & EventBridge Schedules
Section 4 Cost & Usage Reports + SSM Configuration
Section 5 Real-Time Dashboard & GUI
Section 6 Validation, Testing & Cleanup

⚠️ Sections must be deployed in order (1 β†’ 2 β†’ 3 β†’ 4 β†’ 5 β†’ 6). Each section depends on the previous.


Prerequisites

Before starting, ensure you have:

  • AWS account with billing/cost management permissions
  • AWS CLI v2 installed and configured (aws --version)
  • Python 3.11+ installed
  • Git installed and configured
  • GitHub account with repo access
  • IAM permissions for: Lambda, EventBridge, Cost Explorer, S3, DynamoDB, SNS, SSM, CUR, API Gateway

Repository Structure

carbon-optimizer/
β”œβ”€β”€ README.md                        # This file
β”œβ”€β”€ CONTRIBUTING.md                  # Contribution guidelines
β”œβ”€β”€ CHANGELOG.md                     # Version history
β”œβ”€β”€ .gitignore                       # Ignored files
β”‚
β”œβ”€β”€ terraform/                       # ⚑ One-command deploy (recommended)
β”‚   β”œβ”€β”€ main.tf                      # All AWS resources
β”‚   β”œβ”€β”€ variables.tf                 # User configuration
β”‚   β”œβ”€β”€ outputs.tf                   # Dashboard URL & endpoints
β”‚   β”œβ”€β”€ terraform.tfvars.example     # Example config (copy to .tfvars)
β”‚   └── README.md                    # Terraform quick-start guide
β”‚
β”œβ”€β”€ sections/                        # Per-member task breakdowns
β”‚   β”œβ”€β”€ section-1-iam-dynamodb.md
β”‚   β”œβ”€β”€ section-2-lambda.md
β”‚   β”œβ”€β”€ section-3-sns-eventbridge.md
β”‚   β”œβ”€β”€ section-4-cur-ssm.md
β”‚   β”œβ”€β”€ section-5-dashboard.md
β”‚   └── section-6-testing-cleanup.md
β”‚
β”œβ”€β”€ docs/                            # Project documentation
β”‚   └── github-project-setup.md
β”‚
β”œβ”€β”€ lambda-function/                 # Lambda source code
β”‚   └── index.py                     # Carbon footprint analyzer
β”‚
β”œβ”€β”€ dashboard/                       # Dashboard source (Section 5)
β”‚   β”œβ”€β”€ index.html                   # Main dashboard UI
β”‚   └── dashboard-api/
β”‚       └── index.py                 # API Gateway Lambda
β”‚
β”œβ”€β”€ iam/                             # IAM policy documents
β”‚   β”œβ”€β”€ lambda-trust-policy.json
β”‚   └── lambda-permissions-policy.json
β”‚
β”œβ”€β”€ cloudformation/                  # CloudFormation templates
β”‚   └── sustainable-infrastructure.yaml
β”‚
β”œβ”€β”€ scripts/                         # Shell deploy scripts (manual path)
β”‚   β”œβ”€β”€ setup.sh                     # Initial resource creation
β”‚   β”œβ”€β”€ deploy-analyzer.sh           # Analyzer Lambda packaging + deploy
β”‚   β”œβ”€β”€ deploy.sh                    # SNS + EventBridge + CUR + SSM
β”‚   β”œβ”€β”€ deploy-dashboard.sh          # Dashboard Lambda + API + S3
β”‚   β”œβ”€β”€ deploy-cloudfront.sh         # Optional HTTPS via CloudFront
β”‚   β”œβ”€β”€ validate.sh                  # End-to-end validation
β”‚   └── cleanup.sh                   # Delete all resources
β”‚
└── .github/
    β”œβ”€β”€ workflows/
    β”‚   └── validate.yml
    └── ISSUE_TEMPLATE/
        └── bug_report.md

Getting Started

1. Clone the Repository

git clone https://github.com/Atharva013/Carbon-Optimizer.git
cd Carbon-Optimizer

2. Configure Environment

# Set your AWS region and account
export AWS_REGION=$(aws configure get region)
export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)

# Set project name (use the same suffix across all sessions!)
export PROJECT_NAME="carbon-optimizer-cloud"
export S3_BUCKET="${PROJECT_NAME}-data"
export LAMBDA_FUNCTION="${PROJECT_NAME}-analyzer"
export DYNAMODB_TABLE="${PROJECT_NAME}-metrics"

echo "Project: ${PROJECT_NAME}"

3. Follow Section Guides in Order


Deployment Guide

Option A β€” Terraform (Recommended) ⚑

cd terraform
cp terraform.tfvars.example terraform.tfvars   # edit with your values
terraform init
terraform apply

See terraform/README.md for full details.

Option B β€” Shell Scripts (Step-by-step)

Run sections in order (Sections 1–5 deploy; Section 6 validates):

# Optional: create a local env file for convenience
cp .env.example .env
source .env   # or export vars manually

# Full deployment
bash scripts/setup.sh              # IAM + DynamoDB + S3
bash scripts/deploy-analyzer.sh    # Analyzer Lambda
bash scripts/deploy.sh             # SNS + EventBridge + CUR + SSM
bash scripts/deploy-dashboard.sh   # Dashboard Lambda + API Gateway + S3 upload

# Trigger one fresh billing snapshot for the dashboard
aws lambda invoke --function-name ${PROJECT_NAME}-analyzer --payload '{}' /tmp/r.json && cat /tmp/r.json

# Optional: HTTPS via CloudFront (takes 5-10 minutes)
bash scripts/deploy-cloudfront.sh

Validation & Testing

# Test Lambda execution
aws lambda invoke \
    --function-name ${LAMBDA_FUNCTION} \
    --payload '{}' response.json && cat response.json

# Verify DynamoDB data
aws dynamodb scan --table-name ${DYNAMODB_TABLE} --max-items 5

# List EventBridge schedules
aws scheduler list-schedules --name-prefix ${PROJECT_NAME}

# Run full validation suite (Section 6)
bash scripts/validate.sh

Cleanup

# If deployed with Terraform:
cd terraform && terraform destroy

# If deployed with shell scripts:
bash scripts/cleanup.sh

⚠️ This permanently deletes all AWS resources created by this project.


Contributing

See CONTRIBUTING.md for branch naming, commit conventions, and PR process.

Branch naming for each section:

feature/section-1-iam-dynamodb
feature/section-2-lambda
feature/section-3-sns-eventbridge
feature/section-4-cur-ssm
feature/section-5-dashboard
feature/section-6-testing-cleanup

Resources

About

AWS cost and carbon optimization dashboard with Terraform + Lambda + DynamoDB + SNS, built to surface real billing usage through a cached, low-cost dashboard.

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages