Compare commits
3 Commits
cb88caf52a
...
47492c2aee
| Author | SHA1 | Date | |
|---|---|---|---|
|
47492c2aee
|
|||
|
1d5db23dcd
|
|||
|
cc12bb9190
|
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
oauth_creds.json
|
||||
tmp/bin/*
|
||||
state.json
|
||||
extensions
|
||||
antigravity
|
||||
4
google_accounts.json
Normal file
4
google_accounts.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"active": "bob@dxw.com",
|
||||
"old": []
|
||||
}
|
||||
1
history/aws-stuff/.project_root
Normal file
1
history/aws-stuff/.project_root
Normal file
@@ -0,0 +1 @@
|
||||
/Users/bob/git/dxw/aws-stuff
|
||||
1
history/baspress/.project_root
Normal file
1
history/baspress/.project_root
Normal file
@@ -0,0 +1 @@
|
||||
/Users/bob/git/dxw/baspress
|
||||
1
history/beer-list/.project_root
Normal file
1
history/beer-list/.project_root
Normal file
@@ -0,0 +1 @@
|
||||
/Users/bob/git/rjw1/beer-list
|
||||
1
history/dalmatian-config/.project_root
Normal file
1
history/dalmatian-config/.project_root
Normal file
@@ -0,0 +1 @@
|
||||
/Users/bob/git/dxw/dalmatian-config
|
||||
1
history/dalmatian/.project_root
Normal file
1
history/dalmatian/.project_root
Normal file
@@ -0,0 +1 @@
|
||||
/Users/bob/git/dxw/dalmatian
|
||||
1
history/find-security-updates/.project_root
Normal file
1
history/find-security-updates/.project_root
Normal file
@@ -0,0 +1 @@
|
||||
/Users/bob/git/dxw/find-security-updates
|
||||
1
history/gemini-developmnet/.project_root
Normal file
1
history/gemini-developmnet/.project_root
Normal file
@@ -0,0 +1 @@
|
||||
/Users/bob/dxw/gemini-developmnet
|
||||
1
history/gemini/.project_root
Normal file
1
history/gemini/.project_root
Normal file
@@ -0,0 +1 @@
|
||||
/Users/bob/.gemini
|
||||
1
history/natcen/.project_root
Normal file
1
history/natcen/.project_root
Normal file
@@ -0,0 +1 @@
|
||||
/Users/bob/git/dxw/natcen
|
||||
1
history/randomness-puppet/.project_root
Normal file
1
history/randomness-puppet/.project_root
Normal file
@@ -0,0 +1 @@
|
||||
/Users/bob/git/rjw1/randomness-puppet
|
||||
1
history/supabase/.project_root
Normal file
1
history/supabase/.project_root
Normal file
@@ -0,0 +1 @@
|
||||
/Users/bob/git/dxw/discovery_policy_atlas/backend/supabase
|
||||
1
history/sympl-config/.project_root
Normal file
1
history/sympl-config/.project_root
Normal file
@@ -0,0 +1 @@
|
||||
/Users/bob/git/rjw1/sympl-config
|
||||
@@ -0,0 +1 @@
|
||||
/Users/bob/git/dxw/terraform-dxw-dalmatian-infrastructure
|
||||
1
history/tfvars/.project_root
Normal file
1
history/tfvars/.project_root
Normal file
@@ -0,0 +1 @@
|
||||
/Users/bob/.config/dalmatian/.cache/tfvars
|
||||
1
history/uptimes/.project_root
Normal file
1
history/uptimes/.project_root
Normal file
@@ -0,0 +1 @@
|
||||
/Users/bob/git/dxw/uptimes
|
||||
1
installation_id
Normal file
1
installation_id
Normal file
@@ -0,0 +1 @@
|
||||
a7b0d610-c320-4539-8219-c16d8c3509d3
|
||||
19
projects.json
Normal file
19
projects.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"projects": {
|
||||
"/Users/bob/git/rjw1/sympl-config": "sympl-config",
|
||||
"/Users/bob/git/dxw/uptimes": "uptimes",
|
||||
"/Users/bob/git/dxw/dalmatian": "dalmatian",
|
||||
"/Users/bob/git/dxw/find-security-updates": "find-security-updates",
|
||||
"/Users/bob/git/dxw/baspress": "baspress",
|
||||
"/Users/bob/dxw/gemini-developmnet": "gemini-developmnet",
|
||||
"/Users/bob/.gemini": "gemini",
|
||||
"/Users/bob/git/dxw/aws-stuff": "aws-stuff",
|
||||
"/Users/bob/git/dxw/discovery_policy_atlas/backend/supabase": "supabase",
|
||||
"/Users/bob/git/dxw/natcen": "natcen",
|
||||
"/Users/bob/git/rjw1/beer-list": "beer-list",
|
||||
"/Users/bob/git/rjw1/randomness-puppet": "randomness-puppet",
|
||||
"/Users/bob/git/dxw/terraform-dxw-dalmatian-infrastructure": "terraform-dxw-dalmatian-infrastructure",
|
||||
"/Users/bob/git/dxw/dalmatian-config": "dalmatian-config",
|
||||
"/Users/bob/.config/dalmatian/.cache/tfvars": "tfvars"
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,12 @@
|
||||
"general": {
|
||||
"preferredEditor": "neovim",
|
||||
"previewFeatures": true,
|
||||
"enablePromptCompletion": true
|
||||
"enablePromptCompletion": true,
|
||||
"sessionRetention": {
|
||||
"warningAcknowledged": true,
|
||||
"enabled": true,
|
||||
"maxAge": "3650d"
|
||||
}
|
||||
},
|
||||
"context": {
|
||||
"fileName": [
|
||||
@@ -31,9 +36,38 @@
|
||||
"tools": {
|
||||
"shell": {
|
||||
"showColor": true
|
||||
}
|
||||
},
|
||||
"enableHooks": true
|
||||
},
|
||||
"ui": {
|
||||
"showStatusInTitle": true
|
||||
},
|
||||
"hooks": {
|
||||
"Notification": [
|
||||
{
|
||||
"matcher": "",
|
||||
"hooks": [
|
||||
{
|
||||
"name": "code-notify-notification",
|
||||
"type": "command",
|
||||
"command": "/opt/homebrew/lib/code-notify/core/notifier.sh notification gemini",
|
||||
"description": "Desktop notification when input needed"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"AfterAgent": [
|
||||
{
|
||||
"matcher": "",
|
||||
"hooks": [
|
||||
{
|
||||
"name": "code-notify-complete",
|
||||
"type": "command",
|
||||
"command": "/opt/homebrew/lib/code-notify/core/notifier.sh stop gemini",
|
||||
"description": "Desktop notification when task complete"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1
tmp/aws-stuff/.project_root
Normal file
1
tmp/aws-stuff/.project_root
Normal file
@@ -0,0 +1 @@
|
||||
/Users/bob/git/dxw/aws-stuff
|
||||
8
tmp/aws-stuff/backup.env
Normal file
8
tmp/aws-stuff/backup.env
Normal file
@@ -0,0 +1,8 @@
|
||||
# Parent AWS profile for Organizations and SSO login
|
||||
AWS_PARENT_PROFILE=dxw.admin
|
||||
|
||||
# AWS Organization Unit IDs to scan (comma-separated)
|
||||
OU_IDS=ou-h0vo-32wgvd6w,ou-h0vo-0waugyoz
|
||||
|
||||
# AWS Account IDs to skip (comma-separated)
|
||||
# SKIP_ACCOUNTS=123456789012,987654321098
|
||||
953
tmp/aws-stuff/chats/session-2026-01-28T16-26-a4c15690.json
Normal file
953
tmp/aws-stuff/chats/session-2026-01-28T16-26-a4c15690.json
Normal file
File diff suppressed because one or more lines are too long
600
tmp/aws-stuff/chats/session-2026-02-11T17-20-04a4103e.json
Normal file
600
tmp/aws-stuff/chats/session-2026-02-11T17-20-04a4103e.json
Normal file
@@ -0,0 +1,600 @@
|
||||
{
|
||||
"sessionId": "04a4103e-2b12-4236-8ee4-6b36061a0d17",
|
||||
"projectHash": "c4ece9c032ac20d038bbd73e9aa5f86cb3fd24c826b8e99b6edcd77db288fcb1",
|
||||
"startTime": "2026-02-11T17:21:11.711Z",
|
||||
"lastUpdated": "2026-02-11T17:31:51.952Z",
|
||||
"messages": [
|
||||
{
|
||||
"id": "fee3ca2e-5206-4ed0-a8e2-43b983a638d1",
|
||||
"timestamp": "2026-02-11T17:21:11.711Z",
|
||||
"type": "info",
|
||||
"content": "Gemini CLI update available! 0.28.0 → 0.28.1\nInstalled via Homebrew. Please update with \"brew upgrade gemini-cli\"."
|
||||
},
|
||||
{
|
||||
"id": "78ca9582-44f6-4284-a5f2-3001a735a938",
|
||||
"timestamp": "2026-02-11T17:21:43.179Z",
|
||||
"type": "user",
|
||||
"content": [
|
||||
{
|
||||
"text": "write a script which tells me the average bandwidth usage over the last 12 months for an account. see @bwsuage.py for how we work out bandwidth"
|
||||
},
|
||||
{
|
||||
"text": "\n--- Content from referenced files ---"
|
||||
},
|
||||
{
|
||||
"text": "\nContent from @bwsuage.py:\n"
|
||||
},
|
||||
{
|
||||
"text": "import boto3\nfrom datetime import datetime, timedelta\n\ndef get_all_accounts():\n \"\"\"Fetches every account ID and Name in the organization.\"\"\"\n org_client = boto3.client('organizations')\n account_map = {}\n try:\n paginator = org_client.get_paginator('list_accounts')\n for page in paginator.paginate():\n for account in page['Accounts']:\n # Only include active accounts to avoid confusion\n if account['Status'] == 'ACTIVE':\n account_map[account['Id']] = account['Name']\n except Exception as e:\n print(f\"Error fetching account list: {e}\")\n return account_map\n\ndef get_total_bandwidth_report(threshold_gb=100.0):\n ce_client = boto3.client('ce')\n \n # 1. Get the master list of all accounts\n all_accounts = get_all_accounts()\n if not all_accounts:\n print(\"Could not retrieve account list. Check Organizations permissions.\")\n return\n\n # 2. Set dates for previous month\n now = datetime.now()\n first_day_current = now.replace(day=1)\n last_day_prev = first_day_current - timedelta(days=1)\n start_date = last_day_prev.replace(day=1).strftime('%Y-%m-%d')\n end_date = first_day_current.strftime('%Y-%m-%d')\n\n # 3. Initialize tracking for all accounts at 0.0\n account_totals = {acc_id: 0.0 for acc_id in all_accounts.keys()}\n \n next_token = None\n\n try:\n # 4. Query Cost Explorer (with pagination)\n while True:\n params = {\n 'TimePeriod': {'Start': start_date, 'End': end_date},\n 'Granularity': 'MONTHLY',\n 'Metrics': ['UsageQuantity'],\n 'GroupBy': [\n {'Type': 'DIMENSION', 'Key': 'LINKED_ACCOUNT'},\n {'Type': 'DIMENSION', 'Key': 'USAGE_TYPE'}\n ]\n }\n if next_token:\n params['NextPageToken'] = next_token\n\n response = ce_client.get_cost_and_usage(**params)\n\n for result in response['ResultsByTime']:\n for group in result['Groups']:\n acc_id = group['Keys'][0]\n usage_type = group['Keys'][1]\n usage_amount = float(group['Metrics']['UsageQuantity']['Amount'])\n unit = group['Metrics']['UsageQuantity']['Unit']\n\n # Broad filter for Data Transfer\n if \"DataTransfer\" in usage_type:\n if unit == 'Bytes':\n usage_amount /= (1024**3)\n elif unit in ['MB', 'Megabytes']:\n usage_amount /= 1024\n \n # Add to total if account exists in our master list\n if acc_id in account_totals:\n account_totals[acc_id] += usage_amount\n else:\n # Account might have been deleted/closed but has historical data\n account_totals[acc_id] = usage_amount\n\n next_token = response.get('NextPageToken')\n if not next_token:\n break\n\n # 5. Generate the Final Report\n print(f\"\\n--- Full Bandwidth Report (Incl. 0 Usage) ---\")\n print(f\"Period: {start_date} to {last_day_prev.strftime('%Y-%m-%d')}\")\n print(f\"{'Account Name':<25} | {'Total GB':<12} | {'Overage (>100GB)'}\")\n print(\"-\" * 75)\n\n # Sort: Highest usage first, then alphabetically for 0-usage accounts\n sorted_accounts = sorted(\n account_totals.items(), \n key=lambda x: (x[1], all_accounts.get(x[0], x[0])), \n reverse=True\n )\n \n for acc_id, total_usage in sorted_accounts:\n acc_name = all_accounts.get(acc_id, f\"Deleted/Unknown ({acc_id})\")\n overage = max(0, total_usage - threshold_gb)\n \n status_icon = \"⚠️\" if overage > 0 else \"✅\"\n usage_str = f\"{total_usage:>10.2f} GB\"\n overage_str = f\"{overage:>8.2f} GB {status_icon}\"\n \n # Highlight accounts with actual usage\n print(f\"{acc_name[:25]:<25} | {usage_str} | {overage_str}\")\n\n print(f\"\\nTotal Accounts Scanned: {len(all_accounts)}\")\n print(f\"Accounts with >0 usage: {len([v for v in account_totals.values() if v > 0])}\")\n\n except Exception as e:\n print(f\"Error: {e}\")\n\nif __name__ == \"__main__\":\n get_total_bandwidth_report(100.0)"
|
||||
},
|
||||
{
|
||||
"text": "\n--- End of content ---"
|
||||
}
|
||||
],
|
||||
"displayContent": [
|
||||
{
|
||||
"text": "write a script which tells me the average bandwidth usage over the last 12 months for an account. see @bwsuage.py for how we work out bandwidth"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "7d7eb510-dd7e-401f-90af-7afea89b18b9",
|
||||
"timestamp": "2026-02-11T17:22:03.152Z",
|
||||
"type": "gemini",
|
||||
"content": "I will create a new script named `avg_bandwidth_12months.py` that calculates the average monthly bandwidth usage for each account in your organization over the last 12 months, following the bandwidth calculation logic found in `bwsuage.py`.",
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Calculating AWS Bandwidth",
|
||||
"description": "I'm focusing on crafting a script to determine average bandwidth consumption across an AWS account for the past year. I'm leveraging `bwusage.py` as a blueprint, which utilizes the Cost Explorer API's `get_cost_and_usage` to analyze `USAGE_TYPE` data, specifically filtering for \"DataTransfer\" to capture relevant bandwidth metrics.",
|
||||
"timestamp": "2026-02-11T17:21:52.131Z"
|
||||
},
|
||||
{
|
||||
"subject": "Developing the Core Logic",
|
||||
"description": "I'm now zeroing in on the script's core functionality. I'm leveraging `bwusage.py`'s framework, using the Cost Explorer API and `boto3`. My current focus is crafting the function to retrieve 12 months of bandwidth data, using the \"DataTransfer\" `USAGE_TYPE` and `LINKED_ACCOUNT` dimensions. I'm working through date calculations to ensure precise monthly periods and plan to aggregate the data before averaging.",
|
||||
"timestamp": "2026-02-11T17:21:54.495Z"
|
||||
},
|
||||
{
|
||||
"subject": "Querying Cost Explorer Details",
|
||||
"description": "I'm now going deeper into the specific Cost Explorer calls. The key is correctly formatting the date ranges and understanding how `bwusage.py` filters for \"DataTransfer\" types and converts units. I've pinpointed the `get_cost_and_usage` parameters and am focusing on setting `Granularity='MONTHLY'` to streamline the data retrieval for the 12-month period. I'm also ensuring proper handling of Bytes/MB to GB conversions, matching the existing logic.",
|
||||
"timestamp": "2026-02-11T17:21:57.807Z"
|
||||
},
|
||||
{
|
||||
"subject": "Constructing the Core Script",
|
||||
"description": "I'm now outlining the script structure, naming it `avg_bandwidth_12months.py`. The fundamental approach mirrors `bwusage.py`, but will use a 12-month period for calculation. I will query the Cost Explorer for each account, applying the unit conversion logic from the reference script. The structure includes account retrieval, date range computation, Cost Explorer queries, and averaging the data to fulfill the user's requirements.",
|
||||
"timestamp": "2026-02-11T17:21:57.825Z"
|
||||
}
|
||||
],
|
||||
"tokens": {
|
||||
"input": 16102,
|
||||
"output": 1104,
|
||||
"cached": 0,
|
||||
"thoughts": 776,
|
||||
"tool": 0,
|
||||
"total": 17982
|
||||
},
|
||||
"model": "gemini-3-flash-preview",
|
||||
"toolCalls": [
|
||||
{
|
||||
"id": "write_file-1770830523150-548649ad8745d8",
|
||||
"name": "write_file",
|
||||
"args": {
|
||||
"file_path": "avg_bandwidth_12months.py",
|
||||
"content": "import boto3\nfrom datetime import datetime, timedelta\nfrom dateutil.relativedelta import relativedelta\n\ndef get_all_accounts():\n \"\"\"Fetches every account ID and Name in the organization.\"\"\"\n org_client = boto3.client('organizations')\n account_map = {}\n try:\n paginator = org_client.get_paginator('list_accounts')\n for page in paginator.paginate():\n for account in page['Accounts']:\n if account['Status'] == 'ACTIVE':\n account_map[account['Id']] = account['Name']\n except Exception as e:\n print(f\"Error fetching account list: {e}\")\n return account_map\n\ndef get_average_bandwidth_report():\n ce_client = boto3.client('ce')\n \n all_accounts = get_all_accounts()\n if not all_accounts:\n print(\"Could not retrieve account list. Check Organizations permissions.\")\n return\n\n # Set dates for the last 12 full months\n now = datetime.now()\n first_day_current_month = now.replace(day=1)\n end_date = first_day_current_month.strftime('%Y-%m-%d')\n start_date = (first_day_current_month - relativedelta(months=12)).strftime('%Y-%m-%d')\n\n # Initialize tracking: {acc_id: [usage_month1, usage_month2, ...]}\n # Actually, we can just track the total and divide by 12 at the end\n account_totals = {acc_id: 0.0 for acc_id in all_accounts.keys()}\n \n next_token = None\n\n try:\n while True:\n params = {\n 'TimePeriod': {'Start': start_date, 'End': end_date},\n 'Granularity': 'MONTHLY',\n 'Metrics': ['UsageQuantity'],\n 'GroupBy': [\n {'Type': 'DIMENSION', 'Key': 'LINKED_ACCOUNT'},\n {'Type': 'DIMENSION', 'Key': 'USAGE_TYPE'}\n ]\n }\n if next_token:\n params['NextPageToken'] = next_token\n\n response = ce_client.get_cost_and_usage(**params)\n\n for result in response['ResultsByTime']:\n for group in result['Groups']:\n acc_id = group['Keys'][0]\n usage_type = group['Keys'][1]\n usage_amount = float(group['Metrics']['UsageQuantity']['Amount'])\n unit = group['Metrics']['UsageQuantity']['Unit']\n\n # Bandwidth calculation logic from bwsuage.py\n if \"DataTransfer\" in usage_type:\n if unit == 'Bytes':\n usage_amount /= (1024**3)\n elif unit in ['MB', 'Megabytes']:\n usage_amount /= 1024\n \n if acc_id in account_totals:\n account_totals[acc_id] += usage_amount\n else:\n account_totals[acc_id] = usage_amount\n\n next_token = response.get('NextPageToken')\n if not next_token:\n break\n\n print(f\"\\n--- 12-Month Average Bandwidth Report ---\")\n print(f\"Period: {start_date} to {end_date}\")\n print(f\"{'Account Name':<25} | {'12m Total (GB)':<15} | {'Monthly Avg (GB)'}\")\n print(\"-\" * 75)\n\n # Sort by monthly average descending\n sorted_accounts = sorted(\n account_totals.items(), \n key=lambda x: x[1], \n reverse=True\n )\n \n for acc_id, total_usage in sorted_accounts:\n acc_name = all_accounts.get(acc_id, f\"Deleted/Unknown ({acc_id})\")\n avg_usage = total_usage / 12.0\n \n print(f\"{acc_name[:25]:<25} | {total_usage:>15.2f} | {avg_usage:>16.2f}\")\n\n print(f\"\\nTotal Accounts Scanned: {len(all_accounts)}\")\n\n except Exception as e:\n print(f\"Error: {e}\")\n\nif __name__ == \"__main__\":\n get_average_bandwidth_report()\n"
|
||||
},
|
||||
"result": [
|
||||
{
|
||||
"functionResponse": {
|
||||
"id": "write_file-1770830523150-548649ad8745d8",
|
||||
"name": "write_file",
|
||||
"response": {
|
||||
"output": "Successfully created and wrote to new file: /Users/bob/git/dxw/aws-stuff/avg_bandwidth_12months.py."
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": "success",
|
||||
"timestamp": "2026-02-11T17:22:49.123Z",
|
||||
"resultDisplay": {
|
||||
"fileDiff": "Index: avg_bandwidth_12months.py\n===================================================================\n--- avg_bandwidth_12months.py\tOriginal\n+++ avg_bandwidth_12months.py\tWritten\n@@ -0,0 +1,104 @@\n+import boto3\n+from datetime import datetime, timedelta\n+from dateutil.relativedelta import relativedelta\n+\n+def get_all_accounts():\n+ \"\"\"Fetches every account ID and Name in the organization.\"\"\"\n+ org_client = boto3.client('organizations')\n+ account_map = {}\n+ try:\n+ paginator = org_client.get_paginator('list_accounts')\n+ for page in paginator.paginate():\n+ for account in page['Accounts']:\n+ if account['Status'] == 'ACTIVE':\n+ account_map[account['Id']] = account['Name']\n+ except Exception as e:\n+ print(f\"Error fetching account list: {e}\")\n+ return account_map\n+\n+def get_average_bandwidth_report():\n+ ce_client = boto3.client('ce')\n+ \n+ all_accounts = get_all_accounts()\n+ if not all_accounts:\n+ print(\"Could not retrieve account list. Check Organizations permissions.\")\n+ return\n+\n+ # Set dates for the last 12 full months\n+ now = datetime.now()\n+ first_day_current_month = now.replace(day=1)\n+ end_date = first_day_current_month.strftime('%Y-%m-%d')\n+ start_date = (first_day_current_month - relativedelta(months=12)).strftime('%Y-%m-%d')\n+\n+ # Initialize tracking: {acc_id: [usage_month1, usage_month2, ...]}\n+ # Actually, we can just track the total and divide by 12 at the end\n+ account_totals = {acc_id: 0.0 for acc_id in all_accounts.keys()}\n+ \n+ next_token = None\n+\n+ try:\n+ while True:\n+ params = {\n+ 'TimePeriod': {'Start': start_date, 'End': end_date},\n+ 'Granularity': 'MONTHLY',\n+ 'Metrics': ['UsageQuantity'],\n+ 'GroupBy': [\n+ {'Type': 'DIMENSION', 'Key': 'LINKED_ACCOUNT'},\n+ {'Type': 'DIMENSION', 'Key': 'USAGE_TYPE'}\n+ ]\n+ }\n+ if next_token:\n+ params['NextPageToken'] = next_token\n+\n+ response = ce_client.get_cost_and_usage(**params)\n+\n+ for result in response['ResultsByTime']:\n+ for group in result['Groups']:\n+ acc_id = group['Keys'][0]\n+ usage_type = group['Keys'][1]\n+ usage_amount = float(group['Metrics']['UsageQuantity']['Amount'])\n+ unit = group['Metrics']['UsageQuantity']['Unit']\n+\n+ # Bandwidth calculation logic from bwsuage.py\n+ if \"DataTransfer\" in usage_type:\n+ if unit == 'Bytes':\n+ usage_amount /= (1024**3)\n+ elif unit in ['MB', 'Megabytes']:\n+ usage_amount /= 1024\n+ \n+ if acc_id in account_totals:\n+ account_totals[acc_id] += usage_amount\n+ else:\n+ account_totals[acc_id] = usage_amount\n+\n+ next_token = response.get('NextPageToken')\n+ if not next_token:\n+ break\n+\n+ print(f\"\n+--- 12-Month Average Bandwidth Report ---\")\n+ print(f\"Period: {start_date} to {end_date}\")\n+ print(f\"{'Account Name':<25} | {'12m Total (GB)':<15} | {'Monthly Avg (GB)'}\")\n+ print(\"-\" * 75)\n+\n+ # Sort by monthly average descending\n+ sorted_accounts = sorted(\n+ account_totals.items(), \n+ key=lambda x: x[1], \n+ reverse=True\n+ )\n+ \n+ for acc_id, total_usage in sorted_accounts:\n+ acc_name = all_accounts.get(acc_id, f\"Deleted/Unknown ({acc_id})\")\n+ avg_usage = total_usage / 12.0\n+ \n+ print(f\"{acc_name[:25]:<25} | {total_usage:>15.2f} | {avg_usage:>16.2f}\")\n+\n+ print(f\"\n+Total Accounts Scanned: {len(all_accounts)}\")\n+\n+ except Exception as e:\n+ print(f\"Error: {e}\")\n+\n+if __name__ == \"__main__\":\n+ get_average_bandwidth_report()\n",
|
||||
"fileName": "avg_bandwidth_12months.py",
|
||||
"filePath": "/Users/bob/git/dxw/aws-stuff/avg_bandwidth_12months.py",
|
||||
"originalContent": "",
|
||||
"newContent": "import boto3\nfrom datetime import datetime, timedelta\nfrom dateutil.relativedelta import relativedelta\n\ndef get_all_accounts():\n \"\"\"Fetches every account ID and Name in the organization.\"\"\"\n org_client = boto3.client('organizations')\n account_map = {}\n try:\n paginator = org_client.get_paginator('list_accounts')\n for page in paginator.paginate():\n for account in page['Accounts']:\n if account['Status'] == 'ACTIVE':\n account_map[account['Id']] = account['Name']\n except Exception as e:\n print(f\"Error fetching account list: {e}\")\n return account_map\n\ndef get_average_bandwidth_report():\n ce_client = boto3.client('ce')\n \n all_accounts = get_all_accounts()\n if not all_accounts:\n print(\"Could not retrieve account list. Check Organizations permissions.\")\n return\n\n # Set dates for the last 12 full months\n now = datetime.now()\n first_day_current_month = now.replace(day=1)\n end_date = first_day_current_month.strftime('%Y-%m-%d')\n start_date = (first_day_current_month - relativedelta(months=12)).strftime('%Y-%m-%d')\n\n # Initialize tracking: {acc_id: [usage_month1, usage_month2, ...]}\n # Actually, we can just track the total and divide by 12 at the end\n account_totals = {acc_id: 0.0 for acc_id in all_accounts.keys()}\n \n next_token = None\n\n try:\n while True:\n params = {\n 'TimePeriod': {'Start': start_date, 'End': end_date},\n 'Granularity': 'MONTHLY',\n 'Metrics': ['UsageQuantity'],\n 'GroupBy': [\n {'Type': 'DIMENSION', 'Key': 'LINKED_ACCOUNT'},\n {'Type': 'DIMENSION', 'Key': 'USAGE_TYPE'}\n ]\n }\n if next_token:\n params['NextPageToken'] = next_token\n\n response = ce_client.get_cost_and_usage(**params)\n\n for result in response['ResultsByTime']:\n for group in result['Groups']:\n acc_id = group['Keys'][0]\n usage_type = group['Keys'][1]\n usage_amount = float(group['Metrics']['UsageQuantity']['Amount'])\n unit = group['Metrics']['UsageQuantity']['Unit']\n\n # Bandwidth calculation logic from bwsuage.py\n if \"DataTransfer\" in usage_type:\n if unit == 'Bytes':\n usage_amount /= (1024**3)\n elif unit in ['MB', 'Megabytes']:\n usage_amount /= 1024\n \n if acc_id in account_totals:\n account_totals[acc_id] += usage_amount\n else:\n account_totals[acc_id] = usage_amount\n\n next_token = response.get('NextPageToken')\n if not next_token:\n break\n\n print(f\"\n--- 12-Month Average Bandwidth Report ---\")\n print(f\"Period: {start_date} to {end_date}\")\n print(f\"{'Account Name':<25} | {'12m Total (GB)':<15} | {'Monthly Avg (GB)'}\")\n print(\"-\" * 75)\n\n # Sort by monthly average descending\n sorted_accounts = sorted(\n account_totals.items(), \n key=lambda x: x[1], \n reverse=True\n )\n \n for acc_id, total_usage in sorted_accounts:\n acc_name = all_accounts.get(acc_id, f\"Deleted/Unknown ({acc_id})\")\n avg_usage = total_usage / 12.0\n \n print(f\"{acc_name[:25]:<25} | {total_usage:>15.2f} | {avg_usage:>16.2f}\")\n\n print(f\"\nTotal Accounts Scanned: {len(all_accounts)}\")\n\n except Exception as e:\n print(f\"Error: {e}\")\n\nif __name__ == \"__main__\":\n get_average_bandwidth_report()\n",
|
||||
"diffStat": {
|
||||
"model_added_lines": 102,
|
||||
"model_removed_lines": 0,
|
||||
"model_added_chars": 3733,
|
||||
"model_removed_chars": 0,
|
||||
"user_added_lines": 0,
|
||||
"user_removed_lines": 0,
|
||||
"user_added_chars": 0,
|
||||
"user_removed_chars": 0
|
||||
},
|
||||
"isNewFile": true
|
||||
},
|
||||
"displayName": "WriteFile",
|
||||
"description": "Writes content to a specified file in the local filesystem.\n\n The user has the ability to modify `content`. If modified, this will be stated in the response.",
|
||||
"renderOutputAsMarkdown": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "6d14026d-635c-45d3-949f-60372ec946b3",
|
||||
"timestamp": "2026-02-11T17:23:10.614Z",
|
||||
"type": "gemini",
|
||||
"content": "I have created the script `avg_bandwidth_12months.py`. It uses the Cost Explorer API to fetch data transfer usage for the last 12 full months, aggregates it by account, and calculates the monthly average.",
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Verifying the Script's Execution",
|
||||
"description": "I've written the script and now need to ensure it runs correctly, looking for potential errors. I'm focusing on the `dateutil` dependency and whether it is present. The file structure is being used to find the right files to check.",
|
||||
"timestamp": "2026-02-11T17:23:07.084Z"
|
||||
},
|
||||
{
|
||||
"subject": "Validating Script Functionality",
|
||||
"description": "I've reviewed the script's core components, concentrating on the intended data transfer aggregation using Cost Explorer. I'm verifying the 12-month range calculation and confirm that it aggregates \"DataTransfer\" and calculates the average. My current focus is refining the output and ensuring clarity between total, average, and any threshold criteria from the original script that may need removing.",
|
||||
"timestamp": "2026-02-11T17:23:09.420Z"
|
||||
},
|
||||
{
|
||||
"subject": "Checking the Script's Integrity",
|
||||
"description": "I've confirmed the `dateutil` dependency's presence within the virtual environment, cross-referencing file paths to ensure `python-dateutil` is installed. I ran a mental audit of the core features and the logic, paying close attention to the bandwidth calculations and their consistency with the prior script. I then ran a syntax check using `python3 -m py_compile`, to identify any potential initial problems.",
|
||||
"timestamp": "2026-02-11T17:23:10.360Z"
|
||||
}
|
||||
],
|
||||
"tokens": {
|
||||
"input": 17238,
|
||||
"output": 85,
|
||||
"cached": 0,
|
||||
"thoughts": 496,
|
||||
"tool": 0,
|
||||
"total": 17819
|
||||
},
|
||||
"model": "gemini-3-flash-preview",
|
||||
"toolCalls": [
|
||||
{
|
||||
"id": "run_shell_command-1770830590612-1fc8eabce8188",
|
||||
"name": "run_shell_command",
|
||||
"args": {
|
||||
"command": "python3 -m py_compile avg_bandwidth_12months.py",
|
||||
"description": "Check for syntax errors in the newly created script."
|
||||
},
|
||||
"result": [
|
||||
{
|
||||
"functionResponse": {
|
||||
"id": "run_shell_command-1770830590612-1fc8eabce8188",
|
||||
"name": "run_shell_command",
|
||||
"response": {
|
||||
"output": "Output: File \"avg_bandwidth_12months.py\", line 78\n print(f\"\n ^\nSyntaxError: unterminated f-string literal (detected at line 78)\nExit Code: 1\nProcess Group PGID: 58895"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": "success",
|
||||
"timestamp": "2026-02-11T17:23:25.635Z",
|
||||
"resultDisplay": " File \"avg_bandwidth_12months.py\", line 78\n print(f\"\n ^\nSyntaxError: unterminated f-string literal (detected at line 78)",
|
||||
"displayName": "Shell",
|
||||
"description": "This tool executes a given shell command as `bash -c <command>`. To run a command in the background, set the `is_background` parameter to true. Do NOT use `&` to background commands. Command is executed as a subprocess that leads its own process group. Command process group can be terminated as `kill -- -PGID` or signaled as `kill -s SIGNAL -- -PGID`.\n\n The following information is returned:\n\n Output: Combined stdout/stderr. Can be `(empty)` or partial on error and for any unwaited background processes.\n Exit Code: Only included if non-zero (command failed).\n Error: Only included if a process-level error occurred (e.g., spawn failure).\n Signal: Only included if process was terminated by a signal.\n Background PIDs: Only included if background processes were started.\n Process Group PGID: Only included if available.",
|
||||
"renderOutputAsMarkdown": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "a277c63f-f8a1-4d2d-a49c-63a4e9567cbe",
|
||||
"timestamp": "2026-02-11T17:24:50.127Z",
|
||||
"type": "gemini",
|
||||
"content": "I'll read the file to identify and fix the syntax error.",
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Analyzing the Code",
|
||||
"description": "I've identified a syntax error, likely in the print statement near line 78. Now, I'm examining the `write_file` call, specifically the print statement where the error occurred. I'll read the file content to understand the context fully.",
|
||||
"timestamp": "2026-02-11T17:24:49.876Z"
|
||||
},
|
||||
{
|
||||
"subject": "Checking File Contents",
|
||||
"description": "Okay, I just re-read the relevant part of the file. The syntax error is definitely in that print statement on line 78. Now I'll trace back through the `write_file` function to understand why that print statement failed, and why it's there.",
|
||||
"timestamp": "2026-02-11T17:24:49.891Z"
|
||||
}
|
||||
],
|
||||
"tokens": {
|
||||
"input": 17390,
|
||||
"output": 34,
|
||||
"cached": 0,
|
||||
"thoughts": 72,
|
||||
"tool": 0,
|
||||
"total": 17496
|
||||
},
|
||||
"model": "gemini-3-flash-preview",
|
||||
"toolCalls": [
|
||||
{
|
||||
"id": "read_file-1770830690126-7b3665f2dd302",
|
||||
"name": "read_file",
|
||||
"args": {
|
||||
"file_path": "avg_bandwidth_12months.py"
|
||||
},
|
||||
"result": [
|
||||
{
|
||||
"functionResponse": {
|
||||
"id": "read_file-1770830690126-7b3665f2dd302",
|
||||
"name": "read_file",
|
||||
"response": {
|
||||
"output": "import boto3\nfrom datetime import datetime, timedelta\nfrom dateutil.relativedelta import relativedelta\n\ndef get_all_accounts():\n \"\"\"Fetches every account ID and Name in the organization.\"\"\"\n org_client = boto3.client('organizations')\n account_map = {}\n try:\n paginator = org_client.get_paginator('list_accounts')\n for page in paginator.paginate():\n for account in page['Accounts']:\n if account['Status'] == 'ACTIVE':\n account_map[account['Id']] = account['Name']\n except Exception as e:\n print(f\"Error fetching account list: {e}\")\n return account_map\n\ndef get_average_bandwidth_report():\n ce_client = boto3.client('ce')\n \n all_accounts = get_all_accounts()\n if not all_accounts:\n print(\"Could not retrieve account list. Check Organizations permissions.\")\n return\n\n # Set dates for the last 12 full months\n now = datetime.now()\n first_day_current_month = now.replace(day=1)\n end_date = first_day_current_month.strftime('%Y-%m-%d')\n start_date = (first_day_current_month - relativedelta(months=12)).strftime('%Y-%m-%d')\n\n # Initialize tracking: {acc_id: [usage_month1, usage_month2, ...]}\n # Actually, we can just track the total and divide by 12 at the end\n account_totals = {acc_id: 0.0 for acc_id in all_accounts.keys()}\n \n next_token = None\n\n try:\n while True:\n params = {\n 'TimePeriod': {'Start': start_date, 'End': end_date},\n 'Granularity': 'MONTHLY',\n 'Metrics': ['UsageQuantity'],\n 'GroupBy': [\n {'Type': 'DIMENSION', 'Key': 'LINKED_ACCOUNT'},\n {'Type': 'DIMENSION', 'Key': 'USAGE_TYPE'}\n ]\n }\n if next_token:\n params['NextPageToken'] = next_token\n\n response = ce_client.get_cost_and_usage(**params)\n\n for result in response['ResultsByTime']:\n for group in result['Groups']:\n acc_id = group['Keys'][0]\n usage_type = group['Keys'][1]\n usage_amount = float(group['Metrics']['UsageQuantity']['Amount'])\n unit = group['Metrics']['UsageQuantity']['Unit']\n\n # Bandwidth calculation logic from bwsuage.py\n if \"DataTransfer\" in usage_type:\n if unit == 'Bytes':\n usage_amount /= (1024**3)\n elif unit in ['MB', 'Megabytes']:\n usage_amount /= 1024\n \n if acc_id in account_totals:\n account_totals[acc_id] += usage_amount\n else:\n account_totals[acc_id] = usage_amount\n\n next_token = response.get('NextPageToken')\n if not next_token:\n break\n\n print(f\"\n--- 12-Month Average Bandwidth Report ---\")\n print(f\"Period: {start_date} to {end_date}\")\n print(f\"{'Account Name':<25} | {'12m Total (GB)':<15} | {'Monthly Avg (GB)'}\")\n print(\"-\" * 75)\n\n # Sort by monthly average descending\n sorted_accounts = sorted(\n account_totals.items(), \n key=lambda x: x[1], \n reverse=True\n )\n \n for acc_id, total_usage in sorted_accounts:\n acc_name = all_accounts.get(acc_id, f\"Deleted/Unknown ({acc_id})\")\n avg_usage = total_usage / 12.0\n \n print(f\"{acc_name[:25]:<25} | {total_usage:>15.2f} | {avg_usage:>16.2f}\")\n\n print(f\"\nTotal Accounts Scanned: {len(all_accounts)}\")\n\n except Exception as e:\n print(f\"Error: {e}\")\n\nif __name__ == \"__main__\":\n get_average_bandwidth_report()\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": "success",
|
||||
"timestamp": "2026-02-11T17:24:50.145Z",
|
||||
"resultDisplay": "",
|
||||
"displayName": "ReadFile",
|
||||
"description": "Reads and returns the content of a specified file. If the file is large, the content will be truncated. The tool's response will clearly indicate if truncation has occurred and will provide details on how to read more of the file using the 'offset' and 'limit' parameters. Handles text, images (PNG, JPG, GIF, WEBP, SVG, BMP), audio files (MP3, WAV, AIFF, AAC, OGG, FLAC), and PDF files. For text files, it can read specific line ranges.",
|
||||
"renderOutputAsMarkdown": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "5167bfc9-a166-4aec-bf2a-b2ae0a9360d0",
|
||||
"timestamp": "2026-02-11T17:25:46.587Z",
|
||||
"type": "gemini",
|
||||
"content": "I'll fix the syntax errors by correcting the broken f-strings.",
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Correcting the output",
|
||||
"description": "I'm zeroing in on the file output formatting. The f-string interpretation caused some issues with line breaks. My plan is to rectify the situation by employing the `replace` function to correctly insert the newline characters. This should ensure the output is properly formatted.",
|
||||
"timestamp": "2026-02-11T17:25:46.284Z"
|
||||
}
|
||||
],
|
||||
"tokens": {
|
||||
"input": 18454,
|
||||
"output": 152,
|
||||
"cached": 0,
|
||||
"thoughts": 128,
|
||||
"tool": 0,
|
||||
"total": 18734
|
||||
},
|
||||
"model": "gemini-3-flash-preview",
|
||||
"toolCalls": [
|
||||
{
|
||||
"id": "replace-1770830746581-9d7cac6df02ff",
|
||||
"name": "replace",
|
||||
"args": {
|
||||
"old_string": " if not next_token:\n break\n\n print(f\"\n--- 12-Month Average Bandwidth Report ---\")\n print(f\"Period: {start_date} to {end_date}\")",
|
||||
"file_path": "/Users/bob/git/dxw/aws-stuff/avg_bandwidth_12months.py",
|
||||
"expected_replacements": 1,
|
||||
"instruction": "Fix the broken f-string in the report header.",
|
||||
"new_string": " if not next_token:\n break\n\n print(f\"\\n--- 12-Month Average Bandwidth Report ---\")\n print(f\"Period: {start_date} to {end_date}\")"
|
||||
},
|
||||
"result": [
|
||||
{
|
||||
"functionResponse": {
|
||||
"id": "replace-1770830746581-9d7cac6df02ff",
|
||||
"name": "replace",
|
||||
"response": {
|
||||
"output": "Successfully modified file: /Users/bob/git/dxw/aws-stuff/avg_bandwidth_12months.py (1 replacements)."
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": "success",
|
||||
"timestamp": "2026-02-11T17:26:19.438Z",
|
||||
"resultDisplay": {
|
||||
"fileDiff": "Index: avg_bandwidth_12months.py\n===================================================================\n--- avg_bandwidth_12months.py\tCurrent\n+++ avg_bandwidth_12months.py\tProposed\n@@ -75,8 +75,7 @@\n if not next_token:\n break\n \n- print(f\"\n---- 12-Month Average Bandwidth Report ---\")\n+ print(f\"\\n--- 12-Month Average Bandwidth Report ---\")\n print(f\"Period: {start_date} to {end_date}\")\n print(f\"{'Account Name':<25} | {'12m Total (GB)':<15} | {'Monthly Avg (GB)'}\")\n print(\"-\" * 75)\n",
|
||||
"fileName": "avg_bandwidth_12months.py",
|
||||
"filePath": "/Users/bob/git/dxw/aws-stuff/avg_bandwidth_12months.py",
|
||||
"originalContent": "import boto3\nfrom datetime import datetime, timedelta\nfrom dateutil.relativedelta import relativedelta\n\ndef get_all_accounts():\n \"\"\"Fetches every account ID and Name in the organization.\"\"\"\n org_client = boto3.client('organizations')\n account_map = {}\n try:\n paginator = org_client.get_paginator('list_accounts')\n for page in paginator.paginate():\n for account in page['Accounts']:\n if account['Status'] == 'ACTIVE':\n account_map[account['Id']] = account['Name']\n except Exception as e:\n print(f\"Error fetching account list: {e}\")\n return account_map\n\ndef get_average_bandwidth_report():\n ce_client = boto3.client('ce')\n \n all_accounts = get_all_accounts()\n if not all_accounts:\n print(\"Could not retrieve account list. Check Organizations permissions.\")\n return\n\n # Set dates for the last 12 full months\n now = datetime.now()\n first_day_current_month = now.replace(day=1)\n end_date = first_day_current_month.strftime('%Y-%m-%d')\n start_date = (first_day_current_month - relativedelta(months=12)).strftime('%Y-%m-%d')\n\n # Initialize tracking: {acc_id: [usage_month1, usage_month2, ...]}\n # Actually, we can just track the total and divide by 12 at the end\n account_totals = {acc_id: 0.0 for acc_id in all_accounts.keys()}\n \n next_token = None\n\n try:\n while True:\n params = {\n 'TimePeriod': {'Start': start_date, 'End': end_date},\n 'Granularity': 'MONTHLY',\n 'Metrics': ['UsageQuantity'],\n 'GroupBy': [\n {'Type': 'DIMENSION', 'Key': 'LINKED_ACCOUNT'},\n {'Type': 'DIMENSION', 'Key': 'USAGE_TYPE'}\n ]\n }\n if next_token:\n params['NextPageToken'] = next_token\n\n response = ce_client.get_cost_and_usage(**params)\n\n for result in response['ResultsByTime']:\n for group in result['Groups']:\n acc_id = group['Keys'][0]\n usage_type = group['Keys'][1]\n usage_amount = float(group['Metrics']['UsageQuantity']['Amount'])\n unit = group['Metrics']['UsageQuantity']['Unit']\n\n # Bandwidth calculation logic from bwsuage.py\n if \"DataTransfer\" in usage_type:\n if unit == 'Bytes':\n usage_amount /= (1024**3)\n elif unit in ['MB', 'Megabytes']:\n usage_amount /= 1024\n \n if acc_id in account_totals:\n account_totals[acc_id] += usage_amount\n else:\n account_totals[acc_id] = usage_amount\n\n next_token = response.get('NextPageToken')\n if not next_token:\n break\n\n print(f\"\n--- 12-Month Average Bandwidth Report ---\")\n print(f\"Period: {start_date} to {end_date}\")\n print(f\"{'Account Name':<25} | {'12m Total (GB)':<15} | {'Monthly Avg (GB)'}\")\n print(\"-\" * 75)\n\n # Sort by monthly average descending\n sorted_accounts = sorted(\n account_totals.items(), \n key=lambda x: x[1], \n reverse=True\n )\n \n for acc_id, total_usage in sorted_accounts:\n acc_name = all_accounts.get(acc_id, f\"Deleted/Unknown ({acc_id})\")\n avg_usage = total_usage / 12.0\n \n print(f\"{acc_name[:25]:<25} | {total_usage:>15.2f} | {avg_usage:>16.2f}\")\n\n print(f\"\nTotal Accounts Scanned: {len(all_accounts)}\")\n\n except Exception as e:\n print(f\"Error: {e}\")\n\nif __name__ == \"__main__\":\n get_average_bandwidth_report()\n",
|
||||
"newContent": "import boto3\nfrom datetime import datetime, timedelta\nfrom dateutil.relativedelta import relativedelta\n\ndef get_all_accounts():\n \"\"\"Fetches every account ID and Name in the organization.\"\"\"\n org_client = boto3.client('organizations')\n account_map = {}\n try:\n paginator = org_client.get_paginator('list_accounts')\n for page in paginator.paginate():\n for account in page['Accounts']:\n if account['Status'] == 'ACTIVE':\n account_map[account['Id']] = account['Name']\n except Exception as e:\n print(f\"Error fetching account list: {e}\")\n return account_map\n\ndef get_average_bandwidth_report():\n ce_client = boto3.client('ce')\n \n all_accounts = get_all_accounts()\n if not all_accounts:\n print(\"Could not retrieve account list. Check Organizations permissions.\")\n return\n\n # Set dates for the last 12 full months\n now = datetime.now()\n first_day_current_month = now.replace(day=1)\n end_date = first_day_current_month.strftime('%Y-%m-%d')\n start_date = (first_day_current_month - relativedelta(months=12)).strftime('%Y-%m-%d')\n\n # Initialize tracking: {acc_id: [usage_month1, usage_month2, ...]}\n # Actually, we can just track the total and divide by 12 at the end\n account_totals = {acc_id: 0.0 for acc_id in all_accounts.keys()}\n \n next_token = None\n\n try:\n while True:\n params = {\n 'TimePeriod': {'Start': start_date, 'End': end_date},\n 'Granularity': 'MONTHLY',\n 'Metrics': ['UsageQuantity'],\n 'GroupBy': [\n {'Type': 'DIMENSION', 'Key': 'LINKED_ACCOUNT'},\n {'Type': 'DIMENSION', 'Key': 'USAGE_TYPE'}\n ]\n }\n if next_token:\n params['NextPageToken'] = next_token\n\n response = ce_client.get_cost_and_usage(**params)\n\n for result in response['ResultsByTime']:\n for group in result['Groups']:\n acc_id = group['Keys'][0]\n usage_type = group['Keys'][1]\n usage_amount = float(group['Metrics']['UsageQuantity']['Amount'])\n unit = group['Metrics']['UsageQuantity']['Unit']\n\n # Bandwidth calculation logic from bwsuage.py\n if \"DataTransfer\" in usage_type:\n if unit == 'Bytes':\n usage_amount /= (1024**3)\n elif unit in ['MB', 'Megabytes']:\n usage_amount /= 1024\n \n if acc_id in account_totals:\n account_totals[acc_id] += usage_amount\n else:\n account_totals[acc_id] = usage_amount\n\n next_token = response.get('NextPageToken')\n if not next_token:\n break\n\n print(f\"\\n--- 12-Month Average Bandwidth Report ---\")\n print(f\"Period: {start_date} to {end_date}\")\n print(f\"{'Account Name':<25} | {'12m Total (GB)':<15} | {'Monthly Avg (GB)'}\")\n print(\"-\" * 75)\n\n # Sort by monthly average descending\n sorted_accounts = sorted(\n account_totals.items(), \n key=lambda x: x[1], \n reverse=True\n )\n \n for acc_id, total_usage in sorted_accounts:\n acc_name = all_accounts.get(acc_id, f\"Deleted/Unknown ({acc_id})\")\n avg_usage = total_usage / 12.0\n \n print(f\"{acc_name[:25]:<25} | {total_usage:>15.2f} | {avg_usage:>16.2f}\")\n\n print(f\"\nTotal Accounts Scanned: {len(all_accounts)}\")\n\n except Exception as e:\n print(f\"Error: {e}\")\n\nif __name__ == \"__main__\":\n get_average_bandwidth_report()\n",
|
||||
"diffStat": {
|
||||
"model_added_lines": 1,
|
||||
"model_removed_lines": 2,
|
||||
"model_added_chars": 61,
|
||||
"model_removed_chars": 59,
|
||||
"user_added_lines": 1,
|
||||
"user_removed_lines": 99,
|
||||
"user_added_chars": 52,
|
||||
"user_removed_chars": 3619
|
||||
},
|
||||
"isNewFile": false
|
||||
},
|
||||
"displayName": "Edit",
|
||||
"description": "Replaces text within a file. By default, replaces a single occurrence, but can replace multiple occurrences when `expected_replacements` is specified. This tool requires providing significant context around the change to ensure precise targeting. Always use the read_file tool to examine the file's current content before attempting a text replacement.\n \n The user has the ability to modify the `new_string` content. If modified, this will be stated in the response.\n \n Expectation for required parameters:\n 1. `old_string` MUST be the exact literal text to replace (including all whitespace, indentation, newlines, and surrounding code etc.).\n 2. `new_string` MUST be the exact literal text to replace `old_string` with (also including all whitespace, indentation, newlines, and surrounding code etc.). Ensure the resulting code is correct and idiomatic and that `old_string` and `new_string` are different.\n 3. `instruction` is the detailed instruction of what needs to be changed. It is important to Make it specific and detailed so developers or large language models can understand what needs to be changed and perform the changes on their own if necessary. \n 4. NEVER escape `old_string` or `new_string`, that would break the exact literal text requirement.\n **Important:** If ANY of the above are not satisfied, the tool will fail. CRITICAL for `old_string`: Must uniquely identify the single instance to change. Include at least 3 lines of context BEFORE and AFTER the target text, matching whitespace and indentation precisely. If this string matches multiple locations, or does not match exactly, the tool will fail.\n 5. Prefer to break down complex and long changes into multiple smaller atomic calls to this tool. Always check the content of the file after changes or not finding a string to match.\n **Multiple replacements:** Set `expected_replacements` to the number of occurrences you want to replace. The tool will replace ALL occurrences that match `old_string` exactly. Ensure the number of replacements matches your expectation.",
|
||||
"renderOutputAsMarkdown": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "ca5920f1-48b8-4dab-a08e-9c93f81e4351",
|
||||
"timestamp": "2026-02-11T17:26:42.042Z",
|
||||
"type": "gemini",
|
||||
"content": "I'll fix the second broken f-string at the end of the script.",
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Considering Adjustments Needed",
|
||||
"description": "I'm focused on the second item now. It needs some tweaking, a bit of rearrangement to fit better. I'm exploring different options to get the phrasing just right, so it flows smoothly with the first. The goal is to maximize impact, as I refine.",
|
||||
"timestamp": "2026-02-11T17:26:41.322Z"
|
||||
}
|
||||
],
|
||||
"tokens": {
|
||||
"input": 18649,
|
||||
"output": 207,
|
||||
"cached": 0,
|
||||
"thoughts": 6,
|
||||
"tool": 0,
|
||||
"total": 18862
|
||||
},
|
||||
"model": "gemini-3-flash-preview",
|
||||
"toolCalls": [
|
||||
{
|
||||
"id": "replace-1770830802040-1237993fe633c8",
|
||||
"name": "replace",
|
||||
"args": {
|
||||
"file_path": "/Users/bob/git/dxw/aws-stuff/avg_bandwidth_12months.py",
|
||||
"instruction": "Fix the broken f-string in the final account count print statement.",
|
||||
"old_string": " print(f\"{acc_name[:25]:<25} | {total_usage:>15.2f} | {avg_usage:>16.2f}\")\n\n print(f\"\nTotal Accounts Scanned: {len(all_accounts)}\")\n\n except Exception as e:",
|
||||
"new_string": " print(f\"{acc_name[:25]:<25} | {total_usage:>15.2f} | {avg_usage:>16.2f}\")\n\n print(f\"\\nTotal Accounts Scanned: {len(all_accounts)}\")\n\n except Exception as e:",
|
||||
"expected_replacements": 1
|
||||
},
|
||||
"result": [
|
||||
{
|
||||
"functionResponse": {
|
||||
"id": "replace-1770830802040-1237993fe633c8",
|
||||
"name": "replace",
|
||||
"response": {
|
||||
"output": "Successfully modified file: /Users/bob/git/dxw/aws-stuff/avg_bandwidth_12months.py (1 replacements)."
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": "success",
|
||||
"timestamp": "2026-02-11T17:26:46.380Z",
|
||||
"resultDisplay": {
|
||||
"fileDiff": "Index: avg_bandwidth_12months.py\n===================================================================\n--- avg_bandwidth_12months.py\tCurrent\n+++ avg_bandwidth_12months.py\tProposed\n@@ -93,8 +93,7 @@\n \n print(f\"{acc_name[:25]:<25} | {total_usage:>15.2f} | {avg_usage:>16.2f}\")\n \n- print(f\"\n-Total Accounts Scanned: {len(all_accounts)}\")\n+ print(f\"\\nTotal Accounts Scanned: {len(all_accounts)}\")\n \n except Exception as e:\n print(f\"Error: {e}\")\n",
|
||||
"fileName": "avg_bandwidth_12months.py",
|
||||
"filePath": "/Users/bob/git/dxw/aws-stuff/avg_bandwidth_12months.py",
|
||||
"originalContent": "import boto3\nfrom datetime import datetime, timedelta\nfrom dateutil.relativedelta import relativedelta\n\ndef get_all_accounts():\n \"\"\"Fetches every account ID and Name in the organization.\"\"\"\n org_client = boto3.client('organizations')\n account_map = {}\n try:\n paginator = org_client.get_paginator('list_accounts')\n for page in paginator.paginate():\n for account in page['Accounts']:\n if account['Status'] == 'ACTIVE':\n account_map[account['Id']] = account['Name']\n except Exception as e:\n print(f\"Error fetching account list: {e}\")\n return account_map\n\ndef get_average_bandwidth_report():\n ce_client = boto3.client('ce')\n \n all_accounts = get_all_accounts()\n if not all_accounts:\n print(\"Could not retrieve account list. Check Organizations permissions.\")\n return\n\n # Set dates for the last 12 full months\n now = datetime.now()\n first_day_current_month = now.replace(day=1)\n end_date = first_day_current_month.strftime('%Y-%m-%d')\n start_date = (first_day_current_month - relativedelta(months=12)).strftime('%Y-%m-%d')\n\n # Initialize tracking: {acc_id: [usage_month1, usage_month2, ...]}\n # Actually, we can just track the total and divide by 12 at the end\n account_totals = {acc_id: 0.0 for acc_id in all_accounts.keys()}\n \n next_token = None\n\n try:\n while True:\n params = {\n 'TimePeriod': {'Start': start_date, 'End': end_date},\n 'Granularity': 'MONTHLY',\n 'Metrics': ['UsageQuantity'],\n 'GroupBy': [\n {'Type': 'DIMENSION', 'Key': 'LINKED_ACCOUNT'},\n {'Type': 'DIMENSION', 'Key': 'USAGE_TYPE'}\n ]\n }\n if next_token:\n params['NextPageToken'] = next_token\n\n response = ce_client.get_cost_and_usage(**params)\n\n for result in response['ResultsByTime']:\n for group in result['Groups']:\n acc_id = group['Keys'][0]\n usage_type = group['Keys'][1]\n usage_amount = float(group['Metrics']['UsageQuantity']['Amount'])\n unit = group['Metrics']['UsageQuantity']['Unit']\n\n # Bandwidth calculation logic from bwsuage.py\n if \"DataTransfer\" in usage_type:\n if unit == 'Bytes':\n usage_amount /= (1024**3)\n elif unit in ['MB', 'Megabytes']:\n usage_amount /= 1024\n \n if acc_id in account_totals:\n account_totals[acc_id] += usage_amount\n else:\n account_totals[acc_id] = usage_amount\n\n next_token = response.get('NextPageToken')\n if not next_token:\n break\n\n print(f\"\\n--- 12-Month Average Bandwidth Report ---\")\n print(f\"Period: {start_date} to {end_date}\")\n print(f\"{'Account Name':<25} | {'12m Total (GB)':<15} | {'Monthly Avg (GB)'}\")\n print(\"-\" * 75)\n\n # Sort by monthly average descending\n sorted_accounts = sorted(\n account_totals.items(), \n key=lambda x: x[1], \n reverse=True\n )\n \n for acc_id, total_usage in sorted_accounts:\n acc_name = all_accounts.get(acc_id, f\"Deleted/Unknown ({acc_id})\")\n avg_usage = total_usage / 12.0\n \n print(f\"{acc_name[:25]:<25} | {total_usage:>15.2f} | {avg_usage:>16.2f}\")\n\n print(f\"\nTotal Accounts Scanned: {len(all_accounts)}\")\n\n except Exception as e:\n print(f\"Error: {e}\")\n\nif __name__ == \"__main__\":\n get_average_bandwidth_report()\n",
|
||||
"newContent": "import boto3\nfrom datetime import datetime, timedelta\nfrom dateutil.relativedelta import relativedelta\n\ndef get_all_accounts():\n \"\"\"Fetches every account ID and Name in the organization.\"\"\"\n org_client = boto3.client('organizations')\n account_map = {}\n try:\n paginator = org_client.get_paginator('list_accounts')\n for page in paginator.paginate():\n for account in page['Accounts']:\n if account['Status'] == 'ACTIVE':\n account_map[account['Id']] = account['Name']\n except Exception as e:\n print(f\"Error fetching account list: {e}\")\n return account_map\n\ndef get_average_bandwidth_report():\n ce_client = boto3.client('ce')\n \n all_accounts = get_all_accounts()\n if not all_accounts:\n print(\"Could not retrieve account list. Check Organizations permissions.\")\n return\n\n # Set dates for the last 12 full months\n now = datetime.now()\n first_day_current_month = now.replace(day=1)\n end_date = first_day_current_month.strftime('%Y-%m-%d')\n start_date = (first_day_current_month - relativedelta(months=12)).strftime('%Y-%m-%d')\n\n # Initialize tracking: {acc_id: [usage_month1, usage_month2, ...]}\n # Actually, we can just track the total and divide by 12 at the end\n account_totals = {acc_id: 0.0 for acc_id in all_accounts.keys()}\n \n next_token = None\n\n try:\n while True:\n params = {\n 'TimePeriod': {'Start': start_date, 'End': end_date},\n 'Granularity': 'MONTHLY',\n 'Metrics': ['UsageQuantity'],\n 'GroupBy': [\n {'Type': 'DIMENSION', 'Key': 'LINKED_ACCOUNT'},\n {'Type': 'DIMENSION', 'Key': 'USAGE_TYPE'}\n ]\n }\n if next_token:\n params['NextPageToken'] = next_token\n\n response = ce_client.get_cost_and_usage(**params)\n\n for result in response['ResultsByTime']:\n for group in result['Groups']:\n acc_id = group['Keys'][0]\n usage_type = group['Keys'][1]\n usage_amount = float(group['Metrics']['UsageQuantity']['Amount'])\n unit = group['Metrics']['UsageQuantity']['Unit']\n\n # Bandwidth calculation logic from bwsuage.py\n if \"DataTransfer\" in usage_type:\n if unit == 'Bytes':\n usage_amount /= (1024**3)\n elif unit in ['MB', 'Megabytes']:\n usage_amount /= 1024\n \n if acc_id in account_totals:\n account_totals[acc_id] += usage_amount\n else:\n account_totals[acc_id] = usage_amount\n\n next_token = response.get('NextPageToken')\n if not next_token:\n break\n\n print(f\"\\n--- 12-Month Average Bandwidth Report ---\")\n print(f\"Period: {start_date} to {end_date}\")\n print(f\"{'Account Name':<25} | {'12m Total (GB)':<15} | {'Monthly Avg (GB)'}\")\n print(\"-\" * 75)\n\n # Sort by monthly average descending\n sorted_accounts = sorted(\n account_totals.items(), \n key=lambda x: x[1], \n reverse=True\n )\n \n for acc_id, total_usage in sorted_accounts:\n acc_name = all_accounts.get(acc_id, f\"Deleted/Unknown ({acc_id})\")\n avg_usage = total_usage / 12.0\n \n print(f\"{acc_name[:25]:<25} | {total_usage:>15.2f} | {avg_usage:>16.2f}\")\n\n print(f\"\\nTotal Accounts Scanned: {len(all_accounts)}\")\n\n except Exception as e:\n print(f\"Error: {e}\")\n\nif __name__ == \"__main__\":\n get_average_bandwidth_report()\n",
|
||||
"diffStat": {
|
||||
"model_added_lines": 1,
|
||||
"model_removed_lines": 2,
|
||||
"model_added_chars": 63,
|
||||
"model_removed_chars": 61,
|
||||
"user_added_lines": 1,
|
||||
"user_removed_lines": 98,
|
||||
"user_added_chars": 26,
|
||||
"user_removed_chars": 3585
|
||||
},
|
||||
"isNewFile": false
|
||||
},
|
||||
"displayName": "Edit",
|
||||
"description": "Replaces text within a file. By default, replaces a single occurrence, but can replace multiple occurrences when `expected_replacements` is specified. This tool requires providing significant context around the change to ensure precise targeting. Always use the read_file tool to examine the file's current content before attempting a text replacement.\n \n The user has the ability to modify the `new_string` content. If modified, this will be stated in the response.\n \n Expectation for required parameters:\n 1. `old_string` MUST be the exact literal text to replace (including all whitespace, indentation, newlines, and surrounding code etc.).\n 2. `new_string` MUST be the exact literal text to replace `old_string` with (also including all whitespace, indentation, newlines, and surrounding code etc.). Ensure the resulting code is correct and idiomatic and that `old_string` and `new_string` are different.\n 3. `instruction` is the detailed instruction of what needs to be changed. It is important to Make it specific and detailed so developers or large language models can understand what needs to be changed and perform the changes on their own if necessary. \n 4. NEVER escape `old_string` or `new_string`, that would break the exact literal text requirement.\n **Important:** If ANY of the above are not satisfied, the tool will fail. CRITICAL for `old_string`: Must uniquely identify the single instance to change. Include at least 3 lines of context BEFORE and AFTER the target text, matching whitespace and indentation precisely. If this string matches multiple locations, or does not match exactly, the tool will fail.\n 5. Prefer to break down complex and long changes into multiple smaller atomic calls to this tool. Always check the content of the file after changes or not finding a string to match.\n **Multiple replacements:** Set `expected_replacements` to the number of occurrences you want to replace. The tool will replace ALL occurrences that match `old_string` exactly. Ensure the number of replacements matches your expectation.",
|
||||
"renderOutputAsMarkdown": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "3543a5bd-dc79-4945-9f31-f466a0e2946d",
|
||||
"timestamp": "2026-02-11T17:26:55.399Z",
|
||||
"type": "gemini",
|
||||
"content": "I'll verify the script's syntax once more.",
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Checking the Code Again",
|
||||
"description": "I'm currently revisiting the syntax, ensuring everything aligns perfectly. Minor adjustments have been made based on the latest review. I anticipate further refinement as I delve deeper, but so far, things look promising.",
|
||||
"timestamp": "2026-02-11T17:26:55.150Z"
|
||||
}
|
||||
],
|
||||
"tokens": {
|
||||
"input": 18885,
|
||||
"output": 49,
|
||||
"cached": 0,
|
||||
"thoughts": 5,
|
||||
"tool": 0,
|
||||
"total": 18939
|
||||
},
|
||||
"model": "gemini-3-flash-preview",
|
||||
"toolCalls": [
|
||||
{
|
||||
"id": "run_shell_command-1770830815396-dcb6771c807ff",
|
||||
"name": "run_shell_command",
|
||||
"args": {
|
||||
"description": "Check for syntax errors in the fixed script.",
|
||||
"command": "python3 -m py_compile avg_bandwidth_12months.py"
|
||||
},
|
||||
"result": [
|
||||
{
|
||||
"functionResponse": {
|
||||
"id": "run_shell_command-1770830815396-dcb6771c807ff",
|
||||
"name": "run_shell_command",
|
||||
"response": {
|
||||
"output": "Output: (empty)\nProcess Group PGID: 59324"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": "success",
|
||||
"timestamp": "2026-02-11T17:27:00.410Z",
|
||||
"resultDisplay": "",
|
||||
"displayName": "Shell",
|
||||
"description": "This tool executes a given shell command as `bash -c <command>`. To run a command in the background, set the `is_background` parameter to true. Do NOT use `&` to background commands. Command is executed as a subprocess that leads its own process group. Command process group can be terminated as `kill -- -PGID` or signaled as `kill -s SIGNAL -- -PGID`.\n\n The following information is returned:\n\n Output: Combined stdout/stderr. Can be `(empty)` or partial on error and for any unwaited background processes.\n Exit Code: Only included if non-zero (command failed).\n Error: Only included if a process-level error occurred (e.g., spawn failure).\n Signal: Only included if process was terminated by a signal.\n Background PIDs: Only included if background processes were started.\n Process Group PGID: Only included if available.",
|
||||
"renderOutputAsMarkdown": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "ed66efc1-b4a5-4cde-bf3d-03eef336ab07",
|
||||
"timestamp": "2026-02-11T17:27:08.752Z",
|
||||
"type": "gemini",
|
||||
"content": "I've created `avg_bandwidth_12months.py`, which calculates the monthly average bandwidth usage per account over the last 12 months, using the logic from `bwsuage.py`.\n\n```python\nimport boto3\nfrom datetime import datetime\nfrom dateutil.relativedelta import relativedelta\n\ndef get_all_accounts():\n \"\"\"Fetches every active account ID and Name in the organization.\"\"\"\n org_client = boto3.client('organizations')\n account_map = {}\n try:\n paginator = org_client.get_paginator('list_accounts')\n for page in paginator.paginate():\n for account in page['Accounts']:\n if account['Status'] == 'ACTIVE':\n account_map[account['Id']] = account['Name']\n except Exception as e:\n print(f\"Error fetching account list: {e}\")\n return account_map\n\ndef get_average_bandwidth_report():\n ce_client = boto3.client('ce')\n \n all_accounts = get_all_accounts()\n if not all_accounts:\n print(\"Could not retrieve account list. Check Organizations permissions.\")\n return\n\n # Set dates for the last 12 full months\n now = datetime.now()\n first_day_current_month = now.replace(day=1)\n end_date = first_day_current_month.strftime('%Y-%m-%d')\n start_date = (first_day_current_month - relativedelta(months=12)).strftime('%Y-%m-%d')\n\n account_totals = {acc_id: 0.0 for acc_id in all_accounts.keys()}\n next_token = None\n\n try:\n while True:\n params = {\n 'TimePeriod': {'Start': start_date, 'End': end_date},\n 'Granularity': 'MONTHLY',\n 'Metrics': ['UsageQuantity'],\n 'GroupBy': [\n {'Type': 'DIMENSION', 'Key': 'LINKED_ACCOUNT'},\n {'Type': 'DIMENSION', 'Key': 'USAGE_TYPE'}\n ]\n }\n if next_token:\n params['NextPageToken'] = next_token\n\n response = ce_client.get_cost_and_usage(**params)\n\n for result in response['ResultsByTime']:\n for group in result['Groups']:\n acc_id = group['Keys'][0]\n usage_type = group['Keys'][1]\n usage_amount = float(group['Metrics']['UsageQuantity']['Amount'])\n unit = group['Metrics']['UsageQuantity']['Unit']\n\n # Bandwidth calculation logic matched from bwsuage.py\n if \"DataTransfer\" in usage_type:\n if unit == 'Bytes':\n usage_amount /= (1024**3)\n elif unit in ['MB', 'Megabytes']:\n usage_amount /= 1024\n \n if acc_id in account_totals:\n account_totals[acc_id] += usage_amount\n else:\n account_totals[acc_id] = usage_amount\n\n next_token = response.get('NextPageToken')\n if not next_token:\n break\n\n print(f\"\\n--- 12-Month Average Bandwidth Report ---\")\n print(f\"Period: {start_date} to {end_date}\")\n print(f\"{'Account Name':<25} | {'12m Total (GB)':<15} | {'Monthly Avg (GB)'}\")\n print(\"-\" * 75)\n\n sorted_accounts = sorted(\n account_totals.items(), \n key=lambda x: x[1], \n reverse=True\n )\n \n for acc_id, total_usage in sorted_accounts:\n acc_name = all_accounts.get(acc_id, f\"Deleted/Unknown ({acc_id})\")\n avg_usage = total_usage / 12.0\n print(f\"{acc_name[:25]:<25} | {total_usage:>15.2f} | {avg_usage:>16.2f}\")\n\n print(f\"\\nTotal Accounts Scanned: {len(all_accounts)}\")\n\n except Exception as e:\n print(f\"Error: {e}\")\n\nif __name__ == \"__main__\":\n get_average_bandwidth_report()\n```",
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Refining Implementation Strategy",
|
||||
"description": "I've confirmed the script's syntax is sound and ready. I'm now reviewing `bwsuage.py` for any other relevant logic. I noted the `threshold_gb` parameter in `get_total_bandwidth_report()`. The user's instructions omitted it, so I'll need to decide how to handle the parameter.",
|
||||
"timestamp": "2026-02-11T17:27:02.991Z"
|
||||
},
|
||||
{
|
||||
"subject": "Assessing Parameter Handling",
|
||||
"description": "The script is ready, and syntax is confirmed! I'm now wrestling with the `threshold_gb` parameter in `get_total_bandwidth_report()`. Since the user didn't mention it, I will ignore it. I'll make sure to leave boto3 configuration to defaults. I think it is time to package everything up and present it.",
|
||||
"timestamp": "2026-02-11T17:27:03.716Z"
|
||||
}
|
||||
],
|
||||
"tokens": {
|
||||
"input": 18953,
|
||||
"output": 1022,
|
||||
"cached": 0,
|
||||
"thoughts": 140,
|
||||
"tool": 0,
|
||||
"total": 20115
|
||||
},
|
||||
"model": "gemini-3-flash-preview"
|
||||
},
|
||||
{
|
||||
"id": "9e492535-afeb-41d7-bfff-bd238dcfa0e7",
|
||||
"timestamp": "2026-02-11T17:30:12.767Z",
|
||||
"type": "user",
|
||||
"content": [
|
||||
{
|
||||
"text": "also show average cost"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "9a9440b9-89ad-437a-8618-623970534b25",
|
||||
"timestamp": "2026-02-11T17:30:24.585Z",
|
||||
"type": "gemini",
|
||||
"content": "I will update the `avg_bandwidth_12months.py` script to include both usage quantity and unblended cost metrics, allowing it to report the average monthly cost alongside the bandwidth usage.",
|
||||
"thoughts": [],
|
||||
"tokens": {
|
||||
"input": 19980,
|
||||
"output": 945,
|
||||
"cached": 0,
|
||||
"thoughts": 0,
|
||||
"tool": 0,
|
||||
"total": 20925
|
||||
},
|
||||
"model": "gemini-3-flash-preview",
|
||||
"toolCalls": [
|
||||
{
|
||||
"id": "replace-1770831024583-90bde548df6",
|
||||
"name": "replace",
|
||||
"args": {
|
||||
"file_path": "/Users/bob/git/dxw/aws-stuff/avg_bandwidth_12months.py",
|
||||
"new_string": " # Initialize tracking: {acc_id: {'usage': 0.0, 'cost': 0.0}}\n account_totals = {acc_id: {'usage': 0.0, 'cost': 0.0} for acc_id in all_accounts.keys()}\n \n next_token = None\n\n try:\n while True:\n params = {\n 'TimePeriod': {'Start': start_date, 'End': end_date},\n 'Granularity': 'MONTHLY',\n 'Metrics': ['UsageQuantity', 'UnblendedCost'],\n 'GroupBy': [\n {'Type': 'DIMENSION', 'Key': 'LINKED_ACCOUNT'},\n {'Type': 'DIMENSION', 'Key': 'USAGE_TYPE'}\n ]\n }\n if next_token:\n params['NextPageToken'] = next_token\n\n response = ce_client.get_cost_and_usage(**params)\n\n for result in response['ResultsByTime']:\n for group in result['Groups']:\n acc_id = group['Keys'][0]\n usage_type = group['Keys'][1]\n usage_amount = float(group['Metrics']['UsageQuantity']['Amount'])\n unit = group['Metrics']['UsageQuantity']['Unit']\n cost_amount = float(group['Metrics']['UnblendedCost']['Amount'])\n\n # Bandwidth calculation logic from bwsuage.py\n if \"DataTransfer\" in usage_type:\n if unit == 'Bytes':\n usage_amount /= (1024**3)\n elif unit in ['MB', 'Megabytes']:\n usage_amount /= 1024\n \n if acc_id not in account_totals:\n account_totals[acc_id] = {'usage': 0.0, 'cost': 0.0}\n \n account_totals[acc_id]['usage'] += usage_amount\n account_totals[acc_id]['cost'] += cost_amount",
|
||||
"instruction": "Add cost metrics to the Cost Explorer query and track totals for both usage and cost.",
|
||||
"old_string": " # Initialize tracking: {acc_id: [usage_month1, usage_month2, ...]}\n # Actually, we can just track the total and divide by 12 at the end\n account_totals = {acc_id: 0.0 for acc_id in all_accounts.keys()}\n \n next_token = None\n\n try:\n while True:\n params = {\n 'TimePeriod': {'Start': start_date, 'End': end_date},\n 'Granularity': 'MONTHLY',\n 'Metrics': ['UsageQuantity'],\n 'GroupBy': [\n {'Type': 'DIMENSION', 'Key': 'LINKED_ACCOUNT'},\n {'Type': 'DIMENSION', 'Key': 'USAGE_TYPE'}\n ]\n }\n if next_token:\n params['NextPageToken'] = next_token\n\n response = ce_client.get_cost_and_usage(**params)\n\n for result in response['ResultsByTime']:\n for group in result['Groups']:\n acc_id = group['Keys'][0]\n usage_type = group['Keys'][1]\n usage_amount = float(group['Metrics']['UsageQuantity']['Amount'])\n unit = group['Metrics']['UsageQuantity']['Unit']\n\n # Bandwidth calculation logic from bwsuage.py\n if \"DataTransfer\" in usage_type:\n if unit == 'Bytes':\n usage_amount /= (1024**3)\n elif unit in ['MB', 'Megabytes']:\n usage_amount /= 1024\n \n if acc_id in account_totals:\n account_totals[acc_id] += usage_amount\n else:\n account_totals[acc_id] = usage_amount",
|
||||
"expected_replacements": 1
|
||||
},
|
||||
"result": [
|
||||
{
|
||||
"functionResponse": {
|
||||
"id": "replace-1770831024583-90bde548df6",
|
||||
"name": "replace",
|
||||
"response": {
|
||||
"output": "Successfully modified file: /Users/bob/git/dxw/aws-stuff/avg_bandwidth_12months.py (1 replacements)."
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": "success",
|
||||
"timestamp": "2026-02-11T17:30:37.440Z",
|
||||
"resultDisplay": {
|
||||
"fileDiff": "Index: avg_bandwidth_12months.py\n===================================================================\n--- avg_bandwidth_12months.py\tCurrent\n+++ avg_bandwidth_12months.py\tProposed\n@@ -30,9 +30,8 @@\n end_date = first_day_current_month.strftime('%Y-%m-%d')\n start_date = (first_day_current_month - relativedelta(months=12)).strftime('%Y-%m-%d')\n \n- # Initialize tracking: {acc_id: [usage_month1, usage_month2, ...]}\n- # Actually, we can just track the total and divide by 12 at the end\n- account_totals = {acc_id: 0.0 for acc_id in all_accounts.keys()}\n+ # Initialize tracking: {acc_id: {'usage': 0.0, 'cost': 0.0}}\n+ account_totals = {acc_id: {'usage': 0.0, 'cost': 0.0} for acc_id in all_accounts.keys()}\n \n next_token = None\n \n@@ -41,7 +40,7 @@\n params = {\n 'TimePeriod': {'Start': start_date, 'End': end_date},\n 'Granularity': 'MONTHLY',\n- 'Metrics': ['UsageQuantity'],\n+ 'Metrics': ['UsageQuantity', 'UnblendedCost'],\n 'GroupBy': [\n {'Type': 'DIMENSION', 'Key': 'LINKED_ACCOUNT'},\n {'Type': 'DIMENSION', 'Key': 'USAGE_TYPE'}\n@@ -58,6 +57,7 @@\n usage_type = group['Keys'][1]\n usage_amount = float(group['Metrics']['UsageQuantity']['Amount'])\n unit = group['Metrics']['UsageQuantity']['Unit']\n+ cost_amount = float(group['Metrics']['UnblendedCost']['Amount'])\n \n # Bandwidth calculation logic from bwsuage.py\n if \"DataTransfer\" in usage_type:\n@@ -66,10 +66,11 @@\n elif unit in ['MB', 'Megabytes']:\n usage_amount /= 1024\n \n- if acc_id in account_totals:\n- account_totals[acc_id] += usage_amount\n- else:\n- account_totals[acc_id] = usage_amount\n+ if acc_id not in account_totals:\n+ account_totals[acc_id] = {'usage': 0.0, 'cost': 0.0}\n+ \n+ account_totals[acc_id]['usage'] += usage_amount\n+ account_totals[acc_id]['cost'] += cost_amount\n \n next_token = response.get('NextPageToken')\n if not next_token:\n",
|
||||
"fileName": "avg_bandwidth_12months.py",
|
||||
"filePath": "/Users/bob/git/dxw/aws-stuff/avg_bandwidth_12months.py",
|
||||
"originalContent": "import boto3\nfrom datetime import datetime, timedelta\nfrom dateutil.relativedelta import relativedelta\n\ndef get_all_accounts():\n \"\"\"Fetches every account ID and Name in the organization.\"\"\"\n org_client = boto3.client('organizations')\n account_map = {}\n try:\n paginator = org_client.get_paginator('list_accounts')\n for page in paginator.paginate():\n for account in page['Accounts']:\n if account['Status'] == 'ACTIVE':\n account_map[account['Id']] = account['Name']\n except Exception as e:\n print(f\"Error fetching account list: {e}\")\n return account_map\n\ndef get_average_bandwidth_report():\n ce_client = boto3.client('ce')\n \n all_accounts = get_all_accounts()\n if not all_accounts:\n print(\"Could not retrieve account list. Check Organizations permissions.\")\n return\n\n # Set dates for the last 12 full months\n now = datetime.now()\n first_day_current_month = now.replace(day=1)\n end_date = first_day_current_month.strftime('%Y-%m-%d')\n start_date = (first_day_current_month - relativedelta(months=12)).strftime('%Y-%m-%d')\n\n # Initialize tracking: {acc_id: [usage_month1, usage_month2, ...]}\n # Actually, we can just track the total and divide by 12 at the end\n account_totals = {acc_id: 0.0 for acc_id in all_accounts.keys()}\n \n next_token = None\n\n try:\n while True:\n params = {\n 'TimePeriod': {'Start': start_date, 'End': end_date},\n 'Granularity': 'MONTHLY',\n 'Metrics': ['UsageQuantity'],\n 'GroupBy': [\n {'Type': 'DIMENSION', 'Key': 'LINKED_ACCOUNT'},\n {'Type': 'DIMENSION', 'Key': 'USAGE_TYPE'}\n ]\n }\n if next_token:\n params['NextPageToken'] = next_token\n\n response = ce_client.get_cost_and_usage(**params)\n\n for result in response['ResultsByTime']:\n for group in result['Groups']:\n acc_id = group['Keys'][0]\n usage_type = group['Keys'][1]\n usage_amount = float(group['Metrics']['UsageQuantity']['Amount'])\n unit = group['Metrics']['UsageQuantity']['Unit']\n\n # Bandwidth calculation logic from bwsuage.py\n if \"DataTransfer\" in usage_type:\n if unit == 'Bytes':\n usage_amount /= (1024**3)\n elif unit in ['MB', 'Megabytes']:\n usage_amount /= 1024\n \n if acc_id in account_totals:\n account_totals[acc_id] += usage_amount\n else:\n account_totals[acc_id] = usage_amount\n\n next_token = response.get('NextPageToken')\n if not next_token:\n break\n\n print(f\"\\n--- 12-Month Average Bandwidth Report ---\")\n print(f\"Period: {start_date} to {end_date}\")\n print(f\"{'Account Name':<25} | {'12m Total (GB)':<15} | {'Monthly Avg (GB)'}\")\n print(\"-\" * 75)\n\n # Sort by monthly average descending\n sorted_accounts = sorted(\n account_totals.items(), \n key=lambda x: x[1], \n reverse=True\n )\n \n for acc_id, total_usage in sorted_accounts:\n acc_name = all_accounts.get(acc_id, f\"Deleted/Unknown ({acc_id})\")\n avg_usage = total_usage / 12.0\n \n print(f\"{acc_name[:25]:<25} | {total_usage:>15.2f} | {avg_usage:>16.2f}\")\n\n print(f\"\\nTotal Accounts Scanned: {len(all_accounts)}\")\n\n except Exception as e:\n print(f\"Error: {e}\")\n\nif __name__ == \"__main__\":\n get_average_bandwidth_report()\n",
|
||||
"newContent": "import boto3\nfrom datetime import datetime, timedelta\nfrom dateutil.relativedelta import relativedelta\n\ndef get_all_accounts():\n \"\"\"Fetches every account ID and Name in the organization.\"\"\"\n org_client = boto3.client('organizations')\n account_map = {}\n try:\n paginator = org_client.get_paginator('list_accounts')\n for page in paginator.paginate():\n for account in page['Accounts']:\n if account['Status'] == 'ACTIVE':\n account_map[account['Id']] = account['Name']\n except Exception as e:\n print(f\"Error fetching account list: {e}\")\n return account_map\n\ndef get_average_bandwidth_report():\n ce_client = boto3.client('ce')\n \n all_accounts = get_all_accounts()\n if not all_accounts:\n print(\"Could not retrieve account list. Check Organizations permissions.\")\n return\n\n # Set dates for the last 12 full months\n now = datetime.now()\n first_day_current_month = now.replace(day=1)\n end_date = first_day_current_month.strftime('%Y-%m-%d')\n start_date = (first_day_current_month - relativedelta(months=12)).strftime('%Y-%m-%d')\n\n # Initialize tracking: {acc_id: {'usage': 0.0, 'cost': 0.0}}\n account_totals = {acc_id: {'usage': 0.0, 'cost': 0.0} for acc_id in all_accounts.keys()}\n \n next_token = None\n\n try:\n while True:\n params = {\n 'TimePeriod': {'Start': start_date, 'End': end_date},\n 'Granularity': 'MONTHLY',\n 'Metrics': ['UsageQuantity', 'UnblendedCost'],\n 'GroupBy': [\n {'Type': 'DIMENSION', 'Key': 'LINKED_ACCOUNT'},\n {'Type': 'DIMENSION', 'Key': 'USAGE_TYPE'}\n ]\n }\n if next_token:\n params['NextPageToken'] = next_token\n\n response = ce_client.get_cost_and_usage(**params)\n\n for result in response['ResultsByTime']:\n for group in result['Groups']:\n acc_id = group['Keys'][0]\n usage_type = group['Keys'][1]\n usage_amount = float(group['Metrics']['UsageQuantity']['Amount'])\n unit = group['Metrics']['UsageQuantity']['Unit']\n cost_amount = float(group['Metrics']['UnblendedCost']['Amount'])\n\n # Bandwidth calculation logic from bwsuage.py\n if \"DataTransfer\" in usage_type:\n if unit == 'Bytes':\n usage_amount /= (1024**3)\n elif unit in ['MB', 'Megabytes']:\n usage_amount /= 1024\n \n if acc_id not in account_totals:\n account_totals[acc_id] = {'usage': 0.0, 'cost': 0.0}\n \n account_totals[acc_id]['usage'] += usage_amount\n account_totals[acc_id]['cost'] += cost_amount\n\n next_token = response.get('NextPageToken')\n if not next_token:\n break\n\n print(f\"\\n--- 12-Month Average Bandwidth Report ---\")\n print(f\"Period: {start_date} to {end_date}\")\n print(f\"{'Account Name':<25} | {'12m Total (GB)':<15} | {'Monthly Avg (GB)'}\")\n print(\"-\" * 75)\n\n # Sort by monthly average descending\n sorted_accounts = sorted(\n account_totals.items(), \n key=lambda x: x[1], \n reverse=True\n )\n \n for acc_id, total_usage in sorted_accounts:\n acc_name = all_accounts.get(acc_id, f\"Deleted/Unknown ({acc_id})\")\n avg_usage = total_usage / 12.0\n \n print(f\"{acc_name[:25]:<25} | {total_usage:>15.2f} | {avg_usage:>16.2f}\")\n\n print(f\"\\nTotal Accounts Scanned: {len(all_accounts)}\")\n\n except Exception as e:\n print(f\"Error: {e}\")\n\nif __name__ == \"__main__\":\n get_average_bandwidth_report()\n",
|
||||
"diffStat": {
|
||||
"model_added_lines": 9,
|
||||
"model_removed_lines": 8,
|
||||
"model_added_chars": 602,
|
||||
"model_removed_chars": 466,
|
||||
"user_added_lines": 1,
|
||||
"user_removed_lines": 63,
|
||||
"user_added_chars": 69,
|
||||
"user_removed_chars": 2139
|
||||
},
|
||||
"isNewFile": false
|
||||
},
|
||||
"displayName": "Edit",
|
||||
"description": "Replaces text within a file. By default, replaces a single occurrence, but can replace multiple occurrences when `expected_replacements` is specified. This tool requires providing significant context around the change to ensure precise targeting. Always use the read_file tool to examine the file's current content before attempting a text replacement.\n \n The user has the ability to modify the `new_string` content. If modified, this will be stated in the response.\n \n Expectation for required parameters:\n 1. `old_string` MUST be the exact literal text to replace (including all whitespace, indentation, newlines, and surrounding code etc.).\n 2. `new_string` MUST be the exact literal text to replace `old_string` with (also including all whitespace, indentation, newlines, and surrounding code etc.). Ensure the resulting code is correct and idiomatic and that `old_string` and `new_string` are different.\n 3. `instruction` is the detailed instruction of what needs to be changed. It is important to Make it specific and detailed so developers or large language models can understand what needs to be changed and perform the changes on their own if necessary. \n 4. NEVER escape `old_string` or `new_string`, that would break the exact literal text requirement.\n **Important:** If ANY of the above are not satisfied, the tool will fail. CRITICAL for `old_string`: Must uniquely identify the single instance to change. Include at least 3 lines of context BEFORE and AFTER the target text, matching whitespace and indentation precisely. If this string matches multiple locations, or does not match exactly, the tool will fail.\n 5. Prefer to break down complex and long changes into multiple smaller atomic calls to this tool. Always check the content of the file after changes or not finding a string to match.\n **Multiple replacements:** Set `expected_replacements` to the number of occurrences you want to replace. The tool will replace ALL occurrences that match `old_string` exactly. Ensure the number of replacements matches your expectation.",
|
||||
"renderOutputAsMarkdown": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "21b7760d-e6aa-400b-b82f-6ce428d99ef4",
|
||||
"timestamp": "2026-02-11T17:31:21.096Z",
|
||||
"type": "gemini",
|
||||
"content": "I'll update the report printing logic to include the average cost column and sort by cost.",
|
||||
"thoughts": [],
|
||||
"tokens": {
|
||||
"input": 20968,
|
||||
"output": 581,
|
||||
"cached": 0,
|
||||
"thoughts": 0,
|
||||
"tool": 0,
|
||||
"total": 21549
|
||||
},
|
||||
"model": "gemini-3-flash-preview",
|
||||
"toolCalls": [
|
||||
{
|
||||
"id": "replace-1770831081090-f6e59423d87a18",
|
||||
"name": "replace",
|
||||
"args": {
|
||||
"expected_replacements": 1,
|
||||
"file_path": "/Users/bob/git/dxw/aws-stuff/avg_bandwidth_12months.py",
|
||||
"new_string": " print(f\"\\n--- 12-Month Average Bandwidth & Cost Report ---\")\n print(f\"Period: {start_date} to {end_date}\")\n print(f\"{'Account Name':<25} | {'Avg GB':<10} | {'Avg Cost ($)':<12} | {'12m Total ($)'}\")\n print(\"-\" * 80)\n\n # Sort by total cost descending\n sorted_accounts = sorted(\n account_totals.items(), \n key=lambda x: x[1]['cost'], \n reverse=True\n )\n \n for acc_id, totals in sorted_accounts:\n acc_name = all_accounts.get(acc_id, f\"Deleted/Unknown ({acc_id})\")\n avg_usage = totals['usage'] / 12.0\n avg_cost = totals['cost'] / 12.0\n total_cost = totals['cost']\n \n print(f\"{acc_name[:25]:<25} | {avg_usage:>10.2f} | {avg_cost:>12.2f} | {total_cost:>13.2f}\")",
|
||||
"instruction": "Update the report table to include average cost and sort by total cost descending.",
|
||||
"old_string": " print(f\"\\n--- 12-Month Average Bandwidth Report ---\")\n print(f\"Period: {start_date} to {end_date}\")\n print(f\"{'Account Name':<25} | {'12m Total (GB)':<15} | {'Monthly Avg (GB)'}\")\n print(\"-\" * 75)\n\n # Sort by monthly average descending\n sorted_accounts = sorted(\n account_totals.items(), \n key=lambda x: x[1], \n reverse=True\n )\n \n for acc_id, total_usage in sorted_accounts:\n acc_name = all_accounts.get(acc_id, f\"Deleted/Unknown ({acc_id})\")\n avg_usage = total_usage / 12.0\n \n print(f\"{acc_name[:25]:<25} | {total_usage:>15.2f} | {avg_usage:>16.2f}\")"
|
||||
},
|
||||
"result": [
|
||||
{
|
||||
"functionResponse": {
|
||||
"id": "replace-1770831081090-f6e59423d87a18",
|
||||
"name": "replace",
|
||||
"response": {
|
||||
"output": "Successfully modified file: /Users/bob/git/dxw/aws-stuff/avg_bandwidth_12months.py (1 replacements)."
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": "success",
|
||||
"timestamp": "2026-02-11T17:31:34.795Z",
|
||||
"resultDisplay": {
|
||||
"fileDiff": "Index: avg_bandwidth_12months.py\n===================================================================\n--- avg_bandwidth_12months.py\tCurrent\n+++ avg_bandwidth_12months.py\tProposed\n@@ -76,23 +76,25 @@\n if not next_token:\n break\n \n- print(f\"\\n--- 12-Month Average Bandwidth Report ---\")\n+ print(f\"\\n--- 12-Month Average Bandwidth & Cost Report ---\")\n print(f\"Period: {start_date} to {end_date}\")\n- print(f\"{'Account Name':<25} | {'12m Total (GB)':<15} | {'Monthly Avg (GB)'}\")\n- print(\"-\" * 75)\n+ print(f\"{'Account Name':<25} | {'Avg GB':<10} | {'Avg Cost ($)':<12} | {'12m Total ($)'}\")\n+ print(\"-\" * 80)\n \n- # Sort by monthly average descending\n+ # Sort by total cost descending\n sorted_accounts = sorted(\n account_totals.items(), \n- key=lambda x: x[1], \n+ key=lambda x: x[1]['cost'], \n reverse=True\n )\n \n- for acc_id, total_usage in sorted_accounts:\n+ for acc_id, totals in sorted_accounts:\n acc_name = all_accounts.get(acc_id, f\"Deleted/Unknown ({acc_id})\")\n- avg_usage = total_usage / 12.0\n+ avg_usage = totals['usage'] / 12.0\n+ avg_cost = totals['cost'] / 12.0\n+ total_cost = totals['cost']\n \n- print(f\"{acc_name[:25]:<25} | {total_usage:>15.2f} | {avg_usage:>16.2f}\")\n+ print(f\"{acc_name[:25]:<25} | {avg_usage:>10.2f} | {avg_cost:>12.2f} | {total_cost:>13.2f}\")\n \n print(f\"\\nTotal Accounts Scanned: {len(all_accounts)}\")\n \n",
|
||||
"fileName": "avg_bandwidth_12months.py",
|
||||
"filePath": "/Users/bob/git/dxw/aws-stuff/avg_bandwidth_12months.py",
|
||||
"originalContent": "import boto3\nfrom datetime import datetime, timedelta\nfrom dateutil.relativedelta import relativedelta\n\ndef get_all_accounts():\n \"\"\"Fetches every account ID and Name in the organization.\"\"\"\n org_client = boto3.client('organizations')\n account_map = {}\n try:\n paginator = org_client.get_paginator('list_accounts')\n for page in paginator.paginate():\n for account in page['Accounts']:\n if account['Status'] == 'ACTIVE':\n account_map[account['Id']] = account['Name']\n except Exception as e:\n print(f\"Error fetching account list: {e}\")\n return account_map\n\ndef get_average_bandwidth_report():\n ce_client = boto3.client('ce')\n \n all_accounts = get_all_accounts()\n if not all_accounts:\n print(\"Could not retrieve account list. Check Organizations permissions.\")\n return\n\n # Set dates for the last 12 full months\n now = datetime.now()\n first_day_current_month = now.replace(day=1)\n end_date = first_day_current_month.strftime('%Y-%m-%d')\n start_date = (first_day_current_month - relativedelta(months=12)).strftime('%Y-%m-%d')\n\n # Initialize tracking: {acc_id: {'usage': 0.0, 'cost': 0.0}}\n account_totals = {acc_id: {'usage': 0.0, 'cost': 0.0} for acc_id in all_accounts.keys()}\n \n next_token = None\n\n try:\n while True:\n params = {\n 'TimePeriod': {'Start': start_date, 'End': end_date},\n 'Granularity': 'MONTHLY',\n 'Metrics': ['UsageQuantity', 'UnblendedCost'],\n 'GroupBy': [\n {'Type': 'DIMENSION', 'Key': 'LINKED_ACCOUNT'},\n {'Type': 'DIMENSION', 'Key': 'USAGE_TYPE'}\n ]\n }\n if next_token:\n params['NextPageToken'] = next_token\n\n response = ce_client.get_cost_and_usage(**params)\n\n for result in response['ResultsByTime']:\n for group in result['Groups']:\n acc_id = group['Keys'][0]\n usage_type = group['Keys'][1]\n usage_amount = float(group['Metrics']['UsageQuantity']['Amount'])\n unit = group['Metrics']['UsageQuantity']['Unit']\n cost_amount = float(group['Metrics']['UnblendedCost']['Amount'])\n\n # Bandwidth calculation logic from bwsuage.py\n if \"DataTransfer\" in usage_type:\n if unit == 'Bytes':\n usage_amount /= (1024**3)\n elif unit in ['MB', 'Megabytes']:\n usage_amount /= 1024\n \n if acc_id not in account_totals:\n account_totals[acc_id] = {'usage': 0.0, 'cost': 0.0}\n \n account_totals[acc_id]['usage'] += usage_amount\n account_totals[acc_id]['cost'] += cost_amount\n\n next_token = response.get('NextPageToken')\n if not next_token:\n break\n\n print(f\"\\n--- 12-Month Average Bandwidth Report ---\")\n print(f\"Period: {start_date} to {end_date}\")\n print(f\"{'Account Name':<25} | {'12m Total (GB)':<15} | {'Monthly Avg (GB)'}\")\n print(\"-\" * 75)\n\n # Sort by monthly average descending\n sorted_accounts = sorted(\n account_totals.items(), \n key=lambda x: x[1], \n reverse=True\n )\n \n for acc_id, total_usage in sorted_accounts:\n acc_name = all_accounts.get(acc_id, f\"Deleted/Unknown ({acc_id})\")\n avg_usage = total_usage / 12.0\n \n print(f\"{acc_name[:25]:<25} | {total_usage:>15.2f} | {avg_usage:>16.2f}\")\n\n print(f\"\\nTotal Accounts Scanned: {len(all_accounts)}\")\n\n except Exception as e:\n print(f\"Error: {e}\")\n\nif __name__ == \"__main__\":\n get_average_bandwidth_report()\n",
|
||||
"newContent": "import boto3\nfrom datetime import datetime, timedelta\nfrom dateutil.relativedelta import relativedelta\n\ndef get_all_accounts():\n \"\"\"Fetches every account ID and Name in the organization.\"\"\"\n org_client = boto3.client('organizations')\n account_map = {}\n try:\n paginator = org_client.get_paginator('list_accounts')\n for page in paginator.paginate():\n for account in page['Accounts']:\n if account['Status'] == 'ACTIVE':\n account_map[account['Id']] = account['Name']\n except Exception as e:\n print(f\"Error fetching account list: {e}\")\n return account_map\n\ndef get_average_bandwidth_report():\n ce_client = boto3.client('ce')\n \n all_accounts = get_all_accounts()\n if not all_accounts:\n print(\"Could not retrieve account list. Check Organizations permissions.\")\n return\n\n # Set dates for the last 12 full months\n now = datetime.now()\n first_day_current_month = now.replace(day=1)\n end_date = first_day_current_month.strftime('%Y-%m-%d')\n start_date = (first_day_current_month - relativedelta(months=12)).strftime('%Y-%m-%d')\n\n # Initialize tracking: {acc_id: {'usage': 0.0, 'cost': 0.0}}\n account_totals = {acc_id: {'usage': 0.0, 'cost': 0.0} for acc_id in all_accounts.keys()}\n \n next_token = None\n\n try:\n while True:\n params = {\n 'TimePeriod': {'Start': start_date, 'End': end_date},\n 'Granularity': 'MONTHLY',\n 'Metrics': ['UsageQuantity', 'UnblendedCost'],\n 'GroupBy': [\n {'Type': 'DIMENSION', 'Key': 'LINKED_ACCOUNT'},\n {'Type': 'DIMENSION', 'Key': 'USAGE_TYPE'}\n ]\n }\n if next_token:\n params['NextPageToken'] = next_token\n\n response = ce_client.get_cost_and_usage(**params)\n\n for result in response['ResultsByTime']:\n for group in result['Groups']:\n acc_id = group['Keys'][0]\n usage_type = group['Keys'][1]\n usage_amount = float(group['Metrics']['UsageQuantity']['Amount'])\n unit = group['Metrics']['UsageQuantity']['Unit']\n cost_amount = float(group['Metrics']['UnblendedCost']['Amount'])\n\n # Bandwidth calculation logic from bwsuage.py\n if \"DataTransfer\" in usage_type:\n if unit == 'Bytes':\n usage_amount /= (1024**3)\n elif unit in ['MB', 'Megabytes']:\n usage_amount /= 1024\n \n if acc_id not in account_totals:\n account_totals[acc_id] = {'usage': 0.0, 'cost': 0.0}\n \n account_totals[acc_id]['usage'] += usage_amount\n account_totals[acc_id]['cost'] += cost_amount\n\n next_token = response.get('NextPageToken')\n if not next_token:\n break\n\n print(f\"\\n--- 12-Month Average Bandwidth & Cost Report ---\")\n print(f\"Period: {start_date} to {end_date}\")\n print(f\"{'Account Name':<25} | {'Avg GB':<10} | {'Avg Cost ($)':<12} | {'12m Total ($)'}\")\n print(\"-\" * 80)\n\n # Sort by total cost descending\n sorted_accounts = sorted(\n account_totals.items(), \n key=lambda x: x[1]['cost'], \n reverse=True\n )\n \n for acc_id, totals in sorted_accounts:\n acc_name = all_accounts.get(acc_id, f\"Deleted/Unknown ({acc_id})\")\n avg_usage = totals['usage'] / 12.0\n avg_cost = totals['cost'] / 12.0\n total_cost = totals['cost']\n \n print(f\"{acc_name[:25]:<25} | {avg_usage:>10.2f} | {avg_cost:>12.2f} | {total_cost:>13.2f}\")\n\n print(f\"\\nTotal Accounts Scanned: {len(all_accounts)}\")\n\n except Exception as e:\n print(f\"Error: {e}\")\n\nif __name__ == \"__main__\":\n get_average_bandwidth_report()\n",
|
||||
"diffStat": {
|
||||
"model_added_lines": 10,
|
||||
"model_removed_lines": 8,
|
||||
"model_added_chars": 547,
|
||||
"model_removed_chars": 424,
|
||||
"user_added_lines": 1,
|
||||
"user_removed_lines": 87,
|
||||
"user_added_chars": 104,
|
||||
"user_removed_chars": 3297
|
||||
},
|
||||
"isNewFile": false
|
||||
},
|
||||
"displayName": "Edit",
|
||||
"description": "Replaces text within a file. By default, replaces a single occurrence, but can replace multiple occurrences when `expected_replacements` is specified. This tool requires providing significant context around the change to ensure precise targeting. Always use the read_file tool to examine the file's current content before attempting a text replacement.\n \n The user has the ability to modify the `new_string` content. If modified, this will be stated in the response.\n \n Expectation for required parameters:\n 1. `old_string` MUST be the exact literal text to replace (including all whitespace, indentation, newlines, and surrounding code etc.).\n 2. `new_string` MUST be the exact literal text to replace `old_string` with (also including all whitespace, indentation, newlines, and surrounding code etc.). Ensure the resulting code is correct and idiomatic and that `old_string` and `new_string` are different.\n 3. `instruction` is the detailed instruction of what needs to be changed. It is important to Make it specific and detailed so developers or large language models can understand what needs to be changed and perform the changes on their own if necessary. \n 4. NEVER escape `old_string` or `new_string`, that would break the exact literal text requirement.\n **Important:** If ANY of the above are not satisfied, the tool will fail. CRITICAL for `old_string`: Must uniquely identify the single instance to change. Include at least 3 lines of context BEFORE and AFTER the target text, matching whitespace and indentation precisely. If this string matches multiple locations, or does not match exactly, the tool will fail.\n 5. Prefer to break down complex and long changes into multiple smaller atomic calls to this tool. Always check the content of the file after changes or not finding a string to match.\n **Multiple replacements:** Set `expected_replacements` to the number of occurrences you want to replace. The tool will replace ALL occurrences that match `old_string` exactly. Ensure the number of replacements matches your expectation.",
|
||||
"renderOutputAsMarkdown": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "b28be19c-9cff-47a8-b419-cfa1d7ec974e",
|
||||
"timestamp": "2026-02-11T17:31:51.952Z",
|
||||
"type": "gemini",
|
||||
"content": "I have updated `avg_bandwidth_12months.py` to include average monthly cost. The script now queries for `UnblendedCost` and `UsageQuantity`, and the output table displays the average monthly GB, average monthly cost, and the 12-month total cost for each account.",
|
||||
"thoughts": [],
|
||||
"tokens": {
|
||||
"input": 21578,
|
||||
"output": 63,
|
||||
"cached": 0,
|
||||
"thoughts": 0,
|
||||
"tool": 0,
|
||||
"total": 21641
|
||||
},
|
||||
"model": "gemini-3-flash-preview"
|
||||
}
|
||||
]
|
||||
}
|
||||
12398
tmp/aws-stuff/chats/session-2026-02-12T16-16-c4349431.json
Normal file
12398
tmp/aws-stuff/chats/session-2026-02-12T16-16-c4349431.json
Normal file
File diff suppressed because one or more lines are too long
3280
tmp/aws-stuff/chats/session-2026-02-13T10-40-c642b0be.json
Normal file
3280
tmp/aws-stuff/chats/session-2026-02-13T10-40-c642b0be.json
Normal file
File diff suppressed because one or more lines are too long
989
tmp/aws-stuff/chats/session-2026-02-13T14-30-153fb7df.json
Normal file
989
tmp/aws-stuff/chats/session-2026-02-13T14-30-153fb7df.json
Normal file
@@ -0,0 +1,989 @@
|
||||
{
|
||||
"sessionId": "153fb7df-e3ce-41e9-b9ef-785e8c57d032",
|
||||
"projectHash": "c4ece9c032ac20d038bbd73e9aa5f86cb3fd24c826b8e99b6edcd77db288fcb1",
|
||||
"startTime": "2026-02-13T14:30:47.296Z",
|
||||
"lastUpdated": "2026-02-16T12:12:16.978Z",
|
||||
"messages": [
|
||||
{
|
||||
"id": "7965ed2a-a137-4692-b98d-f6b1d9cf55d3",
|
||||
"timestamp": "2026-02-13T14:30:47.296Z",
|
||||
"type": "error",
|
||||
"content": "Error during discovery for MCP server 'terraform': MCP error -32000: Connection closed"
|
||||
},
|
||||
{
|
||||
"id": "a7119688-9ba3-4e2d-8007-b56c5fa13e6a",
|
||||
"timestamp": "2026-02-13T14:31:30.868Z",
|
||||
"type": "user",
|
||||
"content": [
|
||||
{
|
||||
"text": "since we no longer use ruby. remove the Gemfile"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "0276521f-d1cf-48c6-8195-67b723925389",
|
||||
"timestamp": "2026-02-13T14:31:34.771Z",
|
||||
"type": "gemini",
|
||||
"content": "I will remove the Ruby-related files `Gemfile` and `Gemfile.lock` as they are no longer needed.",
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Assessing File Existence",
|
||||
"description": "I'm currently verifying the existence of the `Gemfile` and `Gemfile.lock`. Once I confirm their presence, I'll proceed with the removal of each file. It seems straightforward so far, but I always want to be careful and make sure before doing anything!",
|
||||
"timestamp": "2026-02-13T14:31:33.837Z"
|
||||
},
|
||||
{
|
||||
"subject": "Outlining Removal Procedures",
|
||||
"description": "I've sketched out the procedural steps for removing the `Gemfile` and `Gemfile.lock`. First, a verification step is planned to confirm the existence of both files. Then I'll execute the removal commands, followed by validation to ensure success. I am also making sure that these files can be easily re-added, should they be needed.",
|
||||
"timestamp": "2026-02-13T14:31:33.839Z"
|
||||
},
|
||||
{
|
||||
"subject": "Formulating the Deletion Strategy",
|
||||
"description": "Okay, so I've confirmed I need to get rid of `Gemfile` and `Gemfile.lock`, and the plan is in place. Now, I'm thinking about the most efficient way to achieve this. I will leverage `rm` commands and then will verify their removal. I'm aiming for clean and safe execution.",
|
||||
"timestamp": "2026-02-13T14:31:34.557Z"
|
||||
}
|
||||
],
|
||||
"tokens": {
|
||||
"input": 12958,
|
||||
"output": 56,
|
||||
"cached": 3303,
|
||||
"thoughts": 99,
|
||||
"tool": 0,
|
||||
"total": 13113
|
||||
},
|
||||
"model": "gemini-3-flash-preview",
|
||||
"toolCalls": [
|
||||
{
|
||||
"id": "run_shell_command-1770993094769-d9f3fd9d31297",
|
||||
"name": "run_shell_command",
|
||||
"args": {
|
||||
"command": "rm Gemfile Gemfile.lock",
|
||||
"description": "Remove unused Ruby Gemfile and Gemfile.lock."
|
||||
},
|
||||
"result": [
|
||||
{
|
||||
"functionResponse": {
|
||||
"id": "run_shell_command-1770993094769-d9f3fd9d31297",
|
||||
"name": "run_shell_command",
|
||||
"response": {
|
||||
"output": "Output: (empty)\nProcess Group PGID: 26041"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": "success",
|
||||
"timestamp": "2026-02-13T14:31:39.169Z",
|
||||
"resultDisplay": "",
|
||||
"displayName": "Shell",
|
||||
"description": "This tool executes a given shell command as `bash -c <command>`. To run a command in the background, set the `is_background` parameter to true. Do NOT use `&` to background commands. Command is executed as a subprocess that leads its own process group. Command process group can be terminated as `kill -- -PGID` or signaled as `kill -s SIGNAL -- -PGID`.\n\n The following information is returned:\n\n Output: Combined stdout/stderr. Can be `(empty)` or partial on error and for any unwaited background processes.\n Exit Code: Only included if non-zero (command failed).\n Error: Only included if a process-level error occurred (e.g., spawn failure).\n Signal: Only included if process was terminated by a signal.\n Background PIDs: Only included if background processes were started.\n Process Group PGID: Only included if available.",
|
||||
"renderOutputAsMarkdown": false
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "05892a81-459c-4a59-893d-cf6d993a60b1",
|
||||
"timestamp": "2026-02-13T14:31:41.639Z",
|
||||
"type": "gemini",
|
||||
"content": "",
|
||||
"toolCalls": [
|
||||
{
|
||||
"id": "list_directory-1770993101609-0442f7623b0e78",
|
||||
"name": "list_directory",
|
||||
"args": {
|
||||
"dir_path": "."
|
||||
},
|
||||
"result": [
|
||||
{
|
||||
"functionResponse": {
|
||||
"id": "list_directory-1770993101609-0442f7623b0e78",
|
||||
"name": "list_directory",
|
||||
"response": {
|
||||
"output": "Directory listing for /Users/bob/git/dxw/aws-stuff:\n[DIR] tests\n.env.example\n.gitignore\navg_bandwidth_12months.py\naws_bills.py\naws_cost.py\naws_utils.py\naws-asg-lt-ami.py\naws-ec2-ami.py\naws-ips.py\naws-metrics.py\naws-vpc.py\nbwsuage.py\ncloudfront.py\nec2_price.py\nGEMINI.md\ngenerate-billing-sheets.py\nlast-2-months-billing.py\nlist_rds_instances.py\nnot_running_latest.py\nrds_price.py\nREADME.md\nrequirements.txt\nservice-spend-by-account.py\nstorage-usage.py\nsummarize-ecsv.py\ntest.py\n\n(15 ignored)"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": "success",
|
||||
"timestamp": "2026-02-13T14:31:41.639Z",
|
||||
"resultDisplay": "Listed 27 item(s). (15 ignored)",
|
||||
"displayName": "ReadFolder",
|
||||
"description": "Lists the names of files and subdirectories directly within a specified directory path. Can optionally ignore entries matching provided glob patterns.",
|
||||
"renderOutputAsMarkdown": true
|
||||
}
|
||||
],
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Confirming the Deletion",
|
||||
"description": "I've just finished verifying the file removal. Everything seems to be as it should, with no trace of the items that were previously there. Further investigation isn't needed here. The task is complete.",
|
||||
"timestamp": "2026-02-13T14:31:41.411Z"
|
||||
}
|
||||
],
|
||||
"model": "gemini-3-flash-preview",
|
||||
"tokens": {
|
||||
"input": 13033,
|
||||
"output": 11,
|
||||
"cached": 3279,
|
||||
"thoughts": 11,
|
||||
"tool": 0,
|
||||
"total": 13055
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "8d6e6199-443f-46e8-a8e4-83013ff0e1a3",
|
||||
"timestamp": "2026-02-13T14:31:45.405Z",
|
||||
"type": "gemini",
|
||||
"content": "",
|
||||
"toolCalls": [
|
||||
{
|
||||
"id": "grep_search-1770993105344-b4d97f6dc70cf",
|
||||
"name": "grep_search",
|
||||
"args": {
|
||||
"pattern": "Gemfile|ruby"
|
||||
},
|
||||
"result": [
|
||||
{
|
||||
"functionResponse": {
|
||||
"id": "grep_search-1770993105344-b4d97f6dc70cf",
|
||||
"name": "grep_search",
|
||||
"response": {
|
||||
"output": "No matches found for pattern \"Gemfile|ruby\" in path \".\"."
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": "success",
|
||||
"timestamp": "2026-02-13T14:31:45.405Z",
|
||||
"resultDisplay": "No matches found",
|
||||
"displayName": "SearchText",
|
||||
"description": "Searches for a regular expression pattern within file contents. Max 100 matches.",
|
||||
"renderOutputAsMarkdown": true
|
||||
}
|
||||
],
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Analyzing File Deletions",
|
||||
"description": "I've deleted the `Gemfile` and `Gemfile.lock` successfully. Now, I'm verifying if these files were referenced anywhere, particularly in `.gitignore` or the `README.md` to ensure everything is tidy. Despite the user's specific request, I feel this extra step is beneficial.",
|
||||
"timestamp": "2026-02-13T14:31:44.337Z"
|
||||
},
|
||||
{
|
||||
"subject": "Refining Ruby Removal Scope",
|
||||
"description": "I've successfully deleted the `Gemfile` and `Gemfile.lock`. However, I'm now contemplating a broader cleanup. The initial user request was simple, yet I feel it would be best to check for other Ruby-related artifacts. I'm considering using `grep` to hunt for any \"Gemfile\" or \"ruby\" references to ensure a complete removal.",
|
||||
"timestamp": "2026-02-13T14:31:45.197Z"
|
||||
}
|
||||
],
|
||||
"model": "gemini-3-flash-preview",
|
||||
"tokens": {
|
||||
"input": 13244,
|
||||
"output": 12,
|
||||
"cached": 9845,
|
||||
"thoughts": 125,
|
||||
"tool": 0,
|
||||
"total": 13381
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "1a967a6f-3f2b-443d-a385-c3cfbf5d8e5e",
|
||||
"timestamp": "2026-02-13T14:31:47.691Z",
|
||||
"type": "gemini",
|
||||
"content": "",
|
||||
"toolCalls": [
|
||||
{
|
||||
"id": "read_file-1770993107658-24052daca2e02",
|
||||
"name": "read_file",
|
||||
"args": {
|
||||
"file_path": ".gitignore"
|
||||
},
|
||||
"result": [
|
||||
{
|
||||
"functionResponse": {
|
||||
"id": "read_file-1770993107658-24052daca2e02",
|
||||
"name": "read_file",
|
||||
"response": {
|
||||
"output": ".venv\n*csv\n*txt\n!requirements.txt\n__pycache__\n.env\n!.env.example\n*json\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": "success",
|
||||
"timestamp": "2026-02-13T14:31:47.691Z",
|
||||
"resultDisplay": "",
|
||||
"displayName": "ReadFile",
|
||||
"description": "Reads and returns the content of a specified file. If the file is large, the content will be truncated. The tool's response will clearly indicate if truncation has occurred and will provide details on how to read more of the file using the 'offset' and 'limit' parameters. Handles text, images (PNG, JPG, GIF, WEBP, SVG, BMP), audio files (MP3, WAV, AIFF, AAC, OGG, FLAC), and PDF files. For text files, it can read specific line ranges.",
|
||||
"renderOutputAsMarkdown": true
|
||||
}
|
||||
],
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Confirming the Changes",
|
||||
"description": "The cleanup is done. I've double-checked the `.gitignore` file, and everything appears to be in order. Ready to move forward.",
|
||||
"timestamp": "2026-02-13T14:31:47.456Z"
|
||||
}
|
||||
],
|
||||
"model": "gemini-3-flash-preview",
|
||||
"tokens": {
|
||||
"input": 13271,
|
||||
"output": 12,
|
||||
"cached": 9758,
|
||||
"thoughts": 18,
|
||||
"tool": 0,
|
||||
"total": 13301
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "b03f09bf-76ec-4137-a17e-63973abee504",
|
||||
"timestamp": "2026-02-13T14:31:49.956Z",
|
||||
"type": "gemini",
|
||||
"content": "The `Gemfile` and `Gemfile.lock` have been removed.",
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Reviewing `.gitignore` Status",
|
||||
"description": "I've just reviewed the `.gitignore` file and it seems to be in good shape. It appears to be free of Ruby-specific entries, save for some of the more general items. The task is complete.",
|
||||
"timestamp": "2026-02-13T14:31:49.928Z"
|
||||
}
|
||||
],
|
||||
"tokens": {
|
||||
"input": 13313,
|
||||
"output": 16,
|
||||
"cached": 12982,
|
||||
"thoughts": 21,
|
||||
"tool": 0,
|
||||
"total": 13350
|
||||
},
|
||||
"model": "gemini-3-flash-preview"
|
||||
},
|
||||
{
|
||||
"id": "33a48ae6-fad6-4996-b09b-cad8f02ec959",
|
||||
"timestamp": "2026-02-13T14:32:02.916Z",
|
||||
"type": "user",
|
||||
"content": [
|
||||
{
|
||||
"text": "commit thayt change"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "2f892fe1-a290-4906-a0cc-3c7044888300",
|
||||
"timestamp": "2026-02-13T14:32:09.070Z",
|
||||
"type": "gemini",
|
||||
"content": "",
|
||||
"toolCalls": [
|
||||
{
|
||||
"id": "run_shell_command-1770993126607-fc103f88ed8bd",
|
||||
"name": "run_shell_command",
|
||||
"args": {
|
||||
"description": "Check git status and recent commit history.",
|
||||
"command": "git status && git log -n 3"
|
||||
},
|
||||
"result": [
|
||||
{
|
||||
"functionResponse": {
|
||||
"id": "run_shell_command-1770993126607-fc103f88ed8bd",
|
||||
"name": "run_shell_command",
|
||||
"response": {
|
||||
"output": "Output: On branch main\nYour branch is up to date with 'origin/main'.\n\nChanges not staged for commit:\n (use \"git add/rm <file>...\" to update what will be committed)\n (use \"git restore <file>...\" to discard changes in working directory)\n deleted: Gemfile\n deleted: Gemfile.lock\n\nno changes added to commit (use \"git add\" and/or \"git commit -a\")\ncommit e5ed504207b3b9e8a40b084d2394cb2368d92dc4 (HEAD -> main, origin/main)\nAuthor: bob walker <bob@dxw.com>\nDate: Thu Feb 12 18:15:33 2026 +0000\n\n docs: update GEMINI.md with Google Sheets and testing patterns\n\ncommit a8b94a6635eeec598190fe1ed3e097a7295edb34\nAuthor: bob walker <bob@dxw.com>\nDate: Thu Feb 12 18:13:01 2026 +0000\n\n add test suite for aws_utils and script smoke tests\n\ncommit a283d031abcd6ff3d6a838bb8cba394101c3fcfe\nAuthor: bob walker <bob@dxw.com>\nDate: Thu Feb 12 18:10:37 2026 +0000\n\n docs: add Google Sheets setup and configuration details to README.md\nProcess Group PGID: 26077"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": "success",
|
||||
"timestamp": "2026-02-13T14:32:09.070Z",
|
||||
"resultDisplay": "On branch main\nYour branch is up to date with 'origin/main'.\n\nChanges not staged for commit:\n (use \"git add/rm <file>...\" to update what will be committed)\n (use \"git restore <file>...\" to discard changes in working directory)\n deleted: Gemfile\n deleted: Gemfile.lock\n\nno changes added to commit (use \"git add\" and/or \"git commit -a\")\ncommit e5ed504207b3b9e8a40b084d2394cb2368d92dc4 (HEAD -> main, origin/main)\nAuthor: bob walker <bob@dxw.com>\nDate: Thu Feb 12 18:15:33 2026 +0000\n\n docs: update GEMINI.md with Google Sheets and testing patterns\n\ncommit a8b94a6635eeec598190fe1ed3e097a7295edb34\nAuthor: bob walker <bob@dxw.com>\nDate: Thu Feb 12 18:13:01 2026 +0000\n\n add test suite for aws_utils and script smoke tests\n\ncommit a283d031abcd6ff3d6a838bb8cba394101c3fcfe\nAuthor: bob walker <bob@dxw.com>\nDate: Thu Feb 12 18:10:37 2026 +0000\n\n docs: add Google Sheets setup and configuration details to README.md",
|
||||
"displayName": "Shell",
|
||||
"description": "This tool executes a given shell command as `bash -c <command>`. To run a command in the background, set the `is_background` parameter to true. Do NOT use `&` to background commands. Command is executed as a subprocess that leads its own process group. Command process group can be terminated as `kill -- -PGID` or signaled as `kill -s SIGNAL -- -PGID`.\n\n The following information is returned:\n\n Output: Combined stdout/stderr. Can be `(empty)` or partial on error and for any unwaited background processes.\n Exit Code: Only included if non-zero (command failed).\n Error: Only included if a process-level error occurred (e.g., spawn failure).\n Signal: Only included if process was terminated by a signal.\n Background PIDs: Only included if background processes were started.\n Process Group PGID: Only included if available.",
|
||||
"renderOutputAsMarkdown": false
|
||||
}
|
||||
],
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Reviewing Git Operations",
|
||||
"description": "I'm currently reviewing the steps required for this Git operation. I see the user wants to remove two files. First, I need to check the status. Then, I'll need to stage the deletion of the `Gemfile` and `Gemfile.lock` files, making sure the staging area reflects these changes accurately. Finally, I will commit the staged changes.",
|
||||
"timestamp": "2026-02-13T14:32:05.268Z"
|
||||
},
|
||||
{
|
||||
"subject": "Refining Commit Strategy",
|
||||
"description": "I'm now zeroing in on the commit stage. My plan has evolved. After a `git status` check to confirm the files are slated for deletion, I'm thinking of incorporating a `git diff HEAD` to pre-emptively review the impending commit. I'll also glance at recent commit messages with `git log -n 3` to align with the repository's style guidelines before proceeding. The user's goal of removing the `Gemfile` and `Gemfile.lock` files is crystal clear now.",
|
||||
"timestamp": "2026-02-13T14:32:06.369Z"
|
||||
}
|
||||
],
|
||||
"model": "gemini-3-flash-preview",
|
||||
"tokens": {
|
||||
"input": 13333,
|
||||
"output": 28,
|
||||
"cached": 9892,
|
||||
"thoughts": 131,
|
||||
"tool": 0,
|
||||
"total": 13492
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "235a2957-97af-47f7-8834-c5cdd352579b",
|
||||
"timestamp": "2026-02-13T14:32:20.998Z",
|
||||
"type": "gemini",
|
||||
"content": "",
|
||||
"toolCalls": [
|
||||
{
|
||||
"id": "run_shell_command-1770993133051-c2b0dfb680a238",
|
||||
"name": "run_shell_command",
|
||||
"args": {
|
||||
"command": "git add Gemfile Gemfile.lock && git status && git diff --staged",
|
||||
"description": "Stage the deletions and review the staged changes."
|
||||
},
|
||||
"result": [
|
||||
{
|
||||
"functionResponse": {
|
||||
"id": "run_shell_command-1770993133051-c2b0dfb680a238",
|
||||
"name": "run_shell_command",
|
||||
"response": {
|
||||
"output": "Output: On branch main\nYour branch is up to date with 'origin/main'.\n\nChanges to be committed:\n (use \"git restore --staged <file>...\" to unstage)\n deleted: Gemfile\n deleted: Gemfile.lock\n\ndiff --git a/Gemfile b/Gemfile\ndeleted file mode 100644\nindex 72884af..0000000\n--- a/Gemfile\n+++ /dev/null\n@@ -1,11 +0,0 @@\n-# frozen_string_literal: true\n-\n-source \"https://rubygems.org\"\n-\n-# gem \"rails\"\n-\n-gem \"aws-sdk-costexplorer\", \"~> 1.106\"\n-\n-gem \"nokogiri\", \"~> 1.16\"\n-\n-gem \"aws-sdk-organizations\", \"~> 1.97\"\ndiff --git a/Gemfile.lock b/Gemfile.lock\ndeleted file mode 100644\nindex 6f9ec60..0000000\n--- a/Gemfile.lock\n+++ /dev/null\n@@ -1,33 +0,0 @@\n-GEM\n- remote: https://rubygems.org/\n- specs:\n- aws-eventstream (1.3.0)\n- aws-partitions (1.971.0)\n- aws-sdk-core (3.203.0)\n- aws-eventstream (~> 1, >= 1.3.0)\n- aws-partitions (~> 1, >= 1.651.0)\n- aws-sigv4 (~> 1.9)\n- jmespath (~> 1, >= 1.6.1)\n- aws-sdk-costexplorer (1.106.0)\n- aws-sdk-core (~> 3, >= 3.203.0)\n- aws-sigv4 (~> 1.5)\n- aws-sdk-organizations (1.97.0)\n- aws-sdk-core (~> 3, >= 3.203.0)\n- aws-sigv4 (~> 1.5)\n- aws-sigv4 (1.9.1)\n- aws-eventstream (~> 1, >= 1.0.2)\n- jmespath (1.6.2)\n- nokogiri (1.16.7-arm64-darwin)\n- racc (~> 1.4)\n- racc (1.8.1)\n-\n-PLATFORMS\n- arm64-darwin-22\n-\n-DEPENDENCIES\n- aws-sdk-costexplorer (~> 1.106)\n- aws-sdk-organizations (~> 1.97)\n- nokogiri (~> 1.16)\n-\n-BUNDLED WITH\n- 2.4.1\nProcess Group PGID: 26110"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": "success",
|
||||
"timestamp": "2026-02-13T14:32:20.998Z",
|
||||
"resultDisplay": "On branch main\nYour branch is up to date with 'origin/main'.\n\nChanges to be committed:\n (use \"git restore --staged <file>...\" to unstage)\n deleted: Gemfile\n deleted: Gemfile.lock\n\ndiff --git a/Gemfile b/Gemfile\ndeleted file mode 100644\nindex 72884af..0000000\n--- a/Gemfile\n+++ /dev/null\n@@ -1,11 +0,0 @@\n-# frozen_string_literal: true\n-\n-source \"https://rubygems.org\"\n-\n-# gem \"rails\"\n-\n-gem \"aws-sdk-costexplorer\", \"~> 1.106\"\n-\n-gem \"nokogiri\", \"~> 1.16\"\n-\n-gem \"aws-sdk-organizations\", \"~> 1.97\"\ndiff --git a/Gemfile.lock b/Gemfile.lock\ndeleted file mode 100644\nindex 6f9ec60..0000000\n--- a/Gemfile.lock\n+++ /dev/null\n@@ -1,33 +0,0 @@\n-GEM\n- remote: https://rubygems.org/\n- specs:\n- aws-eventstream (1.3.0)\n- aws-partitions (1.971.0)\n- aws-sdk-core (3.203.0)\n- aws-eventstream (~> 1, >= 1.3.0)\n- aws-partitions (~> 1, >= 1.651.0)\n- aws-sigv4 (~> 1.9)\n- jmespath (~> 1, >= 1.6.1)\n- aws-sdk-costexplorer (1.106.0)\n- aws-sdk-core (~> 3, >= 3.203.0)\n- aws-sigv4 (~> 1.5)\n- aws-sdk-organizations (1.97.0)\n- aws-sdk-core (~> 3, >= 3.203.0)\n- aws-sigv4 (~> 1.5)\n- aws-sigv4 (1.9.1)\n- aws-eventstream (~> 1, >= 1.0.2)\n- jmespath (1.6.2)\n- nokogiri (1.16.7-arm64-darwin)\n- racc (~> 1.4)\n- racc (1.8.1)\n-\n-PLATFORMS\n- arm64-darwin-22\n-\n-DEPENDENCIES\n- aws-sdk-costexplorer (~> 1.106)\n- aws-sdk-organizations (~> 1.97)\n- nokogiri (~> 1.16)\n-\n-BUNDLED WITH\n- 2.4.1",
|
||||
"displayName": "Shell",
|
||||
"description": "This tool executes a given shell command as `bash -c <command>`. To run a command in the background, set the `is_background` parameter to true. Do NOT use `&` to background commands. Command is executed as a subprocess that leads its own process group. Command process group can be terminated as `kill -- -PGID` or signaled as `kill -s SIGNAL -- -PGID`.\n\n The following information is returned:\n\n Output: Combined stdout/stderr. Can be `(empty)` or partial on error and for any unwaited background processes.\n Exit Code: Only included if non-zero (command failed).\n Error: Only included if a process-level error occurred (e.g., spawn failure).\n Signal: Only included if process was terminated by a signal.\n Background PIDs: Only included if background processes were started.\n Process Group PGID: Only included if available.",
|
||||
"renderOutputAsMarkdown": false
|
||||
}
|
||||
],
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Examining Commit Messages",
|
||||
"description": "I'm currently reviewing my commit history, noticing a pattern emerging in the commit messages. I plan to adopt a conventional format using `type: description`. The options seem to be `build` or `chore`, but I'll make sure to use the right one. I'm leaning towards `build: remove unused Ruby files` or `cleanup: remove Gemfile` for the next steps.",
|
||||
"timestamp": "2026-02-13T14:32:11.988Z"
|
||||
},
|
||||
{
|
||||
"subject": "Revisiting Commit Structure",
|
||||
"description": "I've already applied the `type: description` approach. I am now evaluating `docs:`, and `add:` from the existing commit history. The staging is done. Next, I need to commit, and I see `cleanup:` is not yet in the mix.",
|
||||
"timestamp": "2026-02-13T14:32:12.816Z"
|
||||
}
|
||||
],
|
||||
"model": "gemini-3-flash-preview",
|
||||
"tokens": {
|
||||
"input": 13760,
|
||||
"output": 37,
|
||||
"cached": 9856,
|
||||
"thoughts": 99,
|
||||
"tool": 0,
|
||||
"total": 13896
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "ae10c165-aa49-4c9a-9e64-f1a4320d3642",
|
||||
"timestamp": "2026-02-13T14:32:29.304Z",
|
||||
"type": "gemini",
|
||||
"content": "",
|
||||
"toolCalls": [
|
||||
{
|
||||
"id": "run_shell_command-1770993144184-3ab93734e6dab",
|
||||
"name": "run_shell_command",
|
||||
"args": {
|
||||
"description": "Commit the removal of Ruby files and check the status.",
|
||||
"command": "git commit -m \"cleanup: remove unused Ruby Gemfile and Gemfile.lock\" && git status"
|
||||
},
|
||||
"result": [
|
||||
{
|
||||
"functionResponse": {
|
||||
"id": "run_shell_command-1770993144184-3ab93734e6dab",
|
||||
"name": "run_shell_command",
|
||||
"response": {
|
||||
"output": "Output: [main 81fd53e] cleanup: remove unused Ruby Gemfile and Gemfile.lock\n 2 files changed, 44 deletions(-)\n delete mode 100644 Gemfile\n delete mode 100644 Gemfile.lock\nOn branch main\nYour branch is ahead of 'origin/main' by 1 commit.\n (use \"git push\" to publish your local commits)\n\nnothing to commit, working tree clean\nProcess Group PGID: 26117"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": "success",
|
||||
"timestamp": "2026-02-13T14:32:29.304Z",
|
||||
"resultDisplay": "[main 81fd53e] cleanup: remove unused Ruby Gemfile and Gemfile.lock\n 2 files changed, 44 deletions(-)\n delete mode 100644 Gemfile\n delete mode 100644 Gemfile.lock\nOn branch main\nYour branch is ahead of 'origin/main' by 1 commit.\n (use \"git push\" to publish your local commits)\n\nnothing to commit, working tree clean",
|
||||
"displayName": "Shell",
|
||||
"description": "This tool executes a given shell command as `bash -c <command>`. To run a command in the background, set the `is_background` parameter to true. Do NOT use `&` to background commands. Command is executed as a subprocess that leads its own process group. Command process group can be terminated as `kill -- -PGID` or signaled as `kill -s SIGNAL -- -PGID`.\n\n The following information is returned:\n\n Output: Combined stdout/stderr. Can be `(empty)` or partial on error and for any unwaited background processes.\n Exit Code: Only included if non-zero (command failed).\n Error: Only included if a process-level error occurred (e.g., spawn failure).\n Signal: Only included if process was terminated by a signal.\n Background PIDs: Only included if background processes were started.\n Process Group PGID: Only included if available.",
|
||||
"renderOutputAsMarkdown": false
|
||||
}
|
||||
],
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Formulating the Commit",
|
||||
"description": "I'm finalizing the commit message. The aim is a concise explanation of the changes, so I've decided on: `cleanup: remove unused Ruby Gemfile and Gemfile.lock`. This follows the pattern of my previous commit messages, focusing on clarity and conciseness.",
|
||||
"timestamp": "2026-02-13T14:32:23.290Z"
|
||||
},
|
||||
{
|
||||
"subject": "Finalizing the Message",
|
||||
"description": "Now I've reviewed the commit message. It fits with my usual style, focusing on the essential information. The previous messages provide a good framework, and I am ready to push this. I've confirmed that the files are indeed unused.",
|
||||
"timestamp": "2026-02-13T14:32:24.007Z"
|
||||
}
|
||||
],
|
||||
"model": "gemini-3-flash-preview",
|
||||
"tokens": {
|
||||
"input": 14521,
|
||||
"output": 43,
|
||||
"cached": 13182,
|
||||
"thoughts": 104,
|
||||
"tool": 0,
|
||||
"total": 14668
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "ff05ce02-da7a-48d0-9aba-043d24b2d179",
|
||||
"timestamp": "2026-02-13T14:32:30.898Z",
|
||||
"type": "gemini",
|
||||
"content": "The changes have been committed.\n\n```bash\ncleanup: remove unused Ruby Gemfile and Gemfile.lock\n```",
|
||||
"thoughts": [],
|
||||
"tokens": {
|
||||
"input": 14681,
|
||||
"output": 24,
|
||||
"cached": 13110,
|
||||
"thoughts": 0,
|
||||
"tool": 0,
|
||||
"total": 14705
|
||||
},
|
||||
"model": "gemini-3-flash-preview"
|
||||
},
|
||||
{
|
||||
"id": "d8ce28aa-0acf-4fd0-88b7-3aea2f4781a8",
|
||||
"timestamp": "2026-02-13T14:33:25.755Z",
|
||||
"type": "user",
|
||||
"content": [
|
||||
{
|
||||
"text": "this repo is now called aws-utils and is in the dxw git org. https://github.com/dxw/aws-utils update any docs."
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "340d74de-af04-47bb-af98-885e1eabdb0a",
|
||||
"timestamp": "2026-02-13T14:33:29.381Z",
|
||||
"type": "gemini",
|
||||
"content": "",
|
||||
"toolCalls": [
|
||||
{
|
||||
"id": "grep_search-1770993209341-3873f6d6cab3",
|
||||
"name": "grep_search",
|
||||
"args": {
|
||||
"pattern": "aws-stuff|github\\.com/.*aws-stuff"
|
||||
},
|
||||
"result": [
|
||||
{
|
||||
"functionResponse": {
|
||||
"id": "grep_search-1770993209341-3873f6d6cab3",
|
||||
"name": "grep_search",
|
||||
"response": {
|
||||
"output": "Found 1 match for pattern \"aws-stuff|github\\.com/.*aws-stuff\" in path \".\":\n---\nFile: README.md\nL16: cd aws-stuff\n---"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": "success",
|
||||
"timestamp": "2026-02-13T14:33:29.380Z",
|
||||
"resultDisplay": "Found 1 match",
|
||||
"displayName": "SearchText",
|
||||
"description": "Searches for a regular expression pattern within file contents. Max 100 matches.",
|
||||
"renderOutputAsMarkdown": true
|
||||
}
|
||||
],
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Documenting the Repo Change",
|
||||
"description": "I've begun the process of updating the documentation. Initially, I'm focusing on locating all instances of the old repository name and URL. My next step will be replacing those references. I plan to use search and replace functionality to make the changes efficiently. Then, I'll review everything.",
|
||||
"timestamp": "2026-02-13T14:33:28.315Z"
|
||||
},
|
||||
{
|
||||
"subject": "Locating the References",
|
||||
"description": "I'm deep in the search phase, scanning the codebase for any remnants of the old repository details. I've initiated searches for `aws-stuff` as a starting point. Now, I'm expanding the search to catch any other outdated references. I'm taking care to cast a wide net to ensure no mention slips through.",
|
||||
"timestamp": "2026-02-13T14:33:29.137Z"
|
||||
}
|
||||
],
|
||||
"model": "gemini-3-flash-preview",
|
||||
"tokens": {
|
||||
"input": 14738,
|
||||
"output": 20,
|
||||
"cached": 13365,
|
||||
"thoughts": 98,
|
||||
"tool": 0,
|
||||
"total": 14856
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "d7938f10-b19c-4f7b-a141-34fa384046e4",
|
||||
"timestamp": "2026-02-13T14:33:31.683Z",
|
||||
"type": "gemini",
|
||||
"content": "",
|
||||
"toolCalls": [
|
||||
{
|
||||
"id": "read_file-1770993211665-4cc0f2ebe2157",
|
||||
"name": "read_file",
|
||||
"args": {
|
||||
"file_path": "README.md"
|
||||
},
|
||||
"result": [
|
||||
{
|
||||
"functionResponse": {
|
||||
"id": "read_file-1770993211665-4cc0f2ebe2157",
|
||||
"name": "read_file",
|
||||
"response": {
|
||||
"output": "# AWS Organization Audit Scripts\n\nA collection of Python scripts designed to audit and report on resources, costs, and configurations across multiple AWS accounts within an Organization.\n\n## Prerequisites\n\n- **Python 3.8+**\n- **AWS CLI** configured with SSO profiles.\n- **Virtualenv** (highly recommended)\n\n## Setup\n\n1. **Clone the repository:**\n ```bash\n git clone <repository-url>\n cd aws-stuff\n ```\n\n2. **Create and activate a virtual environment:**\n ```bash\n python3 -m venv .venv\n source .venv/bin/activate\n ```\n\n3. **Install dependencies:**\n ```bash\n pip install -r requirements.txt\n ```\n\n4. **Configure your environment:**\n Copy the example environment file and fill in your details:\n ```bash\n cp .env.example .env\n ```\n Edit `.env`:\n - `AWS_PARENT_PROFILE`: The SSO profile used to access the Organizations and Pricing APIs (e.g., your master account profile).\n - `OU_IDS`: Comma-separated list of Organizational Unit IDs to scan.\n - `SKIP_ACCOUNTS`: Comma-separated list of Account IDs to exclude from scans.\n - `GOOGLE_CLIENT_SECRET_FILE`: (Optional) Path to your Google API client secret JSON file. Defaults to `client_secret.json`.\n - `GOOGLE_AUTHORIZED_USER_FILE`: (Optional) Path where the Google auth token will be stored. Defaults to `authorized_user.json`.\n\n## Google Sheets Integration\n\nSeveral scripts automatically export their output to Google Sheets in addition to local CSV files.\n\n### Setup\n1. Create a project in the [Google Cloud Console](https://console.cloud.google.com/).\n2. Enable the **Google Sheets API** and **Google Drive API**.\n3. Create **OAuth 2.0 Client ID** credentials (Desktop app).\n4. Download the JSON file and save it as `client_secret.json` in the project root (or set `GOOGLE_CLIENT_SECRET_FILE`).\n5. On the first run, a browser window will open for authentication. The resulting token is saved to `authorized_user.json`.\n\nIf these files are missing, the scripts will skip the Google Sheets export and only produce CSVs.\n\n## Script Overview\n\nThe project uses a shared `aws_utils.py` module to handle SSO login, date ranges, and account iteration.\n\n### Cost & Billing\n- `aws_bills.py`: Comparison of Amortized and Unblended costs over the last 3 months.\n- `aws_cost.py`: Detailed EC2 cost report including compute savings.\n- `bwsuage.py`: Monthly bandwidth usage report with overage alerts (>100GB).\n- `storage-usage.py`: Monthly storage report (S3, EBS, RDS, EFS).\n- `generate-billing-sheets.py`: Generates detailed Google Sheets reports (requires Google API credentials).\n- `summarize-ecsv.py`: Parses exported AWS billing CSV files for local analysis.\n\n### Resource Inventory\n- `aws-vpc.py`: Lists VPCs and CIDR blocks across all accounts/regions.\n- `aws-ips.py`: Lists public IPs, EIPs, and internet-facing Load Balancer DNS names.\n- `list_rds_instances.py`: Lists all RDS instances and clusters.\n- `cloudfront.py`: Lists CloudFront distributions and their status.\n- `aws-asg-lt-ami.py`: Audits Auto Scaling Groups, Launch Templates, and associated AMIs.\n- `aws-ec2-ami.py`: Inventories running EC2 instances and their AMI IDs.\n\n### Pricing\n- `ec2_price.py`: Fetches current on-demand pricing for T3 instance families in London.\n- `rds_price.py`: Fetches current on-demand pricing for RDS MySQL/PostgreSQL in London.\n\n## Usage\n\nMost scripts run autonomously once your `.env` is configured:\n```bash\npython <script_name>.py\n```\nIf your AWS SSO session has expired, the scripts will automatically attempt to trigger `aws sso login` using your defined parent profile.\n\n## Contributing\n\nWhen adding new scripts, leverage `aws_utils.py` for:\n- `setup_org_accounts_session()`: Iterates through accounts in your OUs.\n- `ensure_sso_login()`: Handles session validation.\n- `get_previous_month_range()`: Standardizes billing periods.\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": "success",
|
||||
"timestamp": "2026-02-13T14:33:31.683Z",
|
||||
"resultDisplay": "",
|
||||
"displayName": "ReadFile",
|
||||
"description": "Reads and returns the content of a specified file. If the file is large, the content will be truncated. The tool's response will clearly indicate if truncation has occurred and will provide details on how to read more of the file using the 'offset' and 'limit' parameters. Handles text, images (PNG, JPG, GIF, WEBP, SVG, BMP), audio files (MP3, WAV, AIFF, AAC, OGG, FLAC), and PDF files. For text files, it can read specific line ranges.",
|
||||
"renderOutputAsMarkdown": true
|
||||
}
|
||||
],
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Scanning for Placeholders",
|
||||
"description": "I've located a match in `README.md`. Now, I'm shifting focus to identify potential generic placeholders within the project, such as `<repository-url>`. This search will encompass a broader scope, ensuring no common placeholders are missed.",
|
||||
"timestamp": "2026-02-13T14:33:31.489Z"
|
||||
}
|
||||
],
|
||||
"model": "gemini-3-flash-preview",
|
||||
"tokens": {
|
||||
"input": 14801,
|
||||
"output": 13,
|
||||
"cached": 13281,
|
||||
"thoughts": 31,
|
||||
"tool": 0,
|
||||
"total": 14845
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "ec2f86ca-8bf4-40c3-adcf-632a3997de29",
|
||||
"timestamp": "2026-02-13T14:33:33.932Z",
|
||||
"type": "gemini",
|
||||
"content": "",
|
||||
"toolCalls": [
|
||||
{
|
||||
"id": "read_file-1770993213914-2429220766bae8",
|
||||
"name": "read_file",
|
||||
"args": {
|
||||
"file_path": "GEMINI.md"
|
||||
},
|
||||
"result": [
|
||||
{
|
||||
"functionResponse": {
|
||||
"id": "read_file-1770993213914-2429220766bae8",
|
||||
"name": "read_file",
|
||||
"response": {
|
||||
"output": "# Gemini CLI Project Context - AWS Organization Audit Scripts\n\n## Project Overview\nThis repository contains a collection of Python scripts for auditing AWS Organizations. It handles multi-account discovery, SSO authentication, and generates reports on costs, bandwidth, and resource inventory.\n\n## Core Guidelines\n\n- **Shared Logic:** All AWS interaction MUST go through `aws_utils.py`. Never initialize `boto3.client` directly without first ensuring a session via `aws_utils`.\n- **Authentication:** Use `ensure_sso_login()` to handle AWS SSO sessions. This triggers `aws sso login` via the CLI if the session is expired.\n- **Session Management:** \n - Use `get_boto_session()` for parent/management account tasks (Organizations, Pricing API).\n - Use `setup_org_accounts_session()` to iterate through accounts in specific OUs or the entire organization. This handles profile switching for multi-account scans and unsets conflicting IAM env vars.\n- **Configuration:** \n - Honor environment variables: `AWS_PARENT_PROFILE`, `OU_IDS`, `SKIP_ACCOUNTS`, `GOOGLE_CLIENT_SECRET_FILE`, and `GOOGLE_AUTHORIZED_USER_FILE`.\n - Support `.env` files via `python-dotenv` (handled in `aws_utils.py`).\n- **Reporting:** \n - For large datasets, prefer CSV output using the `csv` module.\n - **Google Sheets:** Use `export_to_sheets(title, headers, rows)` from `aws_utils.py` to automatically export CSV data to Google Sheets.\n - For console summaries, use formatted tables with `print` or `pandas`.\n\n## Key Patterns\n\n### Account Iteration\nAlways use the generator pattern for cross-account audits:\n```python\nfrom aws_utils import setup_org_accounts_session\nfor account, profile_name in setup_org_accounts_session():\n boto3.setup_default_session(profile_name=profile_name)\n # ... account-specific logic ...\n```\n\n### Date Handling\nStandardize billing periods using `aws_utils.py` helpers:\n- `get_previous_month_range()`: Returns `(start, end)` for the last full month.\n- `get_last_n_months_ranges(n)`: Returns list of ranges for historical analysis.\n\n### Testing\n- Place tests in the `tests/` directory.\n- Use `unittest` and `unittest.mock`.\n- **Mocks:** Always mock `aws_utils.get_boto_session` and AWS clients to ensure tests run without credentials or network access.\n\n## Tooling & Dependencies\n- **Primary:** `boto3`, `pandas`, `python-dotenv`.\n- **Secondary:** `gspread`, `google-auth-oauthlib` (for Google Sheets reports).\n- **Environment:** Always execute within the project's virtual environment (`.venv`).\n\n## Security & Privacy\n- **Identifiers:** Never hardcode Account IDs, OU IDs, or Profile Names. Use the configuration patterns in `aws_utils`.\n- **Sanitization:** When creating examples or documentation, use generic placeholders like `ou-1234-abcd5678` or `123456789012`.\n- **Environment:** Do not commit `.env` files or Google authentication JSON files (`client_secret.json`, `authorized_user.json`).\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": "success",
|
||||
"timestamp": "2026-02-13T14:33:33.932Z",
|
||||
"resultDisplay": "",
|
||||
"displayName": "ReadFile",
|
||||
"description": "Reads and returns the content of a specified file. If the file is large, the content will be truncated. The tool's response will clearly indicate if truncation has occurred and will provide details on how to read more of the file using the 'offset' and 'limit' parameters. Handles text, images (PNG, JPG, GIF, WEBP, SVG, BMP), audio files (MP3, WAV, AIFF, AAC, OGG, FLAC), and PDF files. For text files, it can read specific line ranges.",
|
||||
"renderOutputAsMarkdown": true
|
||||
}
|
||||
],
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Checking Documentation References",
|
||||
"description": "I've begun by updating the `README.md` file with the correct repository details. Now, I'm carefully reviewing `GEMINI.md`, ensuring all references align with the recent URL and directory name changes. I'll make sure there are no overlooked links.",
|
||||
"timestamp": "2026-02-13T14:33:33.736Z"
|
||||
}
|
||||
],
|
||||
"model": "gemini-3-flash-preview",
|
||||
"tokens": {
|
||||
"input": 15811,
|
||||
"output": 14,
|
||||
"cached": 13402,
|
||||
"thoughts": 34,
|
||||
"tool": 0,
|
||||
"total": 15859
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "f3731ad3-5ee8-434e-bdc3-b7748bc30780",
|
||||
"timestamp": "2026-02-13T14:33:47.783Z",
|
||||
"type": "gemini",
|
||||
"content": "",
|
||||
"toolCalls": [
|
||||
{
|
||||
"id": "replace-1770993217087-4ec24459c97788",
|
||||
"name": "replace",
|
||||
"args": {
|
||||
"old_string": "## Setup\n\n1. **Clone the repository:**\n ```bash\n git clone <repository-url>\n cd aws-stuff\n ```\n\n2. **Create and activate a virtual environment:**",
|
||||
"file_path": "/Users/bob/git/dxw/aws-stuff/README.md",
|
||||
"instruction": "Update the repository URL and the directory name in the 'Setup' section of README.md to reflect the new repository name 'aws-utils' and its location in the 'dxw' GitHub organization.",
|
||||
"new_string": "## Setup\n\n1. **Clone the repository:**\n ```bash\n git clone https://github.com/dxw/aws-utils\n cd aws-utils\n ```\n\n2. **Create and activate a virtual environment:**"
|
||||
},
|
||||
"result": [
|
||||
{
|
||||
"functionResponse": {
|
||||
"id": "replace-1770993217087-4ec24459c97788",
|
||||
"name": "replace",
|
||||
"response": {
|
||||
"output": "Successfully modified file: /Users/bob/git/dxw/aws-stuff/README.md (1 replacements)."
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": "success",
|
||||
"timestamp": "2026-02-13T14:33:47.783Z",
|
||||
"resultDisplay": {
|
||||
"fileDiff": "Index: README.md\n===================================================================\n--- README.md\tCurrent\n+++ README.md\tProposed\n@@ -12,8 +12,8 @@\n \n 1. **Clone the repository:**\n ```bash\n- git clone <repository-url>\n- cd aws-stuff\n+ git clone https://github.com/dxw/aws-utils\n+ cd aws-utils\n ```\n \n 2. **Create and activate a virtual environment:**\n",
|
||||
"fileName": "README.md",
|
||||
"filePath": "/Users/bob/git/dxw/aws-stuff/README.md",
|
||||
"originalContent": "# AWS Organization Audit Scripts\n\nA collection of Python scripts designed to audit and report on resources, costs, and configurations across multiple AWS accounts within an Organization.\n\n## Prerequisites\n\n- **Python 3.8+**\n- **AWS CLI** configured with SSO profiles.\n- **Virtualenv** (highly recommended)\n\n## Setup\n\n1. **Clone the repository:**\n ```bash\n git clone <repository-url>\n cd aws-stuff\n ```\n\n2. **Create and activate a virtual environment:**\n ```bash\n python3 -m venv .venv\n source .venv/bin/activate\n ```\n\n3. **Install dependencies:**\n ```bash\n pip install -r requirements.txt\n ```\n\n4. **Configure your environment:**\n Copy the example environment file and fill in your details:\n ```bash\n cp .env.example .env\n ```\n Edit `.env`:\n - `AWS_PARENT_PROFILE`: The SSO profile used to access the Organizations and Pricing APIs (e.g., your master account profile).\n - `OU_IDS`: Comma-separated list of Organizational Unit IDs to scan.\n - `SKIP_ACCOUNTS`: Comma-separated list of Account IDs to exclude from scans.\n - `GOOGLE_CLIENT_SECRET_FILE`: (Optional) Path to your Google API client secret JSON file. Defaults to `client_secret.json`.\n - `GOOGLE_AUTHORIZED_USER_FILE`: (Optional) Path where the Google auth token will be stored. Defaults to `authorized_user.json`.\n\n## Google Sheets Integration\n\nSeveral scripts automatically export their output to Google Sheets in addition to local CSV files.\n\n### Setup\n1. Create a project in the [Google Cloud Console](https://console.cloud.google.com/).\n2. Enable the **Google Sheets API** and **Google Drive API**.\n3. Create **OAuth 2.0 Client ID** credentials (Desktop app).\n4. Download the JSON file and save it as `client_secret.json` in the project root (or set `GOOGLE_CLIENT_SECRET_FILE`).\n5. On the first run, a browser window will open for authentication. The resulting token is saved to `authorized_user.json`.\n\nIf these files are missing, the scripts will skip the Google Sheets export and only produce CSVs.\n\n## Script Overview\n\nThe project uses a shared `aws_utils.py` module to handle SSO login, date ranges, and account iteration.\n\n### Cost & Billing\n- `aws_bills.py`: Comparison of Amortized and Unblended costs over the last 3 months.\n- `aws_cost.py`: Detailed EC2 cost report including compute savings.\n- `bwsuage.py`: Monthly bandwidth usage report with overage alerts (>100GB).\n- `storage-usage.py`: Monthly storage report (S3, EBS, RDS, EFS).\n- `generate-billing-sheets.py`: Generates detailed Google Sheets reports (requires Google API credentials).\n- `summarize-ecsv.py`: Parses exported AWS billing CSV files for local analysis.\n\n### Resource Inventory\n- `aws-vpc.py`: Lists VPCs and CIDR blocks across all accounts/regions.\n- `aws-ips.py`: Lists public IPs, EIPs, and internet-facing Load Balancer DNS names.\n- `list_rds_instances.py`: Lists all RDS instances and clusters.\n- `cloudfront.py`: Lists CloudFront distributions and their status.\n- `aws-asg-lt-ami.py`: Audits Auto Scaling Groups, Launch Templates, and associated AMIs.\n- `aws-ec2-ami.py`: Inventories running EC2 instances and their AMI IDs.\n\n### Pricing\n- `ec2_price.py`: Fetches current on-demand pricing for T3 instance families in London.\n- `rds_price.py`: Fetches current on-demand pricing for RDS MySQL/PostgreSQL in London.\n\n## Usage\n\nMost scripts run autonomously once your `.env` is configured:\n```bash\npython <script_name>.py\n```\nIf your AWS SSO session has expired, the scripts will automatically attempt to trigger `aws sso login` using your defined parent profile.\n\n## Contributing\n\nWhen adding new scripts, leverage `aws_utils.py` for:\n- `setup_org_accounts_session()`: Iterates through accounts in your OUs.\n- `ensure_sso_login()`: Handles session validation.\n- `get_previous_month_range()`: Standardizes billing periods.\n",
|
||||
"newContent": "# AWS Organization Audit Scripts\n\nA collection of Python scripts designed to audit and report on resources, costs, and configurations across multiple AWS accounts within an Organization.\n\n## Prerequisites\n\n- **Python 3.8+**\n- **AWS CLI** configured with SSO profiles.\n- **Virtualenv** (highly recommended)\n\n## Setup\n\n1. **Clone the repository:**\n ```bash\n git clone https://github.com/dxw/aws-utils\n cd aws-utils\n ```\n\n2. **Create and activate a virtual environment:**\n ```bash\n python3 -m venv .venv\n source .venv/bin/activate\n ```\n\n3. **Install dependencies:**\n ```bash\n pip install -r requirements.txt\n ```\n\n4. **Configure your environment:**\n Copy the example environment file and fill in your details:\n ```bash\n cp .env.example .env\n ```\n Edit `.env`:\n - `AWS_PARENT_PROFILE`: The SSO profile used to access the Organizations and Pricing APIs (e.g., your master account profile).\n - `OU_IDS`: Comma-separated list of Organizational Unit IDs to scan.\n - `SKIP_ACCOUNTS`: Comma-separated list of Account IDs to exclude from scans.\n - `GOOGLE_CLIENT_SECRET_FILE`: (Optional) Path to your Google API client secret JSON file. Defaults to `client_secret.json`.\n - `GOOGLE_AUTHORIZED_USER_FILE`: (Optional) Path where the Google auth token will be stored. Defaults to `authorized_user.json`.\n\n## Google Sheets Integration\n\nSeveral scripts automatically export their output to Google Sheets in addition to local CSV files.\n\n### Setup\n1. Create a project in the [Google Cloud Console](https://console.cloud.google.com/).\n2. Enable the **Google Sheets API** and **Google Drive API**.\n3. Create **OAuth 2.0 Client ID** credentials (Desktop app).\n4. Download the JSON file and save it as `client_secret.json` in the project root (or set `GOOGLE_CLIENT_SECRET_FILE`).\n5. On the first run, a browser window will open for authentication. The resulting token is saved to `authorized_user.json`.\n\nIf these files are missing, the scripts will skip the Google Sheets export and only produce CSVs.\n\n## Script Overview\n\nThe project uses a shared `aws_utils.py` module to handle SSO login, date ranges, and account iteration.\n\n### Cost & Billing\n- `aws_bills.py`: Comparison of Amortized and Unblended costs over the last 3 months.\n- `aws_cost.py`: Detailed EC2 cost report including compute savings.\n- `bwsuage.py`: Monthly bandwidth usage report with overage alerts (>100GB).\n- `storage-usage.py`: Monthly storage report (S3, EBS, RDS, EFS).\n- `generate-billing-sheets.py`: Generates detailed Google Sheets reports (requires Google API credentials).\n- `summarize-ecsv.py`: Parses exported AWS billing CSV files for local analysis.\n\n### Resource Inventory\n- `aws-vpc.py`: Lists VPCs and CIDR blocks across all accounts/regions.\n- `aws-ips.py`: Lists public IPs, EIPs, and internet-facing Load Balancer DNS names.\n- `list_rds_instances.py`: Lists all RDS instances and clusters.\n- `cloudfront.py`: Lists CloudFront distributions and their status.\n- `aws-asg-lt-ami.py`: Audits Auto Scaling Groups, Launch Templates, and associated AMIs.\n- `aws-ec2-ami.py`: Inventories running EC2 instances and their AMI IDs.\n\n### Pricing\n- `ec2_price.py`: Fetches current on-demand pricing for T3 instance families in London.\n- `rds_price.py`: Fetches current on-demand pricing for RDS MySQL/PostgreSQL in London.\n\n## Usage\n\nMost scripts run autonomously once your `.env` is configured:\n```bash\npython <script_name>.py\n```\nIf your AWS SSO session has expired, the scripts will automatically attempt to trigger `aws sso login` using your defined parent profile.\n\n## Contributing\n\nWhen adding new scripts, leverage `aws_utils.py` for:\n- `setup_org_accounts_session()`: Iterates through accounts in your OUs.\n- `ensure_sso_login()`: Handles session validation.\n- `get_previous_month_range()`: Standardizes billing periods.\n",
|
||||
"diffStat": {
|
||||
"model_added_lines": 2,
|
||||
"model_removed_lines": 2,
|
||||
"model_added_chars": 60,
|
||||
"model_removed_chars": 44,
|
||||
"user_added_lines": 1,
|
||||
"user_removed_lines": 84,
|
||||
"user_added_chars": 49,
|
||||
"user_removed_chars": 3626
|
||||
},
|
||||
"isNewFile": false
|
||||
},
|
||||
"displayName": "Edit",
|
||||
"description": "Replaces text within a file. By default, replaces a single occurrence, but can replace multiple occurrences when `expected_replacements` is specified. This tool requires providing significant context around the change to ensure precise targeting. Always use the read_file tool to examine the file's current content before attempting a text replacement.\n \n The user has the ability to modify the `new_string` content. If modified, this will be stated in the response.\n \n Expectation for required parameters:\n 1. `old_string` MUST be the exact literal text to replace (including all whitespace, indentation, newlines, and surrounding code etc.).\n 2. `new_string` MUST be the exact literal text to replace `old_string` with (also including all whitespace, indentation, newlines, and surrounding code etc.). Ensure the resulting code is correct and idiomatic and that `old_string` and `new_string` are different.\n 3. `instruction` is the detailed instruction of what needs to be changed. It is important to Make it specific and detailed so developers or large language models can understand what needs to be changed and perform the changes on their own if necessary. \n 4. NEVER escape `old_string` or `new_string`, that would break the exact literal text requirement.\n **Important:** If ANY of the above are not satisfied, the tool will fail. CRITICAL for `old_string`: Must uniquely identify the single instance to change. Include at least 3 lines of context BEFORE and AFTER the target text, matching whitespace and indentation precisely. If this string matches multiple locations, or does not match exactly, the tool will fail.\n 5. Prefer to break down complex and long changes into multiple smaller atomic calls to this tool. Always check the content of the file after changes or not finding a string to match.\n **Multiple replacements:** Set `expected_replacements` to the number of occurrences you want to replace. The tool will replace ALL occurrences that match `old_string` exactly. Ensure the number of replacements matches your expectation.",
|
||||
"renderOutputAsMarkdown": true
|
||||
}
|
||||
],
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Finding Missing Links",
|
||||
"description": "I've checked `GEMINI.md` and am still not seeing the old name or URL I need. My next step is to replace those missing pieces in `README.md`. Hopefully, the correct information is available there.",
|
||||
"timestamp": "2026-02-13T14:33:36.916Z"
|
||||
}
|
||||
],
|
||||
"model": "gemini-3-flash-preview",
|
||||
"tokens": {
|
||||
"input": 16570,
|
||||
"output": 152,
|
||||
"cached": 13471,
|
||||
"thoughts": 33,
|
||||
"tool": 0,
|
||||
"total": 16755
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "8aedf18a-a6fb-4f88-9e76-53e8e4f0e9f0",
|
||||
"timestamp": "2026-02-13T14:33:50.841Z",
|
||||
"type": "gemini",
|
||||
"content": "",
|
||||
"toolCalls": [
|
||||
{
|
||||
"id": "read_file-1770993230824-5fc9a80aae261",
|
||||
"name": "read_file",
|
||||
"args": {
|
||||
"file_path": ".env.example"
|
||||
},
|
||||
"result": [
|
||||
{
|
||||
"functionResponse": {
|
||||
"id": "read_file-1770993230824-5fc9a80aae261",
|
||||
"name": "read_file",
|
||||
"response": {
|
||||
"output": "# Parent AWS profile for Organizations and SSO login\n# AWS_PARENT_PROFILE=my-parent-profile\n\n# AWS Organization Unit IDs to scan (comma-separated)\n# OU_IDS=ou-1234-abcd5678,ou-9012-efgh3456\n\n# AWS Account IDs to skip (comma-separated)\n# SKIP_ACCOUNTS=123456789012,987654321098\n\n# Google Sheets API configuration\n# GOOGLE_CLIENT_SECRET_FILE=client_secret.json\n# GOOGLE_AUTHORIZED_USER_FILE=authorized_user.json\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": "success",
|
||||
"timestamp": "2026-02-13T14:33:50.840Z",
|
||||
"resultDisplay": "",
|
||||
"displayName": "ReadFile",
|
||||
"description": "Reads and returns the content of a specified file. If the file is large, the content will be truncated. The tool's response will clearly indicate if truncation has occurred and will provide details on how to read more of the file using the 'offset' and 'limit' parameters. Handles text, images (PNG, JPG, GIF, WEBP, SVG, BMP), audio files (MP3, WAV, AIFF, AAC, OGG, FLAC), and PDF files. For text files, it can read specific line ranges.",
|
||||
"renderOutputAsMarkdown": true
|
||||
}
|
||||
],
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Considering the Example File",
|
||||
"description": "I'm now shifting my focus to the `.env.example` file. I need to make sure I don't overlook any crucial settings or configurations that might be presented there. My goal is a comprehensive understanding of all relevant parameters.",
|
||||
"timestamp": "2026-02-13T14:33:50.605Z"
|
||||
}
|
||||
],
|
||||
"model": "gemini-3-flash-preview",
|
||||
"tokens": {
|
||||
"input": 16759,
|
||||
"output": 14,
|
||||
"cached": 13449,
|
||||
"thoughts": 14,
|
||||
"tool": 0,
|
||||
"total": 16787
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "fdb714aa-8083-4d42-ad9d-89b0784a5b6d",
|
||||
"timestamp": "2026-02-13T14:33:53.504Z",
|
||||
"type": "gemini",
|
||||
"content": "",
|
||||
"toolCalls": [
|
||||
{
|
||||
"id": "grep_search-1770993233471-194584db0d313",
|
||||
"name": "grep_search",
|
||||
"args": {
|
||||
"pattern": "aws-stuff|github"
|
||||
},
|
||||
"result": [
|
||||
{
|
||||
"functionResponse": {
|
||||
"id": "grep_search-1770993233471-194584db0d313",
|
||||
"name": "grep_search",
|
||||
"response": {
|
||||
"output": "Found 1 match for pattern \"aws-stuff|github\" in path \".\":\n---\nFile: README.md\nL15: git clone https://github.com/dxw/aws-utils\n---"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": "success",
|
||||
"timestamp": "2026-02-13T14:33:53.504Z",
|
||||
"resultDisplay": "Found 1 match",
|
||||
"displayName": "SearchText",
|
||||
"description": "Searches for a regular expression pattern within file contents. Max 100 matches.",
|
||||
"renderOutputAsMarkdown": true
|
||||
}
|
||||
],
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Examining Potential Leaks",
|
||||
"description": "I'm now digging into `aws_utils.py`, meticulously searching for any embedded secrets or hardcoded project identifiers that could be exploited. My focus is on anything related to the project's name or its GitHub repository, to minimize risks associated with these items.",
|
||||
"timestamp": "2026-02-13T14:33:53.245Z"
|
||||
}
|
||||
],
|
||||
"model": "gemini-3-flash-preview",
|
||||
"tokens": {
|
||||
"input": 16923,
|
||||
"output": 13,
|
||||
"cached": 13443,
|
||||
"thoughts": 27,
|
||||
"tool": 0,
|
||||
"total": 16963
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "b16629a0-4f29-4f9a-b767-b43fba26772a",
|
||||
"timestamp": "2026-02-13T14:33:56.557Z",
|
||||
"type": "gemini",
|
||||
"content": "",
|
||||
"toolCalls": [
|
||||
{
|
||||
"id": "grep_search-1770993236533-234497502f2288",
|
||||
"name": "grep_search",
|
||||
"args": {
|
||||
"pattern": "aws-stuff"
|
||||
},
|
||||
"result": [
|
||||
{
|
||||
"functionResponse": {
|
||||
"id": "grep_search-1770993236533-234497502f2288",
|
||||
"name": "grep_search",
|
||||
"response": {
|
||||
"output": "No matches found for pattern \"aws-stuff\" in path \".\"."
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": "success",
|
||||
"timestamp": "2026-02-13T14:33:56.557Z",
|
||||
"resultDisplay": "No matches found",
|
||||
"displayName": "SearchText",
|
||||
"description": "Searches for a regular expression pattern within file contents. Max 100 matches.",
|
||||
"renderOutputAsMarkdown": true
|
||||
}
|
||||
],
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Checking Documentation Updates",
|
||||
"description": "I've finished updating `README.md` and am now conducting a thorough review of all relevant files. My current focus is ensuring consistent terminology, specifically looking for instances of \"dxw\" and \"aws-utils\". I'm also including `test.py` and the `tests/` directory in this final check for completeness.",
|
||||
"timestamp": "2026-02-13T14:33:56.373Z"
|
||||
}
|
||||
],
|
||||
"model": "gemini-3-flash-preview",
|
||||
"tokens": {
|
||||
"input": 16982,
|
||||
"output": 11,
|
||||
"cached": 16769,
|
||||
"thoughts": 66,
|
||||
"tool": 0,
|
||||
"total": 17059
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "2b691478-9767-4e07-ade1-12c1af22d55b",
|
||||
"timestamp": "2026-02-13T14:33:59.317Z",
|
||||
"type": "gemini",
|
||||
"content": "",
|
||||
"toolCalls": [
|
||||
{
|
||||
"id": "read_file-1770993239300-94856bd9b0e6c8",
|
||||
"name": "read_file",
|
||||
"args": {
|
||||
"file_path": "README.md",
|
||||
"limit": 20
|
||||
},
|
||||
"result": [
|
||||
{
|
||||
"functionResponse": {
|
||||
"id": "read_file-1770993239300-94856bd9b0e6c8",
|
||||
"name": "read_file",
|
||||
"response": {
|
||||
"output": "\nIMPORTANT: The file content has been truncated.\nStatus: Showing lines 1-20 of 93 total lines.\nAction: To read more of the file, you can use the 'offset' and 'limit' parameters in a subsequent 'read_file' call. For example, to read the next section of the file, use offset: 20.\n\n--- FILE CONTENT (truncated) ---\n# AWS Organization Audit Scripts\n\nA collection of Python scripts designed to audit and report on resources, costs, and configurations across multiple AWS accounts within an Organization.\n\n## Prerequisites\n\n- **Python 3.8+**\n- **AWS CLI** configured with SSO profiles.\n- **Virtualenv** (highly recommended)\n\n## Setup\n\n1. **Clone the repository:**\n ```bash\n git clone https://github.com/dxw/aws-utils\n cd aws-utils\n ```\n\n2. **Create and activate a virtual environment:**\n ```bash"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": "success",
|
||||
"timestamp": "2026-02-13T14:33:59.316Z",
|
||||
"resultDisplay": "Read lines 1-20 of 93 from README.md",
|
||||
"displayName": "ReadFile",
|
||||
"description": "Reads and returns the content of a specified file. If the file is large, the content will be truncated. The tool's response will clearly indicate if truncation has occurred and will provide details on how to read more of the file using the 'offset' and 'limit' parameters. Handles text, images (PNG, JPG, GIF, WEBP, SVG, BMP), audio files (MP3, WAV, AIFF, AAC, OGG, FLAC), and PDF files. For text files, it can read specific line ranges.",
|
||||
"renderOutputAsMarkdown": true
|
||||
}
|
||||
],
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Revising Project Documentation",
|
||||
"description": "I've just stopped using the term \"aws-stuff.\" Next, I'm going to proofread the URL listed in the `README.md` file again, to ensure its accuracy.",
|
||||
"timestamp": "2026-02-13T14:33:59.137Z"
|
||||
}
|
||||
],
|
||||
"model": "gemini-3-flash-preview",
|
||||
"tokens": {
|
||||
"input": 17007,
|
||||
"output": 15,
|
||||
"cached": 13357,
|
||||
"thoughts": 24,
|
||||
"tool": 0,
|
||||
"total": 17046
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "6947a372-ee53-4dd1-aca9-f6a1e1139a65",
|
||||
"timestamp": "2026-02-13T14:34:07.527Z",
|
||||
"type": "gemini",
|
||||
"content": "",
|
||||
"toolCalls": [
|
||||
{
|
||||
"id": "run_shell_command-1770993242080-9a7824897e065",
|
||||
"name": "run_shell_command",
|
||||
"args": {
|
||||
"command": "git status && git diff README.md",
|
||||
"description": "Check git status and diff for README.md."
|
||||
},
|
||||
"result": [
|
||||
{
|
||||
"functionResponse": {
|
||||
"id": "run_shell_command-1770993242080-9a7824897e065",
|
||||
"name": "run_shell_command",
|
||||
"response": {
|
||||
"output": "Output: On branch main\nYour branch is ahead of 'origin/main' by 1 commit.\n (use \"git push\" to publish your local commits)\n\nChanges not staged for commit:\n (use \"git add <file>...\" to update what will be committed)\n (use \"git restore <file>...\" to discard changes in working directory)\n modified: README.md\n\nno changes added to commit (use \"git add\" and/or \"git commit -a\")\ndiff --git a/README.md b/README.md\nindex 40c30c7..ac7bb4a 100644\n--- a/README.md\n+++ b/README.md\n@@ -12,8 +12,8 @@ A collection of Python scripts designed to audit and report on resources, costs,\n \n 1. **Clone the repository:**\n ```bash\n- git clone <repository-url>\n- cd aws-stuff\n+ git clone https://github.com/dxw/aws-utils\n+ cd aws-utils\n ```\n \n 2. **Create and activate a virtual environment:**\nProcess Group PGID: 26342"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": "success",
|
||||
"timestamp": "2026-02-13T14:34:07.527Z",
|
||||
"resultDisplay": "On branch main\nYour branch is ahead of 'origin/main' by 1 commit.\n (use \"git push\" to publish your local commits)\n\nChanges not staged for commit:\n (use \"git add <file>...\" to update what will be committed)\n (use \"git restore <file>...\" to discard changes in working directory)\n modified: README.md\n\nno changes added to commit (use \"git add\" and/or \"git commit -a\")\ndiff --git a/README.md b/README.md\nindex 40c30c7..ac7bb4a 100644\n--- a/README.md\n+++ b/README.md\n@@ -12,8 +12,8 @@ A collection of Python scripts designed to audit and report on resources, costs,\n \n 1. **Clone the repository:**\n ```bash\n- git clone <repository-url>\n- cd aws-stuff\n+ git clone https://github.com/dxw/aws-utils\n+ cd aws-utils\n ```\n \n 2. **Create and activate a virtual environment:**",
|
||||
"displayName": "Shell",
|
||||
"description": "This tool executes a given shell command as `bash -c <command>`. To run a command in the background, set the `is_background` parameter to true. Do NOT use `&` to background commands. Command is executed as a subprocess that leads its own process group. Command process group can be terminated as `kill -- -PGID` or signaled as `kill -s SIGNAL -- -PGID`.\n\n The following information is returned:\n\n Output: Combined stdout/stderr. Can be `(empty)` or partial on error and for any unwaited background processes.\n Exit Code: Only included if non-zero (command failed).\n Error: Only included if a process-level error occurred (e.g., spawn failure).\n Signal: Only included if process was terminated by a signal.\n Background PIDs: Only included if background processes were started.\n Process Group PGID: Only included if available.",
|
||||
"renderOutputAsMarkdown": false
|
||||
}
|
||||
],
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Reviewing the Commit",
|
||||
"description": "I've just reviewed the changes. All looks good, and I'm ready to commit this update.",
|
||||
"timestamp": "2026-02-13T14:34:01.901Z"
|
||||
}
|
||||
],
|
||||
"model": "gemini-3-flash-preview",
|
||||
"tokens": {
|
||||
"input": 17229,
|
||||
"output": 29,
|
||||
"cached": 16691,
|
||||
"thoughts": 10,
|
||||
"tool": 0,
|
||||
"total": 17268
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "17a19409-7422-4855-ae63-bb0a700a6822",
|
||||
"timestamp": "2026-02-13T14:34:17.348Z",
|
||||
"type": "gemini",
|
||||
"content": "",
|
||||
"toolCalls": [
|
||||
{
|
||||
"id": "run_shell_command-1770993249832-23c2017484231",
|
||||
"name": "run_shell_command",
|
||||
"args": {
|
||||
"command": "git add README.md && git commit -m \"docs: update repository URL and name to dxw/aws-utils\" && git status",
|
||||
"description": "Stage and commit the changes to README.md."
|
||||
},
|
||||
"result": [
|
||||
{
|
||||
"functionResponse": {
|
||||
"id": "run_shell_command-1770993249832-23c2017484231",
|
||||
"name": "run_shell_command",
|
||||
"response": {
|
||||
"output": "Output: [main e72c9d6] docs: update repository URL and name to dxw/aws-utils\n 1 file changed, 2 insertions(+), 2 deletions(-)\nOn branch main\nYour branch is ahead of 'origin/main' by 2 commits.\n (use \"git push\" to publish your local commits)\n\nnothing to commit, working tree clean\nProcess Group PGID: 26372"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"status": "success",
|
||||
"timestamp": "2026-02-13T14:34:17.348Z",
|
||||
"resultDisplay": "[main e72c9d6] docs: update repository URL and name to dxw/aws-utils\n 1 file changed, 2 insertions(+), 2 deletions(-)\nOn branch main\nYour branch is ahead of 'origin/main' by 2 commits.\n (use \"git push\" to publish your local commits)\n\nnothing to commit, working tree clean",
|
||||
"displayName": "Shell",
|
||||
"description": "This tool executes a given shell command as `bash -c <command>`. To run a command in the background, set the `is_background` parameter to true. Do NOT use `&` to background commands. Command is executed as a subprocess that leads its own process group. Command process group can be terminated as `kill -- -PGID` or signaled as `kill -s SIGNAL -- -PGID`.\n\n The following information is returned:\n\n Output: Combined stdout/stderr. Can be `(empty)` or partial on error and for any unwaited background processes.\n Exit Code: Only included if non-zero (command failed).\n Error: Only included if a process-level error occurred (e.g., spawn failure).\n Signal: Only included if process was terminated by a signal.\n Background PIDs: Only included if background processes were started.\n Process Group PGID: Only included if available.",
|
||||
"renderOutputAsMarkdown": false
|
||||
}
|
||||
],
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Committing the Change",
|
||||
"description": "I'm ready to stage and commit the changes now. It's a simple step, but essential to the process. With this done, I can proceed further.",
|
||||
"timestamp": "2026-02-13T14:34:09.637Z"
|
||||
}
|
||||
],
|
||||
"model": "gemini-3-flash-preview",
|
||||
"tokens": {
|
||||
"input": 17531,
|
||||
"output": 50,
|
||||
"cached": 16710,
|
||||
"thoughts": 9,
|
||||
"tool": 0,
|
||||
"total": 17590
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "aa031f8b-39cf-4426-bf7c-b837a4d6b359",
|
||||
"timestamp": "2026-02-13T14:34:18.636Z",
|
||||
"type": "gemini",
|
||||
"content": "The documentation has been updated to reflect the new repository name `aws-utils` and its location in the `dxw` organization.\n\n```bash\ndocs: update repository URL and name to dxw/aws-utils\n```",
|
||||
"thoughts": [],
|
||||
"tokens": {
|
||||
"input": 17678,
|
||||
"output": 47,
|
||||
"cached": 16702,
|
||||
"thoughts": 0,
|
||||
"tool": 0,
|
||||
"total": 17725
|
||||
},
|
||||
"model": "gemini-3-flash-preview"
|
||||
},
|
||||
{
|
||||
"id": "76b88760-09f4-478d-b226-1cacaac7aacf",
|
||||
"timestamp": "2026-02-13T14:44:09.252Z",
|
||||
"type": "error",
|
||||
"content": "Unknown command: /save"
|
||||
},
|
||||
{
|
||||
"id": "0ba303de-7c14-442f-8cc6-e4f9a1aafa07",
|
||||
"timestamp": "2026-02-13T14:44:37.626Z",
|
||||
"type": "info",
|
||||
"content": "Conversation shared to /tmp/today.md"
|
||||
}
|
||||
],
|
||||
"summary": "Update repo name and docs to dxw/aws-utils"
|
||||
}
|
||||
46
tmp/aws-stuff/chats/session-2026-02-16T12-12-f16c4556.json
Normal file
46
tmp/aws-stuff/chats/session-2026-02-16T12-12-f16c4556.json
Normal file
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"sessionId": "f16c4556-b003-4aa4-b7ea-d521966b2ce8",
|
||||
"projectHash": "c4ece9c032ac20d038bbd73e9aa5f86cb3fd24c826b8e99b6edcd77db288fcb1",
|
||||
"startTime": "2026-02-16T12:12:16.597Z",
|
||||
"lastUpdated": "2026-02-16T12:12:47.191Z",
|
||||
"messages": [
|
||||
{
|
||||
"id": "dd5dfbfc-f6b2-4d98-a4b4-c1004325f2f0",
|
||||
"timestamp": "2026-02-16T12:12:16.597Z",
|
||||
"type": "error",
|
||||
"content": "Error during discovery for MCP server 'terraform': MCP error -32000: Connection closed"
|
||||
},
|
||||
{
|
||||
"id": "20e9952e-288e-4f93-b732-ec27f6eef0a2",
|
||||
"timestamp": "2026-02-16T12:12:45.315Z",
|
||||
"type": "user",
|
||||
"content": [
|
||||
{
|
||||
"text": ":wq"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "ddfbcf14-baac-4123-9a7a-98a7d666f5f3",
|
||||
"timestamp": "2026-02-16T12:12:47.191Z",
|
||||
"type": "gemini",
|
||||
"content": "I'm ready. What's our first task?",
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Understanding the Project Brief",
|
||||
"description": "I've got the project structure, core guidelines, and security principles all mapped out. Now, I'm just waiting on the first command. Seems like a simple start, ready to get this underway.",
|
||||
"timestamp": "2026-02-16T12:12:47.138Z"
|
||||
}
|
||||
],
|
||||
"tokens": {
|
||||
"input": 12944,
|
||||
"output": 12,
|
||||
"cached": 3302,
|
||||
"thoughts": 43,
|
||||
"tool": 0,
|
||||
"total": 12999
|
||||
},
|
||||
"model": "gemini-3-flash-preview"
|
||||
}
|
||||
]
|
||||
}
|
||||
1361
tmp/aws-stuff/chats/session-2026-02-17T11-52-29e666b2.json
Normal file
1361
tmp/aws-stuff/chats/session-2026-02-17T11-52-29e666b2.json
Normal file
File diff suppressed because one or more lines are too long
3622
tmp/aws-stuff/chats/session-2026-02-17T17-32-ee47b188.json
Normal file
3622
tmp/aws-stuff/chats/session-2026-02-17T17-32-ee47b188.json
Normal file
File diff suppressed because one or more lines are too long
1370
tmp/aws-stuff/chats/session-2026-02-25T11-14-497df65e.json
Normal file
1370
tmp/aws-stuff/chats/session-2026-02-25T11-14-497df65e.json
Normal file
File diff suppressed because one or more lines are too long
1671
tmp/aws-stuff/chats/session-2026-02-25T17-32-1cbd680b.json
Normal file
1671
tmp/aws-stuff/chats/session-2026-02-25T17-32-1cbd680b.json
Normal file
File diff suppressed because one or more lines are too long
200
tmp/aws-stuff/chats/session-2026-03-03T11-38-e8dc2ec8.json
Normal file
200
tmp/aws-stuff/chats/session-2026-03-03T11-38-e8dc2ec8.json
Normal file
File diff suppressed because one or more lines are too long
303
tmp/aws-stuff/chats/session-2026-03-03T11-40-60b239de.json
Normal file
303
tmp/aws-stuff/chats/session-2026-03-03T11-40-60b239de.json
Normal file
File diff suppressed because one or more lines are too long
190
tmp/aws-stuff/chats/session-2026-03-03T11-45-4c0f4b2a.json
Normal file
190
tmp/aws-stuff/chats/session-2026-03-03T11-45-4c0f4b2a.json
Normal file
File diff suppressed because one or more lines are too long
1025
tmp/aws-stuff/chats/session-2026-03-03T11-48-609b7b2c.json
Normal file
1025
tmp/aws-stuff/chats/session-2026-03-03T11-48-609b7b2c.json
Normal file
File diff suppressed because one or more lines are too long
46
tmp/aws-stuff/chats/session-2026-03-03T15-17-b4d0330e.json
Normal file
46
tmp/aws-stuff/chats/session-2026-03-03T15-17-b4d0330e.json
Normal file
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"sessionId": "b4d0330e-9f58-4a70-b3d6-560b1bb3162d",
|
||||
"projectHash": "c4ece9c032ac20d038bbd73e9aa5f86cb3fd24c826b8e99b6edcd77db288fcb1",
|
||||
"startTime": "2026-03-03T15:17:46.816Z",
|
||||
"lastUpdated": "2026-03-03T15:17:51.297Z",
|
||||
"messages": [
|
||||
{
|
||||
"id": "b95dc682-6b2c-4495-96de-5470e86f9732",
|
||||
"timestamp": "2026-03-03T15:17:46.816Z",
|
||||
"type": "user",
|
||||
"content": [
|
||||
{
|
||||
"text": "deactivate a venv"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "034cebe6-a5aa-47ab-945b-c3e35f1104d6",
|
||||
"timestamp": "2026-03-03T15:17:51.297Z",
|
||||
"type": "gemini",
|
||||
"content": "To deactivate a virtual environment in your current shell, simply run:\n\n```bash\ndeactivate\n```",
|
||||
"thoughts": [
|
||||
{
|
||||
"subject": "Analyzing Deactivation Strategy",
|
||||
"description": "I'm currently considering the user's implicit context; they're probably inside an active virtual environment. The standard approach, \"deactivate,\" seems the logical first step, assuming a typical shell session. My internal processes are formulating a response tailored for this scenario, avoiding unnecessary complications.",
|
||||
"timestamp": "2026-03-03T15:17:49.735Z"
|
||||
},
|
||||
{
|
||||
"subject": "Determining Optimal Response",
|
||||
"description": "The context is now clear: the user requires the `deactivate` command. My previous analysis of their prompt pointed towards either instruction or inquiry. Considering my role, a concise and direct answer, providing the command, seems best. I'm finalizing the response now, aiming for clarity and brevity in execution.",
|
||||
"timestamp": "2026-03-03T15:17:51.202Z"
|
||||
}
|
||||
],
|
||||
"tokens": {
|
||||
"input": 15532,
|
||||
"output": 21,
|
||||
"cached": 3218,
|
||||
"thoughts": 254,
|
||||
"tool": 0,
|
||||
"total": 15807
|
||||
},
|
||||
"model": "gemini-3-flash-preview"
|
||||
}
|
||||
],
|
||||
"kind": "main"
|
||||
}
|
||||
488
tmp/aws-stuff/chats/session-2026-03-10T16-48-2ec84e89.json
Normal file
488
tmp/aws-stuff/chats/session-2026-03-10T16-48-2ec84e89.json
Normal file
File diff suppressed because one or more lines are too long
7917
tmp/aws-stuff/chats/session-2026-03-10T17-42-ebaf7b6b.json
Normal file
7917
tmp/aws-stuff/chats/session-2026-03-10T17-42-ebaf7b6b.json
Normal file
File diff suppressed because one or more lines are too long
737
tmp/aws-stuff/logs.json
Normal file
737
tmp/aws-stuff/logs.json
Normal file
File diff suppressed because one or more lines are too long
5
tmp/aws-stuff/shell_history
Normal file
5
tmp/aws-stuff/shell_history
Normal file
@@ -0,0 +1,5 @@
|
||||
ython3 aws-carbon.py --year 2024 --sheets
|
||||
python3 aws-carbon.py --year 2024 --sheets
|
||||
python3 aws-carbon.py --year 2025 --sheets
|
||||
scripts/audit
|
||||
scripts/audit vpc
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"error": "MCP tool 'get_vulnerability_details' must be requested with its server prefix (e.g., 'osvScanner__get_vulnerability_details') in agent 'generalist'."
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Directory listing for /Users/bob/git/dxw/aws-stuff:\n[DIR] .ruff_cache\n[DIR] tests\n.env.example (451 bytes)\n.gitignore (76 bytes)\navg_bandwidth_12months.py (4145 bytes)\naws_bills_breakdown.py (3184 bytes)\naws_bills_refined.py (2450 bytes)\naws_bills.py (2964 bytes)\naws_cost.py (2649 bytes)\naws_utils.py (10760 bytes)\naws-asg-lt-ami.py (6715 bytes)\naws-carbon.py (6537 bytes)\naws-ec2-ami.py (4290 bytes)\naws-ips.py (5612 bytes)\naws-metrics.py (5042 bytes)\naws-vpc.py (3098 bytes)\nbwsuage.py (3116 bytes)\ncloudfront.py (3073 bytes)\ncloudtrail-audit.py (2940 bytes)\ndownload_invoice.py (3168 bytes)\nec2_price.py (1491 bytes)\nextract_billing_api.py (3574 bytes)\nextract_invoice_charges.py (5401 bytes)\nGEMINI.md (2922 bytes)\ngenerate-billing-sheets.py (6047 bytes)\niam-audit.py (4855 bytes)\ninspect_billing.py (1398 bytes)\ninspect_mtvh.py (1981 bytes)\nlast-2-months-billing.py (2367 bytes)\nlist_rds_instances.py (1490 bytes)\nlist_services.py (671 bytes)\nnot_running_latest.py (1761 bytes)\nrds_price.py (1396 bytes)\nREADME.md (3830 bytes)\nrequirements.txt (116 bytes)\ns3-security-audit.py (5162 bytes)\nsecurity-group-audit.py (3866 bytes)\nservice-spend-by-account.py (2449 bytes)\nstorage-usage.py (3796 bytes)\nsummarize-ecsv.py (3834 bytes)\ntest_invoice_api.py (2954 bytes)\ntest.py (1985 bytes)\n\n(31 ignored)"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Directory listing for /Users/bob/git/dxw/aws-stuff/tests:\n__init__.py (0 bytes)\ntest_aws_utils.py (7304 bytes)\ntest_scripts.py (2279 bytes)"
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "import boto3\nfrom aws_utils import get_account_names, get_last_n_months_ranges, get_boto_session\n\n\ndef get_cost_for_range(ce_client, start_date, end_date, account_costs):\n \"\"\"Fetches costs for a date range and updates account_costs dictionary.\"\"\"\n try:\n response = ce_client.get_cost_and_usage(\n TimePeriod={\"Start\": start_date, \"End\": end_date},\n Granularity=\"MONTHLY\",\n Metrics=[\"UnblendedCost\", \"AmortizedCost\"],\n GroupBy=[{\"Type\": \"DIMENSION\", \"Key\": \"LINKED_ACCOUNT\"}],\n )\n\n for result in response[\"ResultsByTime\"]:\n for group in result[\"Groups\"]:\n account_id = group[\"Keys\"][0]\n unblended = float(group[\"Metrics\"][\"UnblendedCost\"][\"Amount\"])\n amortized = float(group[\"Metrics\"][\"AmortizedCost\"][\"Amount\"])\n\n if account_id not in account_costs:\n account_costs[account_id] = {\"unblended\": [], \"amortized\": []}\n\n account_costs[account_id][\"unblended\"].append(unblended)\n account_costs[account_id][\"amortized\"].append(amortized)\n except Exception as e:\n print(f\"Error fetching cost for range {start_date} to {end_date}: {e}\")\n\n\ndef main():\n session = get_boto_session()\n ce_client = session.client(\"ce\")\n account_names = get_account_names()\n account_costs = {}\n\n ranges = get_last_n_months_ranges(3)\n months_labels = [r[2] for r in ranges]\n\n for start_date, end_date, _ in ranges:\n get_cost_for_range(ce_client, start_date, end_date, account_costs)\n\n # Sort accounts by the most recent month's amortized cost\n sorted_accounts = sorted(\n account_costs.items(),\n key=lambda item: item[1][\"amortized\"][0] if item[1][\"amortized\"] else 0,\n reverse=True,\n )\n\n print(\n f\"\\nAWS Costs for the last 3 months (Amortized and Unblended, sorted by highest Amortized Cost in {months_labels[0]}):\"\n )\n header = f\"{'Account Name':<30} {' ' + months_labels[0] + ' (Amort)':<15} {' ' + months_labels[1] + ' (Amort)':<15} {' ' + months_labels[2] + ' (Amort)':<15} {' ' + months_labels[0] + ' (Unbl)':<15} {' ' + months_labels[1] + ' (Unbl)':<15} {' ' + months_labels[2] + ' (Unbl)':<15}\"\n print(header)\n print(\"-\" * 125)\n\n for account_id, costs in sorted_accounts:\n name = account_names.get(account_id, f\"Unknown ({account_id})\")\n\n # Ensure we have 3 months of data\n amortized = costs[\"amortized\"] + [0.0] * (3 - len(costs[\"amortized\"]))\n unblended = costs[\"unblended\"] + [0.0] * (3 - len(costs[\"unblended\"]))\n\n amortized_fmt = [f\"${c:,.2f}\" for c in amortized[:3]]\n unblended_fmt = [f\"${c:,.2f}\" for c in unblended[:3]]\n\n print(\n f\"{name[:30]:<30} {amortized_fmt[0]:>15} {amortized_fmt[1]:>15} {amortized_fmt[2]:>15} {unblended_fmt[0]:>15} {unblended_fmt[1]:>15} {unblended_fmt[2]:>15}\"\n )\n\n\nif __name__ == \"__main__\":\n main()\n"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "import unittest\nfrom unittest.mock import patch, MagicMock\nimport os\nimport sys\nimport importlib.util\n\n# Add project root to path\nPROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), \"..\"))\nsys.path.append(PROJECT_ROOT)\n\n\nclass TestScripts(unittest.TestCase):\n def setUp(self):\n # Patch get_boto_session for all tests to avoid real AWS calls\n self.patcher = patch(\"aws_utils.get_boto_session\")\n self.mock_session = self.patcher.start()\n self.mock_client = MagicMock()\n self.mock_session.return_value.client.return_value = self.mock_client\n\n def tearDown(self):\n self.patcher.stop()\n\n def test_import_bwsuage(self):\n \"\"\"Smoke test to ensure bwsuage.py can be imported.\"\"\"\n spec = importlib.util.spec_from_file_location(\n \"bwsuage\", os.path.join(PROJECT_ROOT, \"bwsuage.py\")\n )\n bwsuage = importlib.util.module_from_spec(spec)\n spec.loader.exec_module(bwsuage)\n self.assertTrue(hasattr(bwsuage, \"get_total_bandwidth_report\"))\n\n def test_import_aws_bills(self):\n \"\"\"Smoke test to ensure aws_bills.py can be imported.\"\"\"\n spec = importlib.util.spec_from_file_location(\n \"aws_bills\", os.path.join(PROJECT_ROOT, \"aws_bills.py\")\n )\n aws_bills = importlib.util.module_from_spec(spec)\n spec.loader.exec_module(aws_bills)\n self.assertTrue(hasattr(aws_bills, \"get_cost_for_range\"))\n\n def test_import_aws_cost(self):\n \"\"\"Smoke test to ensure aws_cost.py can be imported.\"\"\"\n spec = importlib.util.spec_from_file_location(\n \"aws_cost\", os.path.join(PROJECT_ROOT, \"aws_cost.py\")\n )\n aws_cost = importlib.util.module_from_spec(spec)\n spec.loader.exec_module(aws_cost)\n self.assertTrue(hasattr(aws_cost, \"fetch_costs_with_savings\"))\n\n def test_import_aws_vpc(self):\n \"\"\"Smoke test to ensure aws-vpc.py can be imported.\"\"\"\n spec = importlib.util.spec_from_file_location(\n \"aws_vpc\", os.path.join(PROJECT_ROOT, \"aws-vpc.py\")\n )\n aws_vpc = importlib.util.module_from_spec(spec)\n spec.loader.exec_module(aws_vpc)\n self.assertTrue(hasattr(aws_vpc, \"list_vpcs\"))\n\n\nif __name__ == \"__main__\":\n unittest.main()\n"
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "import boto3\nimport csv\nfrom botocore.exceptions import ClientError, ProfileNotFound\nfrom aws_utils import setup_org_accounts_session, get_boto_session, export_to_sheets\n\n\ndef get_vpc_name(tags):\n if tags:\n for tag in tags:\n if tag[\"Key\"] == \"Name\":\n return tag[\"Value\"]\n return \"Unnamed VPC\"\n\n\ndef list_vpcs(ec2_client):\n vpcs_info = []\n paginator = ec2_client.get_paginator(\"describe_vpcs\")\n for page in paginator.paginate():\n for vpc in page[\"Vpcs\"]:\n vpcs_info.append(\n {\n \"VPCName\": get_vpc_name(vpc.get(\"Tags\")),\n \"VPCID\": vpc[\"VpcId\"],\n \"CIDRBlock\": vpc.get(\"CidrBlock\", \"N/A\"),\n }\n )\n return vpcs_info\n\n\ndef main():\n get_boto_session()\n regions_to_check = [\"eu-west-1\", \"eu-west-2\"]\n total_vpcs_all_accounts = 0\n rows_for_sheets = []\n\n with open(\"aws_vpcs_by_region.csv\", mode=\"w\", newline=\"\") as csvfile:\n fieldnames = [\n \"AccountName\",\n \"AccountID\",\n \"Region\",\n \"VPCName\",\n \"VPCID\",\n \"CIDRBlock\",\n ]\n writer = csv.DictWriter(csvfile, fieldnames=fieldnames)\n writer.writeheader()\n\n for account, profile_name in setup_org_accounts_session():\n account_id = account[\"Id\"]\n account_name = account[\"Name\"]\n try:\n boto3.setup_default_session(profile_name=profile_name)\n for region in regions_to_check:\n try:\n ec2_client = boto3.client(\"ec2\", region_name=region)\n vpcs_info = list_vpcs(ec2_client)\n total_vpcs_all_accounts += len(vpcs_info)\n\n for vpc in vpcs_info:\n row = {\n \"AccountName\": account_name,\n \"AccountID\": account_id,\n \"Region\": region,\n \"VPCName\": vpc[\"VPCName\"],\n \"VPCID\": vpc[\"VPCID\"],\n \"CIDRBlock\": vpc[\"CIDRBlock\"],\n }\n writer.writerow(row)\n rows_for_sheets.append(list(row.values()))\n\n if vpcs_info:\n print(\n f'\"{account_name}\" (ID: {account_id}, Region: {region}) VPCs found: {len(vpcs_info)}'\n )\n except ClientError as e:\n print(f\"Error in {region} for {account_name}: {e}\")\n except (ClientError, ProfileNotFound) as e:\n print(f\"Error accessing account {account_name}: {e}\")\n\n print(f\"\\nTotal number of VPCs found: {total_vpcs_all_accounts}\")\n print(\"CSV file 'aws_vpcs_by_region.csv' generated successfully.\")\n\n # Export to Google Sheets\n export_to_sheets(\"aws-vpc\", fieldnames, rows_for_sheets)\n\n\nif __name__ == \"__main__\":\n main()\n"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "boto3\npandas\npyarrow\npython-dotenv\npython-dateutil\ngspread\ngoogle-auth-oauthlib\ngoogle-auth-httplib2\npypdf\nrequests\n"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "import boto3\nfrom aws_utils import get_account_names, get_previous_month_range, get_boto_session\n\n\ndef fetch_costs_with_savings(ce_client, org_client, start_date, end_date):\n \"\"\"Fetches costs for EC2 grouped by account and service.\"\"\"\n account_map = get_account_names()\n\n try:\n response = ce_client.get_cost_and_usage(\n TimePeriod={\"Start\": start_date, \"End\": end_date},\n Granularity=\"MONTHLY\",\n Metrics=[\n \"UnblendedCost\",\n \"AmortizedCost\",\n \"NetAmortizedCost\",\n \"NetUnblendedCost\",\n ],\n GroupBy=[\n {\"Type\": \"DIMENSION\", \"Key\": \"LINKED_ACCOUNT\"},\n {\"Type\": \"DIMENSION\", \"Key\": \"SERVICE\"},\n ],\n )\n\n if not response[\"ResultsByTime\"]:\n print(\"No cost data available for the specified period.\")\n return\n\n for result in response[\"ResultsByTime\"]:\n period_start = result[\"TimePeriod\"][\"Start\"]\n print(f\"Billing Period: {period_start}\")\n\n for group in result[\"Groups\"]:\n account_id = group[\"Keys\"][0]\n service = group[\"Keys\"][1]\n\n if \"Amazon Elastic Compute Cloud\" in service:\n metrics = group[\"Metrics\"]\n unblended = metrics[\"UnblendedCost\"][\"Amount\"]\n amortized = metrics[\"AmortizedCost\"][\"Amount\"]\n net_amortized = metrics[\"NetAmortizedCost\"][\"Amount\"]\n net_unblended = metrics[\"NetUnblendedCost\"][\"Amount\"]\n unit = metrics[\"UnblendedCost\"][\"Unit\"]\n\n account_name = account_map.get(account_id, account_id)\n\n print(f\"Account: {account_name} | Service: {service}\")\n print(f\" - Total Cost (Unblended): {unblended} {unit}\")\n print(f\" - Net Cost (Amortized): {net_amortized} {unit}\")\n print(f\" - Net Cost (Unblended): {net_unblended} {unit}\")\n print(f\" - Final Cost (Amortized): {amortized} {unit}\")\n\n except Exception as e:\n print(f\"Error fetching costs: {e}\")\n\n\ndef main():\n session = get_boto_session()\n ce_client = session.client(\"ce\", region_name=\"us-east-1\")\n org_client = session.client(\"organizations\", region_name=\"us-east-1\")\n\n start_date, end_date = get_previous_month_range()\n\n print(\n f\"Fetching AWS EC2 costs with compute savings from {start_date} to {end_date}...\"\n )\n fetch_costs_with_savings(ce_client, org_client, start_date, end_date)\n\n\nif __name__ == \"__main__\":\n main()\n"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "import boto3\nfrom aws_utils import get_account_names, get_last_n_months_ranges, get_boto_session\n\n\ndef get_cost_for_range(ce_client, start_date, end_date, account_costs):\n \"\"\"Fetches costs for a date range and updates account_costs dictionary.\"\"\"\n try:\n response = ce_client.get_cost_and_usage(\n TimePeriod={\"Start\": start_date, \"End\": end_date},\n Granularity=\"MONTHLY\",\n Metrics=[\"UnblendedCost\", \"AmortizedCost\"],\n GroupBy=[{\"Type\": \"DIMENSION\", \"Key\": \"LINKED_ACCOUNT\"}],\n )\n\n for result in response[\"ResultsByTime\"]:\n for group in result[\"Groups\"]:\n account_id = group[\"Keys\"][0]\n unblended = float(group[\"Metrics\"][\"UnblendedCost\"][\"Amount\"])\n amortized = float(group[\"Metrics\"][\"AmortizedCost\"][\"Amount\"])\n\n if account_id not in account_costs:\n account_costs[account_id] = {\"unblended\": [], \"amortized\": []}\n\n account_costs[account_id][\"unblended\"].append(unblended)\n account_costs[account_id][\"amortized\"].append(amortized)\n except Exception as e:\n print(f\"Error fetching cost for range {start_date} to {end_date}: {e}\")\n\n\ndef main():\n session = get_boto_session()\n ce_client = session.client(\"ce\")\n account_names = get_account_names()\n account_costs = {}\n\n ranges = get_last_n_months_ranges(3)\n months_labels = [r[2] for r in ranges]\n\n for start_date, end_date, _ in ranges:\n get_cost_for_range(ce_client, start_date, end_date, account_costs)\n\n # Sort accounts by the most recent month's amortized cost\n sorted_accounts = sorted(\n account_costs.items(),\n key=lambda item: item[1][\"amortized\"][0] if item[1][\"amortized\"] else 0,\n reverse=True,\n )\n\n print(\n f\"\\nAWS Costs for the last 3 months (Amortized and Unblended, sorted by highest Amortized Cost in {months_labels[0]}):\"\n )\n header = f\"{'Account Name':<30} {' ' + months_labels[0] + ' (Amort)':<15} {' ' + months_labels[1] + ' (Amort)':<15} {' ' + months_labels[2] + ' (Amort)':<15} {' ' + months_labels[0] + ' (Unbl)':<15} {' ' + months_labels[1] + ' (Unbl)':<15} {' ' + months_labels[2] + ' (Unbl)':<15}\"\n print(header)\n print(\"-\" * 125)\n\n for account_id, costs in sorted_accounts:\n name = account_names.get(account_id, f\"Unknown ({account_id})\")\n\n # Ensure we have 3 months of data\n amortized = costs[\"amortized\"] + [0.0] * (3 - len(costs[\"amortized\"]))\n unblended = costs[\"unblended\"] + [0.0] * (3 - len(costs[\"unblended\"]))\n\n amortized_fmt = [f\"${c:,.2f}\" for c in amortized[:3]]\n unblended_fmt = [f\"${c:,.2f}\" for c in unblended[:3]]\n\n print(\n f\"{name[:30]:<30} {amortized_fmt[0]:>15} {amortized_fmt[1]:>15} {amortized_fmt[2]:>15} {unblended_fmt[0]:>15} {unblended_fmt[1]:>15} {unblended_fmt[2]:>15}\"\n )\n\n\nif __name__ == \"__main__\":\n main()\n"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "import boto3\nfrom aws_utils import (\n get_account_names,\n get_previous_month_range,\n get_boto_session,\n export_to_sheets,\n)\n\n\ndef get_total_bandwidth_report(threshold_gb=100.0):\n session = get_boto_session()\n ce_client = session.client(\"ce\")\n all_accounts = get_account_names()\n if not all_accounts:\n return\n\n start_date, end_date = get_previous_month_range()\n account_totals = {acc_id: 0.0 for acc_id in all_accounts.keys()}\n next_token = None\n\n try:\n while True:\n params = {\n \"TimePeriod\": {\"Start\": start_date, \"End\": end_date},\n \"Granularity\": \"MONTHLY\",\n \"Metrics\": [\"UsageQuantity\"],\n \"GroupBy\": [\n {\"Type\": \"DIMENSION\", \"Key\": \"LINKED_ACCOUNT\"},\n {\"Type\": \"DIMENSION\", \"Key\": \"USAGE_TYPE\"},\n ],\n }\n if next_token:\n params[\"NextPageToken\"] = next_token\n\n response = ce_client.get_cost_and_usage(**params)\n\n for result in response[\"ResultsByTime\"]:\n for group in result[\"Groups\"]:\n acc_id = group[\"Keys\"][0]\n usage_type = group[\"Keys\"][1]\n usage_amount = float(group[\"Metrics\"][\"UsageQuantity\"][\"Amount\"])\n unit = group[\"Metrics\"][\"UsageQuantity\"][\"Unit\"]\n\n if \"DataTransfer\" in usage_type:\n if unit == \"Bytes\":\n usage_amount /= 1024**3\n elif unit in [\"MB\", \"Megabytes\"]:\n usage_amount /= 1024\n\n if acc_id in account_totals:\n account_totals[acc_id] += usage_amount\n else:\n account_totals[acc_id] = usage_amount\n\n next_token = response.get(\"NextPageToken\")\n if not next_token:\n break\n\n print(f\"\\n--- Full Bandwidth Report ({start_date} to {end_date}) ---\")\n print(f\"{'Account Name':<25} | {'Total GB':<12} | {'Overage (>100GB)'}\")\n print(\"-\" * 75)\n\n sorted_accounts = sorted(\n account_totals.items(),\n key=lambda x: (x[1], all_accounts.get(x[0], x[0])),\n reverse=True,\n )\n\n headers = [\"Account Name\", \"Account ID\", \"Total GB\", \"Overage (>100GB)\"]\n rows = []\n\n for acc_id, total_usage in sorted_accounts:\n acc_name = all_accounts.get(acc_id, f\"Deleted/Unknown ({acc_id})\")\n overage = max(0, total_usage - threshold_gb)\n status_icon = \"⚠️\" if overage > 0 else \"✅\"\n print(\n f\"{acc_name[:25]:<25} | {total_usage:>10.2f} GB | {overage:>8.2f} GB {status_icon}\"\n )\n\n rows.append([acc_name, acc_id, round(total_usage, 2), round(overage, 2)])\n\n # Export to Google Sheets\n export_to_sheets(\"AWS_Bandwidth_Usage\", headers, rows)\n\n except Exception as e:\n print(f\"Error: {e}\")\n\n\nif __name__ == \"__main__\":\n get_total_bandwidth_report(100.0)\n"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "import boto3\nimport calendar\nfrom datetime import datetime, timedelta\nfrom aws_utils import (\n get_account_names,\n get_previous_month_range,\n get_boto_session,\n export_to_sheets,\n)\n\n\ndef get_storage_report(threshold_gb=100.0):\n session = get_boto_session()\n ce_client = session.client(\"ce\")\n all_accounts = get_account_names()\n start_date, end_date = get_previous_month_range()\n\n # Calculate hours in the previous month for Byte-Hour conversion\n dt_end = datetime.strptime(end_date, \"%Y-%m-%d\")\n last_day_prev = dt_end - timedelta(days=1)\n _, num_days = calendar.monthrange(last_day_prev.year, last_day_prev.month)\n hours_in_month = num_days * 24\n\n account_storage_totals = {acc_id: 0.0 for acc_id in all_accounts.keys()}\n next_token = None\n\n try:\n while True:\n params = {\n \"TimePeriod\": {\"Start\": start_date, \"End\": end_date},\n \"Granularity\": \"MONTHLY\",\n \"Metrics\": [\"UsageQuantity\"],\n \"GroupBy\": [\n {\"Type\": \"DIMENSION\", \"Key\": \"LINKED_ACCOUNT\"},\n {\"Type\": \"DIMENSION\", \"Key\": \"USAGE_TYPE\"},\n ],\n \"Filter\": {\n \"Dimensions\": {\n \"Key\": \"USAGE_TYPE_GROUP\",\n \"Values\": [\n \"S3: Storage - Standard\",\n \"S3: Storage - Infinite Archive\",\n \"EC2: EBS - Optimized Storage\",\n \"RDS: Storage\",\n \"EFS: Storage - Standard\",\n \"EFS: Storage - IA\",\n \"EFS: Storage - Archive\",\n ],\n }\n },\n }\n if next_token:\n params[\"NextPageToken\"] = next_token\n\n response = ce_client.get_cost_and_usage(**params)\n\n for result in response[\"ResultsByTime\"]:\n for group in result[\"Groups\"]:\n acc_id = group[\"Keys\"][0]\n usage_amount = float(group[\"Metrics\"][\"UsageQuantity\"][\"Amount\"])\n unit = group[\"Metrics\"][\"UsageQuantity\"][\"Unit\"]\n\n if unit == \"ByteHrs\":\n usage_amount = (usage_amount / (1024**3)) / hours_in_month\n elif unit in [\"MB-Mo\", \"Megabyte-Months\"]:\n usage_amount /= 1024\n\n if acc_id in account_storage_totals:\n account_storage_totals[acc_id] += usage_amount\n\n next_token = response.get(\"NextPageToken\")\n if not next_token:\n break\n\n print(f\"\\n--- Storage Report ({start_date} to {end_date}) ---\")\n print(f\"{'Account Name':<25} | {'Storage (GB)':<12} | {'Overage (>100GB)'}\")\n print(\"-\" * 75)\n\n rows = []\n sorted_accounts = sorted(\n account_storage_totals.items(), key=lambda x: x[1], reverse=True\n )\n for acc_id, total_gb in sorted_accounts:\n acc_name = all_accounts.get(acc_id, acc_id)\n overage = max(0, total_gb - threshold_gb)\n status_icon = \"⚠️\" if overage > 0 else \"✅\"\n print(\n f\"{acc_name[:25]:<25} | {total_gb:>10.2f} GB | {overage:>8.2f} GB {status_icon}\"\n )\n rows.append([acc_name, acc_id, round(total_gb, 2), round(overage, 2)])\n\n headers = [\n \"Account Name\",\n \"Account ID\",\n f\"Storage GB ({start_date})\",\n \"Overage (>100GB)\",\n ]\n export_to_sheets(\"AWS_Storage_Usage\", headers, rows)\n\n except Exception as e:\n print(f\"Error: {e}\")\n\n\nif __name__ == \"__main__\":\n get_storage_report(100.0)\n"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "import unittest\nfrom unittest.mock import patch, MagicMock\nimport os\nimport sys\nimport importlib.util\n\n# Add project root to path\nPROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), \"..\"))\nsys.path.append(PROJECT_ROOT)\n\n\nclass TestScripts(unittest.TestCase):\n def setUp(self):\n # Patch get_boto_session for all tests to avoid real AWS calls\n self.patcher = patch(\"aws_utils.get_boto_session\")\n self.mock_session = self.patcher.start()\n self.mock_client = MagicMock()\n self.mock_session.return_value.client.return_value = self.mock_client\n\n def tearDown(self):\n self.patcher.stop()\n\n def test_import_bwsuage(self):\n \"\"\"Smoke test to ensure bwsuage.py can be imported.\"\"\"\n spec = importlib.util.spec_from_file_location(\n \"bwsuage\", os.path.join(PROJECT_ROOT, \"bwsuage.py\")\n )\n bwsuage = importlib.util.module_from_spec(spec)\n spec.loader.exec_module(bwsuage)\n self.assertTrue(hasattr(bwsuage, \"get_total_bandwidth_report\"))\n\n def test_import_aws_bills(self):\n \"\"\"Smoke test to ensure aws_bills.py can be imported.\"\"\"\n spec = importlib.util.spec_from_file_location(\n \"aws_bills\", os.path.join(PROJECT_ROOT, \"aws_bills.py\")\n )\n aws_bills = importlib.util.module_from_spec(spec)\n spec.loader.exec_module(aws_bills)\n self.assertTrue(hasattr(aws_bills, \"get_cost_for_range\"))\n\n def test_import_aws_cost(self):\n \"\"\"Smoke test to ensure aws_cost.py can be imported.\"\"\"\n spec = importlib.util.spec_from_file_location(\n \"aws_cost\", os.path.join(PROJECT_ROOT, \"aws_cost.py\")\n )\n aws_cost = importlib.util.module_from_spec(spec)\n spec.loader.exec_module(aws_cost)\n self.assertTrue(hasattr(aws_cost, \"fetch_costs_with_savings\"))\n\n def test_import_aws_vpc(self):\n \"\"\"Smoke test to ensure aws-vpc.py can be imported.\"\"\"\n spec = importlib.util.spec_from_file_location(\n \"aws_vpc\", os.path.join(PROJECT_ROOT, \"aws-vpc.py\")\n )\n aws_vpc = importlib.util.module_from_spec(spec)\n spec.loader.exec_module(aws_vpc)\n self.assertTrue(hasattr(aws_vpc, \"list_vpcs\"))\n\n\nif __name__ == \"__main__\":\n unittest.main()\n"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "import boto3\nfrom botocore.exceptions import ClientError, ProfileNotFound\nfrom aws_utils import setup_org_accounts_session\n\n\ndef list_rds_instances(rds_client):\n instance_names = []\n paginator = rds_client.get_paginator(\"describe_db_instances\")\n for page in paginator.paginate():\n for db_instance in page[\"DBInstances\"]:\n instance_names.append(db_instance[\"DBInstanceIdentifier\"])\n return instance_names\n\n\ndef list_rds_clusters(rds_client):\n cluster_names = []\n paginator = rds_client.get_paginator(\"describe_db_clusters\")\n for page in paginator.paginate():\n for db_cluster in page[\"DBClusters\"]:\n cluster_names.append(db_cluster[\"DBClusterIdentifier\"])\n return cluster_names\n\n\ndef main():\n for account, profile_name in setup_org_accounts_session():\n account_id = account[\"Id\"]\n account_name = account[\"Name\"]\n try:\n boto3.setup_default_session(profile_name=profile_name)\n rds_client = boto3.client(\"rds\")\n\n names = list_rds_instances(rds_client) + list_rds_clusters(rds_client)\n for name in names:\n print(f'\"{account_name}\":\"{name}\"')\n\n print(f\"Processed account '{account_name}' (ID: {account_id})\")\n except (ClientError, ProfileNotFound) as e:\n print(f\"Error accessing account '{account_name}': {e}\")\n\n print(\"\\nRDS names have been successfully listed for all accounts.\")\n\n\nif __name__ == \"__main__\":\n main()\n"
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "import boto3\nimport csv\nfrom botocore.exceptions import ClientError, ProfileNotFound\nfrom aws_utils import setup_org_accounts_session, get_boto_session, export_to_sheets\n\n\ndef get_cloudfront_details(account_id, account_name, cloudfront_client):\n \"\"\"\n Lists all CloudFront distributions for the account and determines\n their associated details.\n \"\"\"\n dist_info_list = []\n try:\n paginator = cloudfront_client.get_paginator(\"list_distributions\")\n for page in paginator.paginate():\n if \"DistributionList\" in page and \"Items\" in page[\"DistributionList\"]:\n for dist in page[\"DistributionList\"][\"Items\"]:\n dist_info_list.append(\n {\n \"AccountName\": account_name,\n \"AccountID\": account_id,\n \"ID\": dist[\"Id\"],\n \"DomainName\": dist[\"DomainName\"],\n \"Status\": dist[\"Status\"],\n \"Enabled\": dist[\"Enabled\"],\n \"Comment\": dist.get(\"Comment\", \"N/A\"),\n }\n )\n except ClientError as e:\n print(f\" -> Error listing distributions: {e}\")\n return dist_info_list\n\n\ndef main():\n get_boto_session()\n all_dist_info = []\n rows_for_sheets = []\n csv_filepath = \"cloudfront_distributions_info.csv\"\n fieldnames = [\n \"AccountName\",\n \"AccountID\",\n \"ID\",\n \"DomainName\",\n \"Status\",\n \"Enabled\",\n \"Comment\",\n ]\n\n with open(csv_filepath, mode=\"w\", newline=\"\") as csvfile:\n writer = csv.DictWriter(csvfile, fieldnames=fieldnames)\n writer.writeheader()\n\n print(\"\\nIterating through accounts to collect CloudFront data...\")\n for account, profile_name in setup_org_accounts_session():\n account_id = account[\"Id\"]\n account_name = account[\"Name\"]\n print(f\"\\n--- Checking Account: {account_name} (ID: {account_id}) ---\")\n\n try:\n boto3.setup_default_session(profile_name=profile_name)\n cloudfront_client = boto3.client(\"cloudfront\")\n\n dist_data = get_cloudfront_details(\n account_id, account_name, cloudfront_client\n )\n for dist in dist_data:\n all_dist_info.append(dist)\n writer.writerow(dist)\n rows_for_sheets.append(list(dist.values()))\n print(\n f\" [FOUND] ID: {dist['ID']}, Domain: {dist['DomainName']}, Status: {dist['Status']}\"\n )\n except (ClientError, ProfileNotFound) as e:\n print(f\" -> Error setting up session/profile '{profile_name}': {e}\")\n\n print(f\"\\nTotal distributions found: {len(all_dist_info)}\")\n print(f\"CSV file '{csv_filepath}' generated successfully.\")\n export_to_sheets(\"cloudfront-distributions\", fieldnames, rows_for_sheets)\n\n\nif __name__ == \"__main__\":\n main()\n"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Successfully modified file: /Users/bob/git/dxw/aws-stuff/audit.py (1 replacements). Here is the updated code:\n...\nimport os\n\n# Audits mapping: command -> (module_name, file_path)\nAUDITS = {\n \"vpc\": (\"audits.vpc\", \"audits/vpc.py\"),\n \"cost\": (\"audits.cost\", \"audits/cost.py\"),\n \"bills\": (\"aws_bills\", \"aws_bills.py\"),\n \"bw\": (\"bwsuage\", \"bwsuage.py\"),\n \"storage\": (\"storage_usage\", \"storage-usage.py\"),\n \"rds\": (\"list_rds_instances\", \"list_rds_instances.py\"),\n \"asg\": (\"aws_asg_lt_ami\", \"aws-asg-lt-ami.py\"),\n..."
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Successfully modified file: /Users/bob/git/dxw/aws-stuff/audit.py (1 replacements). Here is the updated code:\n...\n\n# Audits mapping: command -> (module_name, file_path)\nAUDITS = {\n \"vpc\": (\"audits.vpc\", \"audits/vpc.py\"),\n \"cost\": (\"audits.cost\", \"audits/cost.py\"),\n \"bills\": (\"audits.bills\", \"audits/bills.py\"),\n \"bw\": (\"bwsuage\", \"bwsuage.py\"),\n \"storage\": (\"storage_usage\", \"storage-usage.py\"),\n \"rds\": (\"list_rds_instances\", \"list_rds_instances.py\"),\n \"asg\": (\"aws_asg_lt_ami\", \"aws-asg-lt-ami.py\"),\n \"ips\": (\"aws_ips\", \"aws-ips.py\"),\n..."
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Successfully modified file: /Users/bob/git/dxw/aws-stuff/audit.py (1 replacements). Here is the updated code:\n...\n# Audits mapping: command -> (module_name, file_path)\nAUDITS = {\n \"vpc\": (\"audits.vpc\", \"audits/vpc.py\"),\n \"cost\": (\"audits.cost\", \"audits/cost.py\"),\n \"bills\": (\"audits.bills\", \"audits/bills.py\"),\n \"bw\": (\"audits.bw\", \"audits/bw.py\"),\n \"storage\": (\"storage_usage\", \"storage-usage.py\"),\n \"rds\": (\"list_rds_instances\", \"list_rds_instances.py\"),\n \"asg\": (\"aws_asg_lt_ami\", \"aws-asg-lt-ami.py\"),\n \"ips\": (\"aws_ips\", \"aws-ips.py\"),\n \"cloudfront\": (\"cloudfront\", \"cloudfront.py\"),\n..."
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Successfully modified file: /Users/bob/git/dxw/aws-stuff/audit.py (1 replacements). Here is the updated code:\n...\nAUDITS = {\n \"vpc\": (\"audits.vpc\", \"audits/vpc.py\"),\n \"cost\": (\"audits.cost\", \"audits/cost.py\"),\n \"bills\": (\"audits.bills\", \"audits/bills.py\"),\n \"bw\": (\"audits.bw\", \"audits/bw.py\"),\n \"storage\": (\"audits.storage\", \"audits/storage.py\"),\n \"rds\": (\"list_rds_instances\", \"list_rds_instances.py\"),\n \"asg\": (\"aws_asg_lt_ami\", \"aws-asg-lt-ami.py\"),\n \"ips\": (\"aws_ips\", \"aws-ips.py\"),\n \"cloudfront\": (\"cloudfront\", \"cloudfront.py\"),\n \"s3\": (\"s3_security_audit\", \"s3-security-audit.py\"),\n..."
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Successfully modified file: /Users/bob/git/dxw/aws-stuff/audit.py (1 replacements). Here is the updated code:\n...\n \"vpc\": (\"audits.vpc\", \"audits/vpc.py\"),\n \"cost\": (\"audits.cost\", \"audits/cost.py\"),\n \"bills\": (\"audits.bills\", \"audits/bills.py\"),\n \"bw\": (\"audits.bw\", \"audits/bw.py\"),\n \"storage\": (\"audits.storage\", \"audits/storage.py\"),\n \"rds\": (\"audits.rds\", \"audits/rds.py\"),\n \"asg\": (\"aws_asg_lt_ami\", \"aws-asg-lt-ami.py\"),\n \"ips\": (\"aws_ips\", \"aws-ips.py\"),\n \"cloudfront\": (\"cloudfront\", \"cloudfront.py\"),\n \"s3\": (\"s3_security_audit\", \"s3-security-audit.py\"),\n \"sg\": (\"security_group_audit\", \"security-group-audit.py\"),\n..."
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Successfully modified file: /Users/bob/git/dxw/aws-stuff/audit.py (1 replacements). Here is the updated code:\n...\n \"cost\": (\"audits.cost\", \"audits/cost.py\"),\n \"bills\": (\"audits.bills\", \"audits/bills.py\"),\n \"bw\": (\"audits.bw\", \"audits/bw.py\"),\n \"storage\": (\"audits.storage\", \"audits/storage.py\"),\n \"rds\": (\"audits.rds\", \"audits/rds.py\"),\n \"asg\": (\"audits.asg\", \"audits/asg.py\"),\n \"ips\": (\"aws_ips\", \"aws-ips.py\"),\n \"cloudfront\": (\"cloudfront\", \"cloudfront.py\"),\n \"s3\": (\"s3_security_audit\", \"s3-security-audit.py\"),\n \"sg\": (\"security_group_audit\", \"security-group-audit.py\"),\n \"iam\": (\"iam_audit\", \"iam-audit.py\"),\n..."
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Output: (empty)\nProcess Group PGID: 75742"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Output: (empty)\nProcess Group PGID: 76074"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Output: (empty)\nProcess Group PGID: 76146"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Output: Running tests...\n./scripts/test: line 10: pytest: command not found\nExit Code: 127\nProcess Group PGID: 76348"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Output: Installing dependencies...\n\n[notice] A new release of pip is available: 24.2 -> 26.0.1\n[notice] To update, run: pip install --upgrade pip\n\n[notice] A new release of pip is available: 24.2 -> 26.0.1\n[notice] To update, run: pip install --upgrade pip\nSetup complete.\nRunning tests...\n====================================================== test session starts =======================================================\nplatform darwin -- Python 3.12.13, pytest-9.0.2, pluggy-1.6.0\nrootdir: /Users/bob/git/dxw/aws-stuff\nplugins: anyio-4.12.1\ncollected 18 items \n\ntests/test_aws_utils.py ............ [ 66%]\ntests/test_scripts.py .... [ 88%]\ntests/test_vpc.py .. [100%]\n\n======================================================= 18 passed in 0.14s =======================================================\nProcess Group PGID: 76391"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Output: (empty)\nProcess Group PGID: 76621"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Output: (empty)\nProcess Group PGID: 80538"
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"error": "[Operation Cancelled] Reason: User denied execution."
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Output: Running tests...\n====================================================== test session starts =======================================================\nplatform darwin -- Python 3.12.13, pytest-9.0.2, pluggy-1.6.0\nrootdir: /Users/bob/git/dxw/aws-stuff\nplugins: anyio-4.12.1\ncollected 18 items \n\ntests/test_aws_utils.py ............ [ 66%]\ntests/test_bills.py . [ 72%]\ntests/test_bw.py . [ 77%]\ntests/test_cost.py . [ 83%]\ntests/test_storage.py . [ 88%]\ntests/test_vpc.py .. [100%]\n\n======================================================= 18 passed in 0.14s =======================================================\nProcess Group PGID: 81294"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Output: Running tests...\n====================================================== test session starts =======================================================\nplatform darwin -- Python 3.12.13, pytest-9.0.2, pluggy-1.6.0\nrootdir: /Users/bob/git/dxw/aws-stuff\nplugins: anyio-4.12.1\ncollected 20 items \n\ntests/test_asg.py . [ 5%]\ntests/test_aws_utils.py ............ [ 65%]\ntests/test_bills.py . [ 70%]\ntests/test_bw.py . [ 75%]\ntests/test_cost.py . [ 80%]\ntests/test_rds.py . [ 85%]\ntests/test_storage.py . [ 90%]\ntests/test_vpc.py .. [100%]\n\n======================================================= 20 passed in 0.15s =======================================================\nProcess Group PGID: 81383"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Successfully overwrote file: /Users/bob/git/dxw/aws-stuff/scripts/setup. Here is the updated code:\n#!/bin/bash\nset -e\n\n# Create virtual environment if it doesn't exist\nif [ ! -d \".venv\" ]; then\n echo \"Creating virtual environment...\"\n python3 -m venv .venv\nfi\n\n# Activate virtualenv and install dependencies\nsource .venv/bin/activate\necho \"Installing dependencies...\"\npip install --quiet -r requirements.txt\npip install --quiet pytest ruff\n\n# Setup .env if it doesn't exist\nif [ ! -f \".env\" ]; then\n echo \"Copying .env.example to .env...\"\n cp .env.example .env\nfi\n\necho \"Setup complete.\"\n"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Successfully overwrote file: /Users/bob/git/dxw/aws-stuff/scripts/test. Here is the updated code:\n#!/bin/bash\nset -e\n\n# Use current virtualenv if available\nif [ -d \".venv\" ]; then\n source .venv/bin/activate\nfi\n\necho \"Running tests...\"\npytest tests/\n"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Successfully overwrote file: /Users/bob/git/dxw/aws-stuff/scripts/lint. Here is the updated code:\n#!/bin/bash\nset -e\n\n# Use current virtualenv if available\nif [ -d \".venv\" ]; then\n source .venv/bin/activate\nfi\n\necho \"Running linting (ruff)...\"\nruff check .\necho \"Running formatting check (ruff)...\"\nruff format --check .\n"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Successfully created and wrote to new file: /Users/bob/git/dxw/aws-stuff/audits/vpc.py. Here is the updated code:\nimport boto3\nimport csv\nfrom botocore.exceptions import ClientError, ProfileNotFound\nfrom aws_utils import setup_org_accounts_session, get_boto_session, export_to_sheets\n\ndef get_vpc_name(tags):\n if tags:\n for tag in tags:\n if tag[\"Key\"] == \"Name\":\n return tag[\"Value\"]\n return \"Unnamed VPC\"\n\ndef fetch_vpcs(ec2_client):\n \"\"\"\n Fetches VPC information from a single region.\n Returns a list of dicts.\n \"\"\"\n vpcs_info = []\n try:\n paginator = ec2_client.get_paginator(\"describe_vpcs\")\n for page in paginator.paginate():\n for vpc in page[\"Vpcs\"]:\n vpcs_info.append(\n {\n \"VPCName\": get_vpc_name(vpc.get(\"Tags\")),\n \"VPCID\": vpc[\"VpcId\"],\n \"CIDRBlock\": vpc.get(\"CidrBlock\", \"N/A\"),\n }\n )\n except ClientError as e:\n print(f\"Error fetching VPCs: {e}\")\n return vpcs_info\n\ndef get_all_org_vpcs(regions=None):\n \"\"\"\n Iterates through all accounts and regions to gather VPC info.\n Returns a list of rows (dicts) for the report.\n \"\"\"\n if regions is None:\n regions = [\"eu-west-1\", \"eu-west-2\"]\n \n all_rows = []\n for account, profile_name in setup_org_accounts_session():\n account_id = account[\"Id\"]\n account_name = account[\"Name\"]\n try:\n # We use a session per account\n account_session = boto3.Session(profile_name=profile_name)\n for region in regions:\n try:\n ec2_client = account_session.client(\"ec2\", region_name=region)\n vpcs_info = fetch_vpcs(ec2_client)\n \n for vpc in vpcs_info:\n row = {\n \"AccountName\": account_name,\n \"AccountID\": account_id,\n \"Region\": region,\n \"VPCName\": vpc[\"VPCName\"],\n \"VPCID\": vpc[\"VPCID\"],\n \"CIDRBlock\": vpc[\"CIDRBlock\"],\n }\n all_rows.append(row)\n \n if vpcs_info:\n print(f'\"{account_name}\" ({account_id}, {region}) VPCs found: {len(vpcs_info)}')\n except ClientError as e:\n print(f\"Error in {region} for {account_name}: {e}\")\n except (ClientError, ProfileNotFound) as e:\n print(f\"Error accessing account {account_name}: {e}\")\n \n return all_rows\n\ndef run():\n \"\"\"Main entry point for the VPC audit.\"\"\"\n get_boto_session() # Ensure SSO login\n \n rows = get_all_org_vpcs()\n fieldnames = [\"AccountName\", \"AccountID\", \"Region\", \"VPCName\", \"VPCID\", \"CIDRBlock\"]\n \n # Write to CSV\n output_file = \"aws_vpcs_by_region.csv\"\n with open(output_file, mode=\"w\", newline=\"\") as csvfile:\n writer = csv.DictWriter(csvfile, fieldnames=fieldnames)\n writer.writeheader()\n for row in rows:\n writer.writerow(row)\n \n print(f\"\\nTotal number of VPCs found: {len(rows)}\")\n print(f\"CSV file '{output_file}' generated successfully.\")\n \n # Export to Google Sheets\n rows_for_sheets = [list(row.values()) for row in rows]\n export_to_sheets(\"aws-vpc\", fieldnames, rows_for_sheets)\n\nif __name__ == \"__main__\":\n run()\n"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Successfully created and wrote to new file: /Users/bob/git/dxw/aws-stuff/tests/test_vpc.py. Here is the updated code:\nimport unittest\nfrom unittest.mock import MagicMock, patch\nfrom audits.vpc import fetch_vpcs, get_vpc_name\n\nclass TestVpcAudit(unittest.TestCase):\n def test_get_vpc_name(self):\n tags = [{\"Key\": \"Name\", \"Value\": \"MyVPC\"}]\n self.assertEqual(get_vpc_name(tags), \"MyVPC\")\n \n tags_no_name = [{\"Key\": \"Environment\", \"Value\": \"Prod\"}]\n self.assertEqual(get_vpc_name(tags_no_name), \"Unnamed VPC\")\n \n self.assertEqual(get_vpc_name([]), \"Unnamed VPC\")\n self.assertEqual(get_vpc_name(None), \"Unnamed VPC\")\n\n def test_fetch_vpcs(self):\n # Mock EC2 client and paginator\n mock_ec2 = MagicMock()\n mock_paginator = MagicMock()\n mock_ec2.get_paginator.return_value = mock_paginator\n \n # Mock the response from describe_vpcs\n mock_paginator.paginate.return_value = [\n {\n \"Vpcs\": [\n {\n \"VpcId\": \"vpc-123\",\n \"CidrBlock\": \"10.0.0.0/16\",\n \"Tags\": [{\"Key\": \"Name\", \"Value\": \"TestVPC\"}]\n },\n {\n \"VpcId\": \"vpc-456\",\n \"CidrBlock\": \"192.168.0.0/24\"\n # No Name tag\n }\n ]\n }\n ]\n \n vpcs = fetch_vpcs(mock_ec2)\n \n self.assertEqual(len(vpcs), 2)\n self.assertEqual(vpcs[0][\"VPCName\"], \"TestVPC\")\n self.assertEqual(vpcs[0][\"VPCID\"], \"vpc-123\")\n self.assertEqual(vpcs[0][\"CIDRBlock\"], \"10.0.0.0/16\")\n \n self.assertEqual(vpcs[1][\"VPCName\"], \"Unnamed VPC\")\n self.assertEqual(vpcs[1][\"VPCID\"], \"vpc-456\")\n self.assertEqual(vpcs[1][\"CIDRBlock\"], \"192.168.0.0/24\")\n\nif __name__ == \"__main__\":\n unittest.main()\n"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Successfully created and wrote to new file: /Users/bob/git/dxw/aws-stuff/audit.py. Here is the updated code:\nimport argparse\nimport sys\nimport importlib.util\nimport os\n\n# Audits mapping: command -> (module_name, file_path)\nAUDITS = {\n \"vpc\": (\"audits.vpc\", \"audits/vpc.py\"),\n \"cost\": (\"aws_cost\", \"aws_cost.py\"),\n \"bills\": (\"aws_bills\", \"aws_bills.py\"),\n \"bw\": (\"bwsuage\", \"bwsuage.py\"),\n \"storage\": (\"storage_usage\", \"storage-usage.py\"),\n \"rds\": (\"list_rds_instances\", \"list_rds_instances.py\"),\n \"asg\": (\"aws_asg_lt_ami\", \"aws-asg-lt-ami.py\"),\n \"ips\": (\"aws_ips\", \"aws-ips.py\"),\n \"cloudfront\": (\"cloudfront\", \"cloudfront.py\"),\n \"s3\": (\"s3_security_audit\", \"s3-security-audit.py\"),\n \"sg\": (\"security_group_audit\", \"security-group-audit.py\"),\n \"iam\": (\"iam_audit\", \"iam-audit.py\"),\n \"carbon\": (\"aws_carbon\", \"aws-carbon.py\"),\n \"metrics\": (\"aws_metrics\", \"aws-metrics.py\"),\n}\n\ndef run_audit(name):\n if name not in AUDITS:\n print(f\"Error: Unknown audit '{name}'\")\n print_usage()\n sys.exit(1)\n \n module_name, file_path = AUDITS[name]\n \n if not os.path.exists(file_path):\n print(f\"Error: File not found for audit '{name}': {file_path}\")\n sys.exit(1)\n \n print(f\"Running audit: {name}...\")\n \n # Import and run the module\n spec = importlib.util.spec_from_file_location(module_name, file_path)\n module = importlib.util.module_from_spec(spec)\n sys.modules[module_name] = module\n spec.loader.exec_module(module)\n \n # Check if there's a 'run' or 'main' function\n if hasattr(module, \"run\"):\n module.run()\n elif hasattr(module, \"main\"):\n module.main()\n else:\n print(f\"Error: Audit '{name}' (in {file_path}) does not have a run() or main() function.\")\n sys.exit(1)\n\ndef print_usage():\n print(\"\\nAvailable audits:\")\n for name in sorted(AUDITS.keys()):\n print(f\" - {name}\")\n\ndef main():\n parser = argparse.ArgumentParser(description=\"AWS Organization Audit CLI\")\n parser.add_argument(\"audit\", nargs=\"?\", help=\"Name of the audit to run\")\n parser.add_argument(\"--list\", action=\"store_true\", help=\"List available audits\")\n \n args = parser.parse_args()\n \n if args.list or not args.audit:\n print_usage()\n return\n \n run_audit(args.audit)\n\nif __name__ == \"__main__\":\n main()\n"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Successfully created and wrote to new file: /Users/bob/git/dxw/aws-stuff/scripts/audit. Here is the updated code:\n#!/bin/bash\nset -e\n\n# Use current virtualenv if available\nif [ -d \".venv\" ]; then\n source .venv/bin/activate\nfi\n\npython3 audit.py \"$@\"\n"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Successfully created and wrote to new file: /Users/bob/git/dxw/aws-stuff/audits/cost.py. Here is the updated code:\nimport boto3\nfrom botocore.exceptions import ClientError\nfrom aws_utils import get_account_names, get_previous_month_range, get_boto_session\n\ndef fetch_costs_with_savings(ce_client, start_date, end_date, account_map):\n \"\"\"\n Fetches EC2 costs grouped by account and service.\n Returns a list of dicts with cost details.\n \"\"\"\n results = []\n try:\n response = ce_client.get_cost_and_usage(\n TimePeriod={\"Start\": start_date, \"End\": end_date},\n Granularity=\"MONTHLY\",\n Metrics=[\n \"UnblendedCost\",\n \"AmortizedCost\",\n \"NetAmortizedCost\",\n \"NetUnblendedCost\",\n ],\n GroupBy=[\n {\"Type\": \"DIMENSION\", \"Key\": \"LINKED_ACCOUNT\"},\n {\"Type\": \"DIMENSION\", \"Key\": \"SERVICE\"},\n ],\n )\n\n if not response.get(\"ResultsByTime\"):\n return results\n\n for result in response[\"ResultsByTime\"]:\n period_start = result[\"TimePeriod\"][\"Start\"]\n\n for group in result[\"Groups\"]:\n account_id = group[\"Keys\"][0]\n service = group[\"Keys\"][1]\n\n if \"Amazon Elastic Compute Cloud\" in service:\n metrics = group[\"Metrics\"]\n unblended = float(metrics[\"UnblendedCost\"][\"Amount\"])\n amortized = float(metrics[\"AmortizedCost\"][\"Amount\"])\n net_amortized = float(metrics[\"NetAmortizedCost\"][\"Amount\"])\n net_unblended = float(metrics[\"NetUnblendedCost\"][\"Amount\"])\n unit = metrics[\"UnblendedCost\"][\"Unit\"]\n\n account_name = account_map.get(account_id, account_id)\n\n results.append({\n \"PeriodStart\": period_start,\n \"AccountName\": account_name,\n \"AccountID\": account_id,\n \"Service\": service,\n \"UnblendedCost\": unblended,\n \"AmortizedCost\": amortized,\n \"NetAmortizedCost\": net_amortized,\n \"NetUnblendedCost\": net_unblended,\n \"Unit\": unit\n })\n\n except ClientError as e:\n print(f\"Error fetching costs: {e}\")\n \n return results\n\ndef run():\n session = get_boto_session()\n ce_client = session.client(\"ce\", region_name=\"us-east-1\")\n account_map = get_account_names()\n start_date, end_date = get_previous_month_range()\n\n print(f\"Fetching AWS EC2 costs with compute savings from {start_date} to {end_date}...\")\n \n cost_data = fetch_costs_with_savings(ce_client, start_date, end_date, account_map)\n \n if not cost_data:\n print(\"No cost data available for the specified period.\")\n return\n\n for item in cost_data:\n print(f\"Billing Period: {item['PeriodStart']}\")\n print(f\"Account: {item['AccountName']} | Service: {item['Service']}\")\n print(f\" - Total Cost (Unblended): {item['UnblendedCost']} {item['Unit']}\")\n print(f\" - Net Cost (Amortized): {item['NetAmortizedCost']} {item['Unit']}\")\n print(f\" - Net Cost (Unblended): {item['NetUnblendedCost']} {item['Unit']}\")\n print(f\" - Final Cost (Amortized): {item['AmortizedCost']} {item['Unit']}\")\n\nif __name__ == \"__main__\":\n run()\n"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Successfully created and wrote to new file: /Users/bob/git/dxw/aws-stuff/audits/bills.py. Here is the updated code:\nimport boto3\nfrom botocore.exceptions import ClientError\nfrom aws_utils import get_account_names, get_last_n_months_ranges, get_boto_session\n\ndef fetch_bills(ce_client, ranges):\n \"\"\"\n Fetches unblended and amortized costs across given ranges.\n Returns a dict: { account_id: { \"unblended\": [m1, m2, m3], \"amortized\": [m1, m2, m3] } }\n \"\"\"\n account_costs = {}\n \n for start_date, end_date, _ in ranges:\n try:\n response = ce_client.get_cost_and_usage(\n TimePeriod={\"Start\": start_date, \"End\": end_date},\n Granularity=\"MONTHLY\",\n Metrics=[\"UnblendedCost\", \"AmortizedCost\"],\n GroupBy=[{\"Type\": \"DIMENSION\", \"Key\": \"LINKED_ACCOUNT\"}],\n )\n\n for result in response[\"ResultsByTime\"]:\n for group in result[\"Groups\"]:\n account_id = group[\"Keys\"][0]\n unblended = float(group[\"Metrics\"][\"UnblendedCost\"][\"Amount\"])\n amortized = float(group[\"Metrics\"][\"AmortizedCost\"][\"Amount\"])\n\n if account_id not in account_costs:\n account_costs[account_id] = {\"unblended\": [], \"amortized\": []}\n\n account_costs[account_id][\"unblended\"].append(unblended)\n account_costs[account_id][\"amortized\"].append(amortized)\n except ClientError as e:\n print(f\"Error fetching cost for range {start_date} to {end_date}: {e}\")\n \n return account_costs\n\ndef run():\n session = get_boto_session()\n ce_client = session.client(\"ce\")\n account_names = get_account_names()\n\n ranges = get_last_n_months_ranges(3)\n months_labels = [r[2] for r in ranges]\n\n account_costs = fetch_bills(ce_client, ranges)\n\n # Sort accounts by the most recent month's amortized cost\n sorted_accounts = sorted(\n account_costs.items(),\n key=lambda item: item[1][\"amortized\"][0] if item[1][\"amortized\"] else 0,\n reverse=True,\n )\n\n print(f\"\\nAWS Costs for the last 3 months (Amortized and Unblended, sorted by highest Amortized Cost in {months_labels[0]}):\")\n header = f\"{'Account Name':<30} {' ' + months_labels[0] + ' (Amort)':<15} {' ' + months_labels[1] + ' (Amort)':<15} {' ' + months_labels[2] + ' (Amort)':<15} {' ' + months_labels[0] + ' (Unbl)':<15} {' ' + months_labels[1] + ' (Unbl)':<15} {' ' + months_labels[2] + ' (Unbl)':<15}\"\n print(header)\n print(\"-\" * 125)\n\n for account_id, costs in sorted_accounts:\n name = account_names.get(account_id, f\"Unknown ({account_id})\")\n\n # Ensure we have 3 months of data\n amortized = costs[\"amortized\"] + [0.0] * (3 - len(costs[\"amortized\"]))\n unblended = costs[\"unblended\"] + [0.0] * (3 - len(costs[\"unblended\"]))\n\n amortized_fmt = [f\"${c:,.2f}\" for c in amortized[:3]]\n unblended_fmt = [f\"${c:,.2f}\" for c in unblended[:3]]\n\n print(\n f\"{name[:30]:<30} {amortized_fmt[0]:>15} {amortized_fmt[1]:>15} {amortized_fmt[2]:>15} {unblended_fmt[0]:>15} {unblended_fmt[1]:>15} {unblended_fmt[2]:>15}\"\n )\n\nif __name__ == \"__main__\":\n run()\n"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Successfully created and wrote to new file: /Users/bob/git/dxw/aws-stuff/tests/test_cost.py. Here is the updated code:\nimport unittest\nfrom unittest.mock import MagicMock\nfrom audits.cost import fetch_costs_with_savings\n\nclass TestCostAudit(unittest.TestCase):\n def test_fetch_costs_with_savings(self):\n mock_ce = MagicMock()\n \n # Mock response\n mock_ce.get_cost_and_usage.return_value = {\n \"ResultsByTime\": [\n {\n \"TimePeriod\": {\"Start\": \"2023-10-01\", \"End\": \"2023-11-01\"},\n \"Groups\": [\n {\n \"Keys\": [\"123456789012\", \"Amazon Elastic Compute Cloud - Compute\"],\n \"Metrics\": {\n \"UnblendedCost\": {\"Amount\": \"100.0\", \"Unit\": \"USD\"},\n \"AmortizedCost\": {\"Amount\": \"90.0\", \"Unit\": \"USD\"},\n \"NetAmortizedCost\": {\"Amount\": \"85.0\", \"Unit\": \"USD\"},\n \"NetUnblendedCost\": {\"Amount\": \"95.0\", \"Unit\": \"USD\"},\n }\n }\n ]\n }\n ]\n }\n \n account_map = {\"123456789012\": \"Test Account\"}\n \n results = fetch_costs_with_savings(mock_ce, \"2023-10-01\", \"2023-11-01\", account_map)\n \n self.assertEqual(len(results), 1)\n self.assertEqual(results[0][\"AccountName\"], \"Test Account\")\n self.assertEqual(results[0][\"Service\"], \"Amazon Elastic Compute Cloud - Compute\")\n self.assertEqual(results[0][\"UnblendedCost\"], 100.0)\n self.assertEqual(results[0][\"AmortizedCost\"], 90.0)\n\nif __name__ == \"__main__\":\n unittest.main()\n"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Successfully created and wrote to new file: /Users/bob/git/dxw/aws-stuff/tests/test_bills.py. Here is the updated code:\nimport unittest\nfrom unittest.mock import MagicMock\nfrom audits.bills import fetch_bills\n\nclass TestBillsAudit(unittest.TestCase):\n def test_fetch_bills(self):\n mock_ce = MagicMock()\n \n # Mock response for one range\n mock_ce.get_cost_and_usage.return_value = {\n \"ResultsByTime\": [\n {\n \"Groups\": [\n {\n \"Keys\": [\"123456789012\"],\n \"Metrics\": {\n \"UnblendedCost\": {\"Amount\": \"100.0\", \"Unit\": \"USD\"},\n \"AmortizedCost\": {\"Amount\": \"90.0\", \"Unit\": \"USD\"},\n }\n }\n ]\n }\n ]\n }\n \n ranges = [(\"2023-10-01\", \"2023-11-01\", \"2023-10\")]\n \n results = fetch_bills(mock_ce, ranges)\n \n self.assertIn(\"123456789012\", results)\n self.assertEqual(results[\"123456789012\"][\"unblended\"], [100.0])\n self.assertEqual(results[\"123456789012\"][\"amortized\"], [90.0])\n\nif __name__ == \"__main__\":\n unittest.main()\n"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Successfully created and wrote to new file: /Users/bob/git/dxw/aws-stuff/audits/bw.py. Here is the updated code:\nimport boto3\nfrom botocore.exceptions import ClientError\nfrom aws_utils import (\n get_account_names,\n get_previous_month_range,\n get_boto_session,\n export_to_sheets,\n)\n\ndef fetch_bandwidth(ce_client, start_date, end_date, all_accounts):\n \"\"\"\n Fetches bandwidth usage grouped by account.\n Returns a dict: { account_id: total_usage_in_gb }\n \"\"\"\n account_totals = {acc_id: 0.0 for acc_id in all_accounts.keys()}\n next_token = None\n\n try:\n while True:\n params = {\n \"TimePeriod\": {\"Start\": start_date, \"End\": end_date},\n \"Granularity\": \"MONTHLY\",\n \"Metrics\": [\"UsageQuantity\"],\n \"GroupBy\": [\n {\"Type\": \"DIMENSION\", \"Key\": \"LINKED_ACCOUNT\"},\n {\"Type\": \"DIMENSION\", \"Key\": \"USAGE_TYPE\"},\n ],\n }\n if next_token:\n params[\"NextPageToken\"] = next_token\n\n response = ce_client.get_cost_and_usage(**params)\n\n for result in response.get(\"ResultsByTime\", []):\n for group in result.get(\"Groups\", []):\n acc_id = group[\"Keys\"][0]\n usage_type = group[\"Keys\"][1]\n usage_amount = float(group[\"Metrics\"][\"UsageQuantity\"][\"Amount\"])\n unit = group[\"Metrics\"][\"UsageQuantity\"][\"Unit\"]\n\n if \"DataTransfer\" in usage_type:\n if unit == \"Bytes\":\n usage_amount /= 1024**3\n elif unit in [\"MB\", \"Megabytes\"]:\n usage_amount /= 1024\n\n if acc_id in account_totals:\n account_totals[acc_id] += usage_amount\n else:\n account_totals[acc_id] = usage_amount\n\n next_token = response.get(\"NextPageToken\")\n if not next_token:\n break\n except ClientError as e:\n print(f\"Error fetching bandwidth: {e}\")\n\n return account_totals\n\ndef run():\n threshold_gb = 100.0\n session = get_boto_session()\n ce_client = session.client(\"ce\")\n all_accounts = get_account_names()\n \n if not all_accounts:\n print(\"No accounts found.\")\n return\n\n start_date, end_date = get_previous_month_range()\n \n account_totals = fetch_bandwidth(ce_client, start_date, end_date, all_accounts)\n\n print(f\"\\n--- Full Bandwidth Report ({start_date} to {end_date}) ---\")\n print(f\"{'Account Name':<25} | {'Total GB':<12} | {'Overage (>100GB)'}\")\n print(\"-\" * 75)\n\n sorted_accounts = sorted(\n account_totals.items(),\n key=lambda x: (x[1], all_accounts.get(x[0], x[0])),\n reverse=True,\n )\n\n headers = [\"Account Name\", \"Account ID\", \"Total GB\", \"Overage (>100GB)\"]\n rows = []\n\n for acc_id, total_usage in sorted_accounts:\n acc_name = all_accounts.get(acc_id, f\"Deleted/Unknown ({acc_id})\")\n overage = max(0, total_usage - threshold_gb)\n status_icon = \"⚠️\" if overage > 0 else \"✅\"\n print(\n f\"{acc_name[:25]:<25} | {total_usage:>10.2f} GB | {overage:>8.2f} GB {status_icon}\"\n )\n\n rows.append([acc_name, acc_id, round(total_usage, 2), round(overage, 2)])\n\n # Export to Google Sheets\n export_to_sheets(\"AWS_Bandwidth_Usage\", headers, rows)\n\nif __name__ == \"__main__\":\n run()\n"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Successfully created and wrote to new file: /Users/bob/git/dxw/aws-stuff/audits/storage.py. Here is the updated code:\nimport boto3\nimport calendar\nfrom datetime import datetime, timedelta\nfrom botocore.exceptions import ClientError\nfrom aws_utils import (\n get_account_names,\n get_previous_month_range,\n get_boto_session,\n export_to_sheets,\n)\n\ndef fetch_storage(ce_client, start_date, end_date, all_accounts, hours_in_month):\n \"\"\"\n Fetches storage usage grouped by account.\n Returns a dict: { account_id: total_gb }\n \"\"\"\n account_storage_totals = {acc_id: 0.0 for acc_id in all_accounts.keys()}\n next_token = None\n\n try:\n while True:\n params = {\n \"TimePeriod\": {\"Start\": start_date, \"End\": end_date},\n \"Granularity\": \"MONTHLY\",\n \"Metrics\": [\"UsageQuantity\"],\n \"GroupBy\": [\n {\"Type\": \"DIMENSION\", \"Key\": \"LINKED_ACCOUNT\"},\n {\"Type\": \"DIMENSION\", \"Key\": \"USAGE_TYPE\"},\n ],\n \"Filter\": {\n \"Dimensions\": {\n \"Key\": \"USAGE_TYPE_GROUP\",\n \"Values\": [\n \"S3: Storage - Standard\",\n \"S3: Storage - Infinite Archive\",\n \"EC2: EBS - Optimized Storage\",\n \"RDS: Storage\",\n \"EFS: Storage - Standard\",\n \"EFS: Storage - IA\",\n \"EFS: Storage - Archive\",\n ],\n }\n },\n }\n if next_token:\n params[\"NextPageToken\"] = next_token\n\n response = ce_client.get_cost_and_usage(**params)\n\n for result in response.get(\"ResultsByTime\", []):\n for group in result.get(\"Groups\", []):\n acc_id = group[\"Keys\"][0]\n usage_amount = float(group[\"Metrics\"][\"UsageQuantity\"][\"Amount\"])\n unit = group[\"Metrics\"][\"UsageQuantity\"][\"Unit\"]\n\n if unit == \"ByteHrs\":\n usage_amount = (usage_amount / (1024**3)) / hours_in_month\n elif unit in [\"MB-Mo\", \"Megabyte-Months\"]:\n usage_amount /= 1024\n\n if acc_id in account_storage_totals:\n account_storage_totals[acc_id] += usage_amount\n\n next_token = response.get(\"NextPageToken\")\n if not next_token:\n break\n except ClientError as e:\n print(f\"Error fetching storage: {e}\")\n \n return account_storage_totals\n\ndef run():\n threshold_gb = 100.0\n session = get_boto_session()\n ce_client = session.client(\"ce\")\n all_accounts = get_account_names()\n start_date, end_date = get_previous_month_range()\n\n # Calculate hours in the previous month for Byte-Hour conversion\n dt_end = datetime.strptime(end_date, \"%Y-%m-%d\")\n last_day_prev = dt_end - timedelta(days=1)\n _, num_days = calendar.monthrange(last_day_prev.year, last_day_prev.month)\n hours_in_month = num_days * 24\n\n account_storage_totals = fetch_storage(ce_client, start_date, end_date, all_accounts, hours_in_month)\n\n print(f\"\\n--- Storage Report ({start_date} to {end_date}) ---\")\n print(f\"{'Account Name':<25} | {'Storage (GB)':<12} | {'Overage (>100GB)'}\")\n print(\"-\" * 75)\n\n rows = []\n sorted_accounts = sorted(\n account_storage_totals.items(), key=lambda x: x[1], reverse=True\n )\n for acc_id, total_gb in sorted_accounts:\n acc_name = all_accounts.get(acc_id, acc_id)\n overage = max(0, total_gb - threshold_gb)\n status_icon = \"⚠️\" if overage > 0 else \"✅\"\n print(\n f\"{acc_name[:25]:<25} | {total_gb:>10.2f} GB | {overage:>8.2f} GB {status_icon}\"\n )\n rows.append([acc_name, acc_id, round(total_gb, 2), round(overage, 2)])\n\n headers = [\n \"Account Name\",\n \"Account ID\",\n f\"Storage GB ({start_date})\",\n \"Overage (>100GB)\",\n ]\n export_to_sheets(\"AWS_Storage_Usage\", headers, rows)\n\nif __name__ == \"__main__\":\n run()\n"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Successfully created and wrote to new file: /Users/bob/git/dxw/aws-stuff/tests/test_bw.py. Here is the updated code:\nimport unittest\nfrom unittest.mock import MagicMock\nfrom audits.bw import fetch_bandwidth\n\nclass TestBwAudit(unittest.TestCase):\n def test_fetch_bandwidth(self):\n mock_ce = MagicMock()\n \n # Mock response\n mock_ce.get_cost_and_usage.return_value = {\n \"ResultsByTime\": [\n {\n \"Groups\": [\n {\n \"Keys\": [\"123456789012\", \"DataTransfer-Out-Bytes\"],\n \"Metrics\": {\n \"UsageQuantity\": {\"Amount\": str(1024**3 * 50), \"Unit\": \"Bytes\"},\n }\n },\n {\n \"Keys\": [\"123456789012\", \"DataTransfer-Regional-Bytes\"],\n \"Metrics\": {\n \"UsageQuantity\": {\"Amount\": str(1024**3 * 10), \"Unit\": \"Bytes\"},\n }\n }\n ]\n }\n ]\n }\n \n all_accounts = {\"123456789012\": \"Test Account\"}\n \n results = fetch_bandwidth(mock_ce, \"2023-10-01\", \"2023-11-01\", all_accounts)\n \n self.assertIn(\"123456789012\", results)\n # Total usage should be 50 + 10 = 60 GB\n self.assertEqual(results[\"123456789012\"], 60.0)\n\nif __name__ == \"__main__\":\n unittest.main()\n"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Successfully created and wrote to new file: /Users/bob/git/dxw/aws-stuff/tests/test_storage.py. Here is the updated code:\nimport unittest\nfrom unittest.mock import MagicMock\nfrom audits.storage import fetch_storage\n\nclass TestStorageAudit(unittest.TestCase):\n def test_fetch_storage(self):\n mock_ce = MagicMock()\n \n # Mock response\n mock_ce.get_cost_and_usage.return_value = {\n \"ResultsByTime\": [\n {\n \"Groups\": [\n {\n \"Keys\": [\"123456789012\", \"S3: Storage - Standard\"],\n \"Metrics\": {\n \"UsageQuantity\": {\"Amount\": str(1024**3 * 100 * 720), \"Unit\": \"ByteHrs\"},\n }\n }\n ]\n }\n ]\n }\n \n all_accounts = {\"123456789012\": \"Test Account\"}\n hours_in_month = 720\n \n results = fetch_storage(mock_ce, \"2023-10-01\", \"2023-11-01\", all_accounts, hours_in_month)\n \n self.assertIn(\"123456789012\", results)\n # Usage should be 100 GB\n self.assertEqual(results[\"123456789012\"], 100.0)\n\nif __name__ == \"__main__\":\n unittest.main()\n"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Successfully created and wrote to new file: /Users/bob/git/dxw/aws-stuff/audits/rds.py. Here is the updated code:\nimport boto3\nfrom botocore.exceptions import ClientError, ProfileNotFound\nfrom aws_utils import setup_org_accounts_session\n\ndef fetch_rds_resources(rds_client):\n \"\"\"\n Fetches RDS instances and clusters names.\n Returns a list of strings.\n \"\"\"\n resources = []\n try:\n # Instances\n paginator = rds_client.get_paginator(\"describe_db_instances\")\n for page in paginator.paginate():\n for db_instance in page[\"DBInstances\"]:\n resources.append(db_instance[\"DBInstanceIdentifier\"])\n \n # Clusters\n paginator = rds_client.get_paginator(\"describe_db_clusters\")\n for page in paginator.paginate():\n for db_cluster in page[\"DBClusters\"]:\n resources.append(db_cluster[\"DBClusterIdentifier\"])\n except ClientError as e:\n print(f\"Error fetching RDS resources: {e}\")\n \n return resources\n\ndef run():\n \"\"\"Main entry point for RDS audit.\"\"\"\n for account, profile_name in setup_org_accounts_session():\n account_id = account[\"Id\"]\n account_name = account[\"Name\"]\n try:\n account_session = boto3.Session(profile_name=profile_name)\n rds_client = account_session.client(\"rds\")\n\n names = fetch_rds_resources(rds_client)\n for name in names:\n print(f'\"{account_name}\":\"{name}\"')\n\n if names:\n print(f\"Processed account '{account_name}' (ID: {account_id})\")\n except (ClientError, ProfileNotFound) as e:\n print(f\"Error accessing account '{account_name}': {e}\")\n\n print(\"\\nRDS names have been successfully listed for all accounts.\")\n\nif __name__ == \"__main__\":\n run()\n"
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Successfully created and wrote to new file: /Users/bob/git/dxw/aws-stuff/tests/test_rds.py. Here is the updated code:\nimport unittest\nfrom unittest.mock import MagicMock\nfrom audits.rds import fetch_rds_resources\n\nclass TestRdsAudit(unittest.TestCase):\n def test_fetch_rds_resources(self):\n mock_rds = MagicMock()\n \n # Mock instance response\n mock_rds.get_paginator.return_value.paginate.side_effect = [\n [{\"DBInstances\": [{\"DBInstanceIdentifier\": \"db-1\"}]}], # first call (instances)\n [{\"DBClusters\": [{\"DBClusterIdentifier\": \"cluster-1\"}]}] # second call (clusters)\n ]\n \n resources = fetch_rds_resources(mock_rds)\n \n self.assertEqual(len(resources), 2)\n self.assertIn(\"db-1\", resources)\n self.assertIn(\"cluster-1\", resources)\n\nif __name__ == \"__main__\":\n unittest.main()\n"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"output": "Successfully created and wrote to new file: /Users/bob/git/dxw/aws-stuff/tests/test_asg.py. Here is the updated code:\nimport unittest\nfrom unittest.mock import MagicMock, patch\nfrom audits.asg import fetch_asg_details\n\nclass TestAsgAudit(unittest.TestCase):\n @patch(\"audits.asg.get_ami_name\")\n def test_fetch_asg_details_launch_config(self, mock_get_ami_name):\n mock_asg_client = MagicMock()\n mock_ec2_client = MagicMock()\n mock_get_ami_name.return_value = \"TestAMI\"\n \n # Mock ASG with Launch Config\n mock_asg_client.get_paginator.return_value.paginate.return_value = [\n {\n \"AutoScalingGroups\": [\n {\n \"AutoScalingGroupName\": \"asg-lc\",\n \"LaunchConfigurationName\": \"lc-1\"\n }\n ]\n }\n ]\n \n # Mock LC response\n mock_asg_client.describe_launch_configurations.return_value = {\n \"LaunchConfigurations\": [{\"ImageId\": \"ami-123\"}]\n }\n \n results = fetch_asg_details(mock_asg_client, mock_ec2_client, \"123\", \"Acc\", \"region\")\n \n self.assertEqual(len(results), 1)\n self.assertEqual(results[0][\"ASG_Name\"], \"asg-lc\")\n self.assertEqual(results[0][\"Template_Type\"], \"LaunchConfiguration\")\n self.assertEqual(results[0][\"AMI_ID\"], \"ami-123\")\n\nif __name__ == \"__main__\":\n unittest.main()\n"
|
||||
}
|
||||
9629
tmp/aws-stuff/tool_output/run_shell_command_1.txt
Normal file
9629
tmp/aws-stuff/tool_output/run_shell_command_1.txt
Normal file
File diff suppressed because it is too large
Load Diff
9663
tmp/aws-stuff/tool_output/run_shell_command_2.txt
Normal file
9663
tmp/aws-stuff/tool_output/run_shell_command_2.txt
Normal file
File diff suppressed because it is too large
Load Diff
1766
tmp/aws-stuff/tool_output/run_shell_command_3.txt
Normal file
1766
tmp/aws-stuff/tool_output/run_shell_command_3.txt
Normal file
File diff suppressed because one or more lines are too long
9628
tmp/aws-stuff/tool_output/run_shell_command_4.txt
Normal file
9628
tmp/aws-stuff/tool_output/run_shell_command_4.txt
Normal file
File diff suppressed because it is too large
Load Diff
9529
tmp/aws-stuff/tool_output/run_shell_command_5.txt
Normal file
9529
tmp/aws-stuff/tool_output/run_shell_command_5.txt
Normal file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user