Skip to content

Commit 3a9517a

Browse files
committed
Initial commit: AWS Cost Optimization Dashboard
- Complete Terraform infrastructure for cost monitoring - Lambda function with comprehensive error handling - S3 storage with lifecycle policies for cost data - Slack integration for intelligent cost alerts - EventBridge scheduling for daily cost checks - Security best practices with IAM least privilege - Automated deployment and testing scripts - Comprehensive documentation and best practices - CI/CD pipeline with GitHub Actions - Multi-environment support (dev/staging/prod)
0 parents  commit 3a9517a

23 files changed

+2086
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: '[BUG] '
5+
labels: bug
6+
assignees: ''
7+
8+
---
9+
10+
**Describe the bug**
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
Steps to reproduce the behavior:
15+
1. Go to '...'
16+
2. Click on '....'
17+
3. Scroll down to '....'
18+
4. See error
19+
20+
**Expected behavior**
21+
A clear and concise description of what you expected to happen.
22+
23+
**Screenshots**
24+
If applicable, add screenshots to help explain your problem.
25+
26+
**Environment (please complete the following information):**
27+
- OS: [e.g. macOS, Linux, Windows]
28+
- Terraform version: [e.g. 1.5.0]
29+
- AWS CLI version: [e.g. 2.13.0]
30+
- Python version: [e.g. 3.11]
31+
32+
**AWS Configuration:**
33+
- Region: [e.g. us-east-1]
34+
- Environment: [e.g. dev, staging, prod]
35+
36+
**Additional context**
37+
Add any other context about the problem here.
38+
39+
**Logs**
40+
If applicable, add relevant logs from:
41+
- Terraform output
42+
- Lambda CloudWatch logs
43+
- AWS CLI output
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: '[FEATURE] '
5+
labels: enhancement
6+
assignees: ''
7+
8+
---
9+
10+
**Is your feature request related to a problem? Please describe.**
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
**Describe the solution you'd like**
14+
A clear and concise description of what you want to happen.
15+
16+
**Describe alternatives you've considered**
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
**Use Case**
20+
Describe the specific use case or scenario where this feature would be beneficial.
21+
22+
**Implementation Ideas**
23+
If you have ideas about how this could be implemented, please share them.
24+
25+
**Additional context**
26+
Add any other context or screenshots about the feature request here.
27+
28+
**Priority**
29+
- [ ] Low
30+
- [ ] Medium
31+
- [ ] High
32+
- [ ] Critical

.github/workflows/ci.yml

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
terraform-validate:
11+
name: Terraform Validation
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Terraform
19+
uses: hashicorp/setup-terraform@v3
20+
with:
21+
terraform_version: 1.5.0
22+
23+
- name: Terraform Format Check
24+
run: terraform fmt -check -recursive
25+
26+
- name: Terraform Init
27+
run: terraform init -backend=false
28+
29+
- name: Terraform Validate
30+
run: terraform validate
31+
32+
python-lint:
33+
name: Python Linting
34+
runs-on: ubuntu-latest
35+
36+
steps:
37+
- name: Checkout code
38+
uses: actions/checkout@v4
39+
40+
- name: Setup Python
41+
uses: actions/setup-python@v4
42+
with:
43+
python-version: '3.11'
44+
45+
- name: Install dependencies
46+
run: |
47+
python -m pip install --upgrade pip
48+
pip install black pylint boto3 urllib3
49+
50+
- name: Run Black formatter check
51+
run: black --check lambda/
52+
53+
- name: Run Pylint
54+
run: pylint lambda/handler.py
55+
56+
security-scan:
57+
name: Security Scan
58+
runs-on: ubuntu-latest
59+
60+
steps:
61+
- name: Checkout code
62+
uses: actions/checkout@v4
63+
64+
- name: Run Trivy vulnerability scanner
65+
uses: aquasecurity/trivy-action@master
66+
with:
67+
scan-type: 'fs'
68+
scan-ref: '.'
69+
format: 'sarif'
70+
output: 'trivy-results.sarif'
71+
72+
- name: Upload Trivy scan results to GitHub Security tab
73+
uses: github/codeql-action/upload-sarif@v2
74+
if: always()
75+
with:
76+
sarif_file: 'trivy-results.sarif'
77+
78+
terraform-plan:
79+
name: Terraform Plan
80+
runs-on: ubuntu-latest
81+
needs: [terraform-validate, python-lint]
82+
if: github.event_name == 'pull_request'
83+
84+
steps:
85+
- name: Checkout code
86+
uses: actions/checkout@v4
87+
88+
- name: Setup Terraform
89+
uses: hashicorp/setup-terraform@v3
90+
with:
91+
terraform_version: 1.5.0
92+
93+
- name: Configure AWS credentials
94+
uses: aws-actions/configure-aws-credentials@v4
95+
with:
96+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
97+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
98+
aws-region: us-east-1
99+
100+
- name: Terraform Init
101+
run: terraform init
102+
103+
- name: Terraform Plan
104+
run: terraform plan -no-color
105+
continue-on-error: true
106+
107+
- name: Comment PR with plan
108+
uses: actions/github-script@v6
109+
with:
110+
script: |
111+
const output = `#### Terraform Plan 📖
112+
113+
\`\`\`
114+
${{ steps.plan.outputs.stdout }}
115+
\`\`\`
116+
117+
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
118+
119+
github.rest.issues.createComment({
120+
issue_number: context.issue.number,
121+
owner: context.repo.owner,
122+
repo: context.repo.repo,
123+
body: output
124+
})
125+
126+
deploy-dev:
127+
name: Deploy to Development
128+
runs-on: ubuntu-latest
129+
needs: [terraform-validate, python-lint, security-scan]
130+
if: github.ref == 'refs/heads/develop' && github.event_name == 'push'
131+
environment: development
132+
133+
steps:
134+
- name: Checkout code
135+
uses: actions/checkout@v4
136+
137+
- name: Setup Terraform
138+
uses: hashicorp/setup-terraform@v3
139+
with:
140+
terraform_version: 1.5.0
141+
142+
- name: Configure AWS credentials
143+
uses: aws-actions/configure-aws-credentials@v4
144+
with:
145+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
146+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
147+
aws-region: us-east-1
148+
149+
- name: Terraform Init
150+
run: terraform init
151+
152+
- name: Terraform Apply
153+
run: terraform apply -auto-approve -var="environment=dev"
154+
155+
deploy-prod:
156+
name: Deploy to Production
157+
runs-on: ubuntu-latest
158+
needs: [terraform-validate, python-lint, security-scan]
159+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
160+
environment: production
161+
162+
steps:
163+
- name: Checkout code
164+
uses: actions/checkout@v4
165+
166+
- name: Setup Terraform
167+
uses: hashicorp/setup-terraform@v3
168+
with:
169+
terraform_version: 1.5.0
170+
171+
- name: Configure AWS credentials
172+
uses: aws-actions/configure-aws-credentials@v4
173+
with:
174+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
175+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
176+
aws-region: us-east-1
177+
178+
- name: Terraform Init
179+
run: terraform init
180+
181+
- name: Terraform Apply
182+
run: terraform apply -auto-approve -var="environment=prod"

.gitignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Terraform
2+
*.tfstate
3+
*.tfstate.*
4+
*.tfvars
5+
!*.tfvars.example
6+
.terraform/
7+
.terraform.lock.hcl
8+
tfplan
9+
10+
# Lambda deployment package
11+
lambda_deployment.zip
12+
lambda.zip
13+
14+
# Python
15+
__pycache__/
16+
*.py[cod]
17+
*$py.class
18+
*.so
19+
.Python
20+
env/
21+
venv/
22+
ENV/
23+
24+
# IDE
25+
.vscode/
26+
.idea/
27+
*.swp
28+
*.swo
29+
30+
# OS
31+
.DS_Store
32+
Thumbs.db
33+
34+
# Logs
35+
*.log
36+
response.json
37+
38+
# AWS
39+
.aws/

CHANGELOG.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [1.0.0] - 2024-01-15
9+
10+
### Added
11+
- Initial release of AWS Cost Optimization Dashboard
12+
- Terraform infrastructure for automated cost monitoring
13+
- Lambda function for daily cost collection and alerting
14+
- S3 storage for historical cost data with lifecycle policies
15+
- Slack integration for cost threshold alerts
16+
- EventBridge scheduling for daily cost checks
17+
- Comprehensive security with IAM least privilege
18+
- Automated deployment scripts
19+
- Testing and validation utilities
20+
21+
### Features
22+
- Daily AWS cost monitoring via Cost Explorer API
23+
- Service-level cost breakdown and analysis
24+
- Configurable cost thresholds and alert schedules
25+
- Encrypted storage of historical cost data
26+
- Rich Slack notifications with cost details
27+
- Multi-environment support (dev, staging, prod)
28+
- Comprehensive error handling and logging
29+
- Cost optimization with S3 lifecycle policies
30+
31+
### Security
32+
- IAM roles with least privilege access
33+
- S3 bucket encryption with AES256
34+
- Secrets Manager for secure webhook storage
35+
- CloudTrail integration for audit logging
36+
- VPC deployment options for enhanced security
37+
38+
### Documentation
39+
- Comprehensive README with setup instructions
40+
- Best practices guide for security and operations
41+
- Contributing guidelines for open source collaboration
42+
- Example configurations and customization options

0 commit comments

Comments
 (0)