awsdeleter 0.1.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.
- awsdeleter-0.1.0/.gitignore +25 -0
- awsdeleter-0.1.0/LICENSE +22 -0
- awsdeleter-0.1.0/MANIFEST.in +19 -0
- awsdeleter-0.1.0/PKG-INFO +63 -0
- awsdeleter-0.1.0/README.md +37 -0
- awsdeleter-0.1.0/awsdeleter/__init__.py +0 -0
- awsdeleter-0.1.0/awsdeleter/__pycache__/__init__.cpython-313.pyc +0 -0
- awsdeleter-0.1.0/awsdeleter/__pycache__/awsdeleter.cpython-313.pyc +0 -0
- awsdeleter-0.1.0/awsdeleter/awsdeleter.py +131 -0
- awsdeleter-0.1.0/awsdeleter.egg-info/PKG-INFO +63 -0
- awsdeleter-0.1.0/awsdeleter.egg-info/SOURCES.txt +16 -0
- awsdeleter-0.1.0/awsdeleter.egg-info/dependency_links.txt +1 -0
- awsdeleter-0.1.0/awsdeleter.egg-info/entry_points.txt +2 -0
- awsdeleter-0.1.0/awsdeleter.egg-info/requires.txt +2 -0
- awsdeleter-0.1.0/awsdeleter.egg-info/top_level.txt +1 -0
- awsdeleter-0.1.0/pyproject.toml +3 -0
- awsdeleter-0.1.0/setup.cfg +4 -0
- awsdeleter-0.1.0/setup.py +30 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
*.pyc
|
|
3
|
+
*.pyo
|
|
4
|
+
*.pyd
|
|
5
|
+
__pycache__
|
|
6
|
+
env/
|
|
7
|
+
.venv/
|
|
8
|
+
*.egg-info/
|
|
9
|
+
*.dist-info/
|
|
10
|
+
|
|
11
|
+
# Distribution / packaging
|
|
12
|
+
build/
|
|
13
|
+
dist/
|
|
14
|
+
*.egg
|
|
15
|
+
*.tar.gz
|
|
16
|
+
|
|
17
|
+
# PyCharm (example for local IDE setups)
|
|
18
|
+
.idea/
|
|
19
|
+
|
|
20
|
+
# VS Code (example for local IDE setups)
|
|
21
|
+
.vscode/
|
|
22
|
+
|
|
23
|
+
# MacOS
|
|
24
|
+
.DS_Store
|
|
25
|
+
|
awsdeleter-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Omkar Khatavkar
|
|
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.
|
|
22
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Include the README file
|
|
2
|
+
include README.md
|
|
3
|
+
|
|
4
|
+
# Include the LICENSE file
|
|
5
|
+
include LICENSE
|
|
6
|
+
|
|
7
|
+
# Include .gitignore (optional)
|
|
8
|
+
include .gitignore
|
|
9
|
+
|
|
10
|
+
# Include setup.py (optional)
|
|
11
|
+
include setup.py
|
|
12
|
+
|
|
13
|
+
# Include all the source code
|
|
14
|
+
recursive-include awsdeleter *
|
|
15
|
+
|
|
16
|
+
# Include test files (if applicable)
|
|
17
|
+
recursive-include tests *
|
|
18
|
+
|
|
19
|
+
exclude __pycache__/*
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: awsdeleter
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A CLI tool to search and delete AWS EC2, S3, and VPC resources by prefix
|
|
5
|
+
Author: Omkar Khatavkar
|
|
6
|
+
Author-email: okhatavkar007@gmail.com
|
|
7
|
+
License: MIT
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: boto3
|
|
15
|
+
Requires-Dist: click
|
|
16
|
+
Dynamic: author
|
|
17
|
+
Dynamic: author-email
|
|
18
|
+
Dynamic: classifier
|
|
19
|
+
Dynamic: description
|
|
20
|
+
Dynamic: description-content-type
|
|
21
|
+
Dynamic: license
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
Dynamic: requires-dist
|
|
24
|
+
Dynamic: requires-python
|
|
25
|
+
Dynamic: summary
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# AWS Deleter
|
|
29
|
+
|
|
30
|
+
A CLI tool to delete AWS resources (EC2, S3, VPC) by prefix.
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
Install via pip:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install awsdeleter
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
Delete resources with a specified prefix:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
aws_deleter <prefix> --resource <resource_type> --confirm
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
- `<prefix>`: Resource name prefix to search for.
|
|
49
|
+
- `--resource`: Specify resource type (`ec2`, `s3`, `vpc`).
|
|
50
|
+
- `--confirm`: Delete without confirmation.
|
|
51
|
+
|
|
52
|
+
### Example
|
|
53
|
+
|
|
54
|
+
Delete EC2 instances starting with "test":
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
aws_deleter test --resource ec2 --confirm
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
MIT License. See [LICENSE](LICENSE).
|
|
63
|
+
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
|
|
2
|
+
# AWS Deleter
|
|
3
|
+
|
|
4
|
+
A CLI tool to delete AWS resources (EC2, S3, VPC) by prefix.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
Install via pip:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
pip install awsdeleter
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
Delete resources with a specified prefix:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
aws_deleter <prefix> --resource <resource_type> --confirm
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
- `<prefix>`: Resource name prefix to search for.
|
|
23
|
+
- `--resource`: Specify resource type (`ec2`, `s3`, `vpc`).
|
|
24
|
+
- `--confirm`: Delete without confirmation.
|
|
25
|
+
|
|
26
|
+
### Example
|
|
27
|
+
|
|
28
|
+
Delete EC2 instances starting with "test":
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
aws_deleter test --resource ec2 --confirm
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## License
|
|
35
|
+
|
|
36
|
+
MIT License. See [LICENSE](LICENSE).
|
|
37
|
+
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import click
|
|
2
|
+
import boto3
|
|
3
|
+
|
|
4
|
+
def search_resources_with_prefix(prefix, resource):
|
|
5
|
+
resources = []
|
|
6
|
+
|
|
7
|
+
ec2 = boto3.client('ec2')
|
|
8
|
+
s3 = boto3.client('s3')
|
|
9
|
+
if resource is None or resource =='':
|
|
10
|
+
resource = ['ec2', 's3', 'vpc']
|
|
11
|
+
else:
|
|
12
|
+
resource = [str(resource)]
|
|
13
|
+
# EC2 Instances
|
|
14
|
+
if 'ec2' in resource:
|
|
15
|
+
instances = ec2.describe_instances()
|
|
16
|
+
for reservation in instances['Reservations']:
|
|
17
|
+
for instance in reservation['Instances']:
|
|
18
|
+
for tag in instance.get('Tags', []):
|
|
19
|
+
if tag['Key'] == 'Name' and tag['Value'].startswith(prefix):
|
|
20
|
+
resources.append({'Type': 'EC2 Instance', 'ID': instance['InstanceId'], 'Name': tag['Value']})
|
|
21
|
+
|
|
22
|
+
# S3 Buckets
|
|
23
|
+
if 's3' in resource:
|
|
24
|
+
buckets = s3.list_buckets()
|
|
25
|
+
for bucket in buckets['Buckets']:
|
|
26
|
+
if bucket['Name'].startswith(prefix):
|
|
27
|
+
resources.append({'Type': 'S3 Bucket', 'Name': bucket['Name']})
|
|
28
|
+
|
|
29
|
+
# VPCs
|
|
30
|
+
if 'vpc' in resource:
|
|
31
|
+
vpcs = ec2.describe_vpcs()
|
|
32
|
+
for vpc in vpcs['Vpcs']:
|
|
33
|
+
for tag in vpc.get('Tags', []):
|
|
34
|
+
if tag['Key'] == 'Name' and tag['Value'].startswith(prefix):
|
|
35
|
+
resources.append({'Type': 'VPC', 'ID': vpc['VpcId'], 'Name': tag['Value']})
|
|
36
|
+
|
|
37
|
+
return resources
|
|
38
|
+
|
|
39
|
+
def delete_vpc(vpc_id):
|
|
40
|
+
"""Delete VPC and its dependencies."""
|
|
41
|
+
ec2 = boto3.client('ec2')
|
|
42
|
+
|
|
43
|
+
click.echo(f"Deleting dependencies of VPC {vpc_id}...")
|
|
44
|
+
|
|
45
|
+
# Detach and delete Internet Gateways
|
|
46
|
+
igws = ec2.describe_internet_gateways(
|
|
47
|
+
Filters=[{'Name': 'attachment.vpc-id', 'Values': [vpc_id]}]
|
|
48
|
+
)['InternetGateways']
|
|
49
|
+
|
|
50
|
+
for igw in igws:
|
|
51
|
+
ec2.detach_internet_gateway(InternetGatewayId=igw['InternetGatewayId'], VpcId=vpc_id)
|
|
52
|
+
ec2.delete_internet_gateway(InternetGatewayId=igw['InternetGatewayId'])
|
|
53
|
+
click.echo(f"Deleted Internet Gateway {igw['InternetGatewayId']}.")
|
|
54
|
+
|
|
55
|
+
# Delete Subnets
|
|
56
|
+
subnets = ec2.describe_subnets(
|
|
57
|
+
Filters=[{'Name': 'vpc-id', 'Values': [vpc_id]}]
|
|
58
|
+
)['Subnets']
|
|
59
|
+
|
|
60
|
+
for subnet in subnets:
|
|
61
|
+
ec2.delete_subnet(SubnetId=subnet['SubnetId'])
|
|
62
|
+
click.echo(f"Deleted Subnet {subnet['SubnetId']}.")
|
|
63
|
+
|
|
64
|
+
# Delete Route Tables (excluding main)
|
|
65
|
+
route_tables = ec2.describe_route_tables(
|
|
66
|
+
Filters=[{'Name': 'vpc-id', 'Values': [vpc_id]}]
|
|
67
|
+
)['RouteTables']
|
|
68
|
+
|
|
69
|
+
for rtb in route_tables:
|
|
70
|
+
if not any(assoc.get('Main', False) for assoc in rtb.get('Associations', [])):
|
|
71
|
+
ec2.delete_route_table(RouteTableId=rtb['RouteTableId'])
|
|
72
|
+
click.echo(f"Deleted Route Table {rtb['RouteTableId']}.")
|
|
73
|
+
|
|
74
|
+
# Delete Security Groups (excluding default)
|
|
75
|
+
security_groups = ec2.describe_security_groups(
|
|
76
|
+
Filters=[{'Name': 'vpc-id', 'Values': [vpc_id]}]
|
|
77
|
+
)['SecurityGroups']
|
|
78
|
+
|
|
79
|
+
for sg in security_groups:
|
|
80
|
+
if sg['GroupName'] != 'default':
|
|
81
|
+
ec2.delete_security_group(GroupId=sg['GroupId'])
|
|
82
|
+
click.echo(f"Deleted Security Group {sg['GroupId']}.")
|
|
83
|
+
|
|
84
|
+
# Finally, delete the VPC
|
|
85
|
+
ec2.delete_vpc(VpcId=vpc_id)
|
|
86
|
+
click.echo(f"Deleted VPC {vpc_id}.")
|
|
87
|
+
|
|
88
|
+
def delete_resource(resource):
|
|
89
|
+
"""Delete EC2 instance, S3 bucket, or VPC."""
|
|
90
|
+
ec2 = boto3.client('ec2')
|
|
91
|
+
s3 = boto3.client('s3')
|
|
92
|
+
|
|
93
|
+
if resource['Type'] == 'EC2 Instance':
|
|
94
|
+
ec2.terminate_instances(InstanceIds=[resource['ID']])
|
|
95
|
+
click.echo(f"EC2 Instance {resource['ID']} has been terminated.")
|
|
96
|
+
|
|
97
|
+
elif resource['Type'] == 'S3 Bucket':
|
|
98
|
+
objects = s3.list_objects_v2(Bucket=resource['Name'])
|
|
99
|
+
if 'Contents' in objects:
|
|
100
|
+
for obj in objects['Contents']:
|
|
101
|
+
s3.delete_object(Bucket=resource['Name'], Key=obj['Key'])
|
|
102
|
+
s3.delete_bucket(Bucket=resource['Name'])
|
|
103
|
+
click.echo(f"S3 Bucket {resource['Name']} has been deleted.")
|
|
104
|
+
|
|
105
|
+
elif resource['Type'] == 'VPC':
|
|
106
|
+
delete_vpc(resource['ID'])
|
|
107
|
+
|
|
108
|
+
@click.command()
|
|
109
|
+
@click.argument('prefix')
|
|
110
|
+
@click.option('--resource', default=None, help="Enter the resoruce type wanted to delete e.g. --resource=vpc or ec2 or s3")
|
|
111
|
+
@click.option('--confirm', default=False, help="Enter boolean to delete without getting the confirm popup")
|
|
112
|
+
def main(prefix, resource, confirm):
|
|
113
|
+
results = search_resources_with_prefix(prefix, resource)
|
|
114
|
+
delete_confirm = None
|
|
115
|
+
if results:
|
|
116
|
+
click.echo(f"Resources found with prefix '{prefix}':")
|
|
117
|
+
for resource in results:
|
|
118
|
+
click.echo(f"Type: {resource['Type']}, ID/Name: {resource.get('ID', resource['Name'])}")
|
|
119
|
+
if confirm:
|
|
120
|
+
delete_confirm = 'yes'
|
|
121
|
+
else:
|
|
122
|
+
delete_confirm = click.prompt(f"Do you want to delete this resource (ID/Name: {resource.get('ID', resource['Name'])})? (yes/y to confirm)")
|
|
123
|
+
if delete_confirm.lower() in ['yes', 'y']:
|
|
124
|
+
delete_resource(resource)
|
|
125
|
+
else:
|
|
126
|
+
click.echo(f"Resource {resource.get('ID', resource['Name'])} has not been deleted.")
|
|
127
|
+
else:
|
|
128
|
+
click.echo(f"No resources found with prefix '{prefix}'.")
|
|
129
|
+
|
|
130
|
+
if __name__ == "__main__":
|
|
131
|
+
main()
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: awsdeleter
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A CLI tool to search and delete AWS EC2, S3, and VPC resources by prefix
|
|
5
|
+
Author: Omkar Khatavkar
|
|
6
|
+
Author-email: okhatavkar007@gmail.com
|
|
7
|
+
License: MIT
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: boto3
|
|
15
|
+
Requires-Dist: click
|
|
16
|
+
Dynamic: author
|
|
17
|
+
Dynamic: author-email
|
|
18
|
+
Dynamic: classifier
|
|
19
|
+
Dynamic: description
|
|
20
|
+
Dynamic: description-content-type
|
|
21
|
+
Dynamic: license
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
Dynamic: requires-dist
|
|
24
|
+
Dynamic: requires-python
|
|
25
|
+
Dynamic: summary
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# AWS Deleter
|
|
29
|
+
|
|
30
|
+
A CLI tool to delete AWS resources (EC2, S3, VPC) by prefix.
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
Install via pip:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install awsdeleter
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
Delete resources with a specified prefix:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
aws_deleter <prefix> --resource <resource_type> --confirm
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
- `<prefix>`: Resource name prefix to search for.
|
|
49
|
+
- `--resource`: Specify resource type (`ec2`, `s3`, `vpc`).
|
|
50
|
+
- `--confirm`: Delete without confirmation.
|
|
51
|
+
|
|
52
|
+
### Example
|
|
53
|
+
|
|
54
|
+
Delete EC2 instances starting with "test":
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
aws_deleter test --resource ec2 --confirm
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
MIT License. See [LICENSE](LICENSE).
|
|
63
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
.gitignore
|
|
2
|
+
LICENSE
|
|
3
|
+
MANIFEST.in
|
|
4
|
+
README.md
|
|
5
|
+
pyproject.toml
|
|
6
|
+
setup.py
|
|
7
|
+
awsdeleter/__init__.py
|
|
8
|
+
awsdeleter/awsdeleter.py
|
|
9
|
+
awsdeleter.egg-info/PKG-INFO
|
|
10
|
+
awsdeleter.egg-info/SOURCES.txt
|
|
11
|
+
awsdeleter.egg-info/dependency_links.txt
|
|
12
|
+
awsdeleter.egg-info/entry_points.txt
|
|
13
|
+
awsdeleter.egg-info/requires.txt
|
|
14
|
+
awsdeleter.egg-info/top_level.txt
|
|
15
|
+
awsdeleter/__pycache__/__init__.cpython-313.pyc
|
|
16
|
+
awsdeleter/__pycache__/awsdeleter.cpython-313.pyc
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
awsdeleter
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
|
|
3
|
+
setup(
|
|
4
|
+
name='awsdeleter',
|
|
5
|
+
version='0.1.0',
|
|
6
|
+
description='A CLI tool to search and delete AWS EC2, S3, and VPC resources by prefix',
|
|
7
|
+
author='Omkar Khatavkar',
|
|
8
|
+
author_email='okhatavkar007@gmail.com',
|
|
9
|
+
license='MIT',
|
|
10
|
+
packages=find_packages(exclude=["__pycache__"]),
|
|
11
|
+
install_requires=[
|
|
12
|
+
'boto3',
|
|
13
|
+
'click',
|
|
14
|
+
],
|
|
15
|
+
entry_points={
|
|
16
|
+
'console_scripts': [
|
|
17
|
+
'awsdeleter = awsdeleter.awsdeleter:main',
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
include_package_data=True,
|
|
21
|
+
long_description=open('README.md').read(),
|
|
22
|
+
long_description_content_type='text/markdown',
|
|
23
|
+
classifiers=[
|
|
24
|
+
'Programming Language :: Python :: 3',
|
|
25
|
+
'License :: OSI Approved :: MIT License',
|
|
26
|
+
'Operating System :: OS Independent',
|
|
27
|
+
],
|
|
28
|
+
python_requires='>=3.6',
|
|
29
|
+
)
|
|
30
|
+
|