cloudsweep-aws 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Abdullah Tahir
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,93 @@
1
+ Metadata-Version: 2.4
2
+ Name: cloudsweep-aws
3
+ Version: 1.0.0
4
+ Summary: Find forgotten AWS resources that are costing you money.
5
+ Keywords: aws,cost,cloud,cli,finops
6
+ Author: Abdullah Tahir
7
+ Author-email: Abdullah Tahir <157417306+abdthr@users.noreply.github.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Requires-Dist: boto3[crt]>=1.43.118
11
+ Requires-Dist: rich>=15.0.0
12
+ Requires-Dist: typer>=0.27.3
13
+ Requires-Python: >=3.12
14
+ Project-URL: Homepage, https://github.com/abdthr/cloudsweep
15
+ Project-URL: Issues, https://github.com/abdthr/cloudsweep/issues
16
+ Description-Content-Type: text/markdown
17
+
18
+ # cloudsweep
19
+ [![Tests](https://github.com/abdthr/cloudsweep/actions/workflows/tests.yml/badge.svg)](https://github.com/abdthr/cloudsweep/actions/workflows/tests.yml)
20
+
21
+ Find forgotten AWS resources that are costing you money.
22
+
23
+ You delete an EC2 instance, but its disk stays behind. It's attached to nothing,
24
+ nobody remembers it exists and it shows up on your bill every month. Cloudsweep
25
+ finds that kind of leftover and tells you roughly what it's costing you.
26
+
27
+ ```
28
+ $ cloudsweep scan --all-regions
29
+ ...
30
+ ┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
31
+ ┃ Region ┃ Resource ┃ ID ┃ Details ┃ Monthly cost ┃
32
+ ┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
33
+ │ us-east-1 │ EBS volume │ vol-0a7c3f19e2b84d561 │ gp2, 500 GB │ $50.00 │
34
+ │ eu-north-1 │ EBS volume │ vol-0e01dd418b516f0ab │ gp3, 100 GB │ $8.00 │
35
+ │ us-east-1 │ Elastic IP │ eipalloc-07d4c1e9a2b3f5a68 │ 3.91.24.17 │ $3.65 │
36
+ └────────────┴────────────┴────────────────────────────┴─────────────┴──────────────┘
37
+ Potential savings: $61.65/month
38
+ ```
39
+
40
+ It can scan a single region or every region your account has enabled.
41
+
42
+ ## What it finds
43
+
44
+ | Resource | Why it costs money |
45
+ |---|---|
46
+ | Unattached EBS volumes | Disks are billed per GB every month, even when nothing uses them |
47
+ | Unused Elastic IPs | AWS charges for every public IPv4 address by the hour, attached or not |
48
+ | Log groups that never expire | CloudWatch keeps logs forever by default, and you pay for every GB stored |
49
+
50
+ ## How it behaves
51
+
52
+ Cloudsweep is read-only. It lists what it finds and leaves the decision to you,
53
+ because an "unused" volume might be someone's backup. If it can't price something,
54
+ it still shows it and marks the cost as `unknown` instead of hiding it.
55
+
56
+ If a region can't be scanned (for example because a policy blocks it), cloudsweep
57
+ skips it, tells you which ones it missed and carries on with the rest.
58
+
59
+ Costs are estimates based on approximate US prices, so treat them as a rough guide.
60
+
61
+ ## Usage
62
+
63
+ You'll need [uv](https://docs.astral.sh/uv/) and AWS credentials (for example from `aws login`).
64
+
65
+ ```bash
66
+ git clone https://github.com/abdthr/cloudsweep.git
67
+ cd cloudsweep
68
+ uv run cloudsweep scan # uses your default AWS region
69
+ uv run cloudsweep scan --region us-east-1
70
+ uv run cloudsweep scan --all-regions # every region enabled for your account
71
+ uv run cloudsweep scan --output json # machine-readable, for scripts
72
+ uv run cloudsweep --help
73
+ ```
74
+
75
+ It only needs read permissions: `ec2:DescribeVolumes`, `ec2:DescribeAddresses`,
76
+ `ec2:DescribeRegions` and `logs:DescribeLogGroups`.
77
+
78
+ ## Tests
79
+
80
+ The tests use [moto](https://github.com/getmoto/moto) to fake AWS, so they don't
81
+ need an account or cost anything.
82
+
83
+ ```bash
84
+ uv run pytest
85
+ ```
86
+
87
+ ## What's next
88
+
89
+ - Publish it so you can `pip install cloudsweep`
90
+
91
+ ## License
92
+
93
+ MIT
@@ -0,0 +1,76 @@
1
+ # cloudsweep
2
+ [![Tests](https://github.com/abdthr/cloudsweep/actions/workflows/tests.yml/badge.svg)](https://github.com/abdthr/cloudsweep/actions/workflows/tests.yml)
3
+
4
+ Find forgotten AWS resources that are costing you money.
5
+
6
+ You delete an EC2 instance, but its disk stays behind. It's attached to nothing,
7
+ nobody remembers it exists and it shows up on your bill every month. Cloudsweep
8
+ finds that kind of leftover and tells you roughly what it's costing you.
9
+
10
+ ```
11
+ $ cloudsweep scan --all-regions
12
+ ...
13
+ ┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
14
+ ┃ Region ┃ Resource ┃ ID ┃ Details ┃ Monthly cost ┃
15
+ ┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
16
+ │ us-east-1 │ EBS volume │ vol-0a7c3f19e2b84d561 │ gp2, 500 GB │ $50.00 │
17
+ │ eu-north-1 │ EBS volume │ vol-0e01dd418b516f0ab │ gp3, 100 GB │ $8.00 │
18
+ │ us-east-1 │ Elastic IP │ eipalloc-07d4c1e9a2b3f5a68 │ 3.91.24.17 │ $3.65 │
19
+ └────────────┴────────────┴────────────────────────────┴─────────────┴──────────────┘
20
+ Potential savings: $61.65/month
21
+ ```
22
+
23
+ It can scan a single region or every region your account has enabled.
24
+
25
+ ## What it finds
26
+
27
+ | Resource | Why it costs money |
28
+ |---|---|
29
+ | Unattached EBS volumes | Disks are billed per GB every month, even when nothing uses them |
30
+ | Unused Elastic IPs | AWS charges for every public IPv4 address by the hour, attached or not |
31
+ | Log groups that never expire | CloudWatch keeps logs forever by default, and you pay for every GB stored |
32
+
33
+ ## How it behaves
34
+
35
+ Cloudsweep is read-only. It lists what it finds and leaves the decision to you,
36
+ because an "unused" volume might be someone's backup. If it can't price something,
37
+ it still shows it and marks the cost as `unknown` instead of hiding it.
38
+
39
+ If a region can't be scanned (for example because a policy blocks it), cloudsweep
40
+ skips it, tells you which ones it missed and carries on with the rest.
41
+
42
+ Costs are estimates based on approximate US prices, so treat them as a rough guide.
43
+
44
+ ## Usage
45
+
46
+ You'll need [uv](https://docs.astral.sh/uv/) and AWS credentials (for example from `aws login`).
47
+
48
+ ```bash
49
+ git clone https://github.com/abdthr/cloudsweep.git
50
+ cd cloudsweep
51
+ uv run cloudsweep scan # uses your default AWS region
52
+ uv run cloudsweep scan --region us-east-1
53
+ uv run cloudsweep scan --all-regions # every region enabled for your account
54
+ uv run cloudsweep scan --output json # machine-readable, for scripts
55
+ uv run cloudsweep --help
56
+ ```
57
+
58
+ It only needs read permissions: `ec2:DescribeVolumes`, `ec2:DescribeAddresses`,
59
+ `ec2:DescribeRegions` and `logs:DescribeLogGroups`.
60
+
61
+ ## Tests
62
+
63
+ The tests use [moto](https://github.com/getmoto/moto) to fake AWS, so they don't
64
+ need an account or cost anything.
65
+
66
+ ```bash
67
+ uv run pytest
68
+ ```
69
+
70
+ ## What's next
71
+
72
+ - Publish it so you can `pip install cloudsweep`
73
+
74
+ ## License
75
+
76
+ MIT
@@ -0,0 +1,44 @@
1
+ [project]
2
+ name = "cloudsweep-aws"
3
+ version = "1.0.0"
4
+ description = "Find forgotten AWS resources that are costing you money."
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ keywords = [
9
+ "aws",
10
+ "cost",
11
+ "cloud",
12
+ "cli",
13
+ "finops",
14
+ ]
15
+ requires-python = ">=3.12"
16
+ dependencies = [
17
+ "boto3[crt]>=1.43.118",
18
+ "rich>=15.0.0",
19
+ "typer>=0.27.3",
20
+ ]
21
+
22
+ [[project.authors]]
23
+ name = "Abdullah Tahir"
24
+ email = "157417306+abdthr@users.noreply.github.com"
25
+
26
+ [project.urls]
27
+ Homepage = "https://github.com/abdthr/cloudsweep"
28
+ Issues = "https://github.com/abdthr/cloudsweep/issues"
29
+
30
+ [project.scripts]
31
+ cloudsweep = "cloudsweep:app"
32
+
33
+ [build-system]
34
+ requires = ["uv_build>=0.12.21,<0.13.0"]
35
+ build-backend = "uv_build"
36
+
37
+ [tool.uv.build-backend]
38
+ module-name = "cloudsweep"
39
+
40
+ [dependency-groups]
41
+ dev = [
42
+ "moto[ec2]>=5.2.4",
43
+ "pytest>=9.1.1",
44
+ ]
@@ -0,0 +1,37 @@
1
+ [project]
2
+ name = "cloudsweep-aws"
3
+ version = "1.0.0"
4
+ description = "Find forgotten AWS resources that are costing you money."
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ keywords = ["aws", "cost", "cloud", "cli", "finops"]
9
+ authors = [
10
+ { name = "Abdullah Tahir", email = "157417306+abdthr@users.noreply.github.com" }
11
+ ]
12
+ requires-python = ">=3.12"
13
+ dependencies = [
14
+ "boto3[crt]>=1.43.118",
15
+ "rich>=15.0.0",
16
+ "typer>=0.27.3",
17
+ ]
18
+
19
+ [project.urls]
20
+ Homepage = "https://github.com/abdthr/cloudsweep"
21
+ Issues = "https://github.com/abdthr/cloudsweep/issues"
22
+
23
+ [project.scripts]
24
+ cloudsweep = "cloudsweep:app"
25
+
26
+ [build-system]
27
+ requires = ["uv_build>=0.12.21,<0.13.0"]
28
+ build-backend = "uv_build"
29
+
30
+ [tool.uv.build-backend]
31
+ module-name = "cloudsweep"
32
+
33
+ [dependency-groups]
34
+ dev = [
35
+ "moto[ec2]>=5.2.4",
36
+ "pytest>=9.1.1",
37
+ ]
@@ -0,0 +1,126 @@
1
+ import json
2
+ import sys
3
+ from importlib.metadata import version
4
+
5
+ import boto3
6
+ import typer
7
+ from botocore.exceptions import ClientError
8
+ from rich.console import Console
9
+ from rich.table import Table
10
+
11
+ from cloudsweep.ebs import find_unattached_volumes
12
+ from cloudsweep.eip import find_unused_elastic_ips
13
+ from cloudsweep.logs import find_log_groups_without_retention
14
+ from cloudsweep.regions import get_enabled_regions
15
+
16
+ app = typer.Typer(
17
+ help="Find forgotten AWS resources that are costing you money.",
18
+ no_args_is_help=True,
19
+ )
20
+
21
+
22
+ def cost_for_sorting(finding: dict) -> float:
23
+ """Unknown costs count as 0, so they end up at the bottom."""
24
+ if finding["monthly_cost"] is None:
25
+ return 0.0
26
+ return finding["monthly_cost"]
27
+
28
+
29
+ def print_message(text: str) -> None:
30
+ """Print progress and warnings to stderr, so they never mix with the results."""
31
+ print(text, file=sys.stderr)
32
+
33
+
34
+ def print_table(findings: list[dict]) -> None:
35
+ if not findings:
36
+ print("No forgotten resources found.")
37
+ return
38
+
39
+ table = Table()
40
+ table.add_column("Region")
41
+ table.add_column("Resource")
42
+ table.add_column("ID", no_wrap=True)
43
+ table.add_column("Details")
44
+ table.add_column("Monthly cost", justify="right")
45
+
46
+ total = 0.0
47
+ for f in findings:
48
+ cost = f["monthly_cost"]
49
+ cost_text = "unknown" if cost is None else f"${cost:.2f}"
50
+ table.add_row(f["region"], f["resource"], f["id"], f["details"], cost_text)
51
+ if cost is not None:
52
+ total += cost
53
+
54
+ Console().print(table)
55
+ print(f"Potential savings: ${total:.2f}/month")
56
+
57
+
58
+ def show_version(value: bool) -> None:
59
+ if value:
60
+ print(f"cloudsweep {version('cloudsweep-aws')}")
61
+ raise typer.Exit()
62
+
63
+
64
+ @app.callback()
65
+ def main(
66
+ version_flag: bool = typer.Option(
67
+ False, "--version", callback=show_version, is_eager=True, help="Show the version and exit."
68
+ ),
69
+ ) -> None:
70
+ pass
71
+
72
+
73
+ @app.command()
74
+ def scan(
75
+ region: str | None = typer.Option(
76
+ None, "--region", "-r", help="AWS region to scan. Defaults to your AWS CLI region."
77
+ ),
78
+ all_regions: bool = typer.Option(
79
+ False, "--all-regions", help="Scan every region enabled for your account."
80
+ ),
81
+ output: str = typer.Option(
82
+ "table", "--output", "-o", help="How to show the results: table or json."
83
+ ),
84
+ ) -> None:
85
+ """Scan for forgotten resources and estimate what they cost per month."""
86
+ if output not in ["table", "json"]:
87
+ print_message(f"Unknown output format '{output}'. Use table or json.")
88
+ raise typer.Exit(code=2)
89
+
90
+ if region is None:
91
+ region = boto3.Session().region_name
92
+ if region is None:
93
+ print_message("No region given. Use --region, or set one with: aws configure set region <region>")
94
+ raise typer.Exit(code=2)
95
+
96
+ if all_regions:
97
+ regions_to_scan = get_enabled_regions(region)
98
+ else:
99
+ regions_to_scan = [region]
100
+
101
+ findings = []
102
+ skipped = []
103
+ for r in regions_to_scan:
104
+ print_message(f"Scanning {r}...")
105
+ try:
106
+ for f in find_unattached_volumes(r):
107
+ findings.append(f)
108
+ for f in find_unused_elastic_ips(r):
109
+ findings.append(f)
110
+ for f in find_log_groups_without_retention(r):
111
+ findings.append(f)
112
+ except ClientError as error:
113
+ code = error.response["Error"]["Code"]
114
+ print_message(f" Skipped {r}: {code}")
115
+ skipped.append(r)
116
+
117
+ if skipped:
118
+ print_message(f"Warning: could not scan {len(skipped)} region(s): {', '.join(skipped)}")
119
+
120
+ findings = sorted(findings, key=cost_for_sorting, reverse=True)
121
+
122
+ if output == "json":
123
+ print(json.dumps(findings, indent=2))
124
+ else:
125
+ print_message("")
126
+ print_table(findings)
@@ -0,0 +1,38 @@
1
+ import boto3
2
+
3
+ EBS_PRICE_PER_GB = {
4
+ "gp3": 0.08,
5
+ "gp2": 0.10,
6
+ "io2": 0.125,
7
+ "st1": 0.045,
8
+ "sc1": 0.015,
9
+ }
10
+
11
+
12
+ def find_unattached_volumes(region: str) -> list[dict]:
13
+ ec2 = boto3.client("ec2", region_name=region)
14
+ paginator = ec2.get_paginator("describe_volumes")
15
+ findings = []
16
+
17
+ for page in paginator.paginate():
18
+ for volume in page["Volumes"]:
19
+ if volume["State"] != "available":
20
+ continue
21
+
22
+ price = EBS_PRICE_PER_GB.get(volume["VolumeType"])
23
+ if price is None:
24
+ monthly_cost = None
25
+ else:
26
+ monthly_cost = round(volume["Size"] * price, 2)
27
+
28
+ findings.append({
29
+ "resource": "EBS volume",
30
+ "id": volume["VolumeId"],
31
+ "region": region,
32
+ "details": f"{volume['VolumeType']}, {volume['Size']} GB",
33
+ "type": volume["VolumeType"],
34
+ "size_gb": volume["Size"],
35
+ "monthly_cost": monthly_cost,
36
+ })
37
+
38
+ return findings
@@ -0,0 +1,25 @@
1
+ import boto3
2
+
3
+ PUBLIC_IP_PRICE_PER_HOUR = 0.005
4
+ HOURS_PER_MONTH = 730
5
+
6
+
7
+ def find_unused_elastic_ips(region: str) -> list[dict]:
8
+ """Return Elastic IPs in a region that aren't attached to anything."""
9
+ ec2 = boto3.client("ec2", region_name=region)
10
+ response = ec2.describe_addresses()
11
+ findings = []
12
+
13
+ for address in response["Addresses"]:
14
+ if "AssociationId" in address:
15
+ continue
16
+
17
+ findings.append({
18
+ "resource": "Elastic IP",
19
+ "id": address["AllocationId"],
20
+ "region": region,
21
+ "details": address["PublicIp"],
22
+ "monthly_cost": round(PUBLIC_IP_PRICE_PER_HOUR * HOURS_PER_MONTH, 2),
23
+ })
24
+
25
+ return findings
@@ -0,0 +1,30 @@
1
+ import boto3
2
+
3
+ LOG_STORAGE_PRICE_PER_GB = 0.03
4
+ BYTES_PER_GB = 1024 * 1024 * 1024
5
+
6
+
7
+ def find_log_groups_without_retention(region: str) -> list[dict]:
8
+ """Return log groups that keep their logs forever and have data stored."""
9
+ logs = boto3.client("logs", region_name=region)
10
+ paginator = logs.get_paginator("describe_log_groups")
11
+ findings = []
12
+
13
+ for page in paginator.paginate():
14
+ for group in page["logGroups"]:
15
+ if "retentionInDays" in group:
16
+ continue
17
+ if group["storedBytes"] == 0:
18
+ continue
19
+
20
+ stored_gb = group["storedBytes"] / BYTES_PER_GB
21
+
22
+ findings.append({
23
+ "resource": "Log group",
24
+ "id": group["logGroupName"],
25
+ "region": region,
26
+ "details": f"{stored_gb:.2f} GB, never expires",
27
+ "monthly_cost": round(stored_gb * LOG_STORAGE_PRICE_PER_GB, 2),
28
+ })
29
+
30
+ return findings
@@ -0,0 +1,13 @@
1
+ import boto3
2
+
3
+
4
+ def get_enabled_regions(region: str) -> list[str]:
5
+ """Return the names of all regions enabled for this AWS account."""
6
+ ec2 = boto3.client("ec2", region_name=region)
7
+ response = ec2.describe_regions()
8
+
9
+ regions = []
10
+ for r in response["Regions"]:
11
+ regions.append(r["RegionName"])
12
+
13
+ return regions