aws-inventory-manager 0.13.2__py3-none-any.whl

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.

Potentially problematic release.


This version of aws-inventory-manager might be problematic. Click here for more details.

Files changed (145) hide show
  1. aws_inventory_manager-0.13.2.dist-info/LICENSE +21 -0
  2. aws_inventory_manager-0.13.2.dist-info/METADATA +1226 -0
  3. aws_inventory_manager-0.13.2.dist-info/RECORD +145 -0
  4. aws_inventory_manager-0.13.2.dist-info/WHEEL +5 -0
  5. aws_inventory_manager-0.13.2.dist-info/entry_points.txt +2 -0
  6. aws_inventory_manager-0.13.2.dist-info/top_level.txt +1 -0
  7. src/__init__.py +3 -0
  8. src/aws/__init__.py +11 -0
  9. src/aws/client.py +128 -0
  10. src/aws/credentials.py +191 -0
  11. src/aws/rate_limiter.py +177 -0
  12. src/cli/__init__.py +12 -0
  13. src/cli/config.py +130 -0
  14. src/cli/main.py +3626 -0
  15. src/config_service/__init__.py +21 -0
  16. src/config_service/collector.py +346 -0
  17. src/config_service/detector.py +256 -0
  18. src/config_service/resource_type_mapping.py +328 -0
  19. src/cost/__init__.py +5 -0
  20. src/cost/analyzer.py +226 -0
  21. src/cost/explorer.py +209 -0
  22. src/cost/reporter.py +237 -0
  23. src/delta/__init__.py +5 -0
  24. src/delta/calculator.py +206 -0
  25. src/delta/differ.py +185 -0
  26. src/delta/formatters.py +272 -0
  27. src/delta/models.py +154 -0
  28. src/delta/reporter.py +234 -0
  29. src/models/__init__.py +21 -0
  30. src/models/config_diff.py +135 -0
  31. src/models/cost_report.py +87 -0
  32. src/models/deletion_operation.py +104 -0
  33. src/models/deletion_record.py +97 -0
  34. src/models/delta_report.py +122 -0
  35. src/models/efs_resource.py +80 -0
  36. src/models/elasticache_resource.py +90 -0
  37. src/models/group.py +318 -0
  38. src/models/inventory.py +133 -0
  39. src/models/protection_rule.py +123 -0
  40. src/models/report.py +288 -0
  41. src/models/resource.py +111 -0
  42. src/models/security_finding.py +102 -0
  43. src/models/snapshot.py +122 -0
  44. src/restore/__init__.py +20 -0
  45. src/restore/audit.py +175 -0
  46. src/restore/cleaner.py +461 -0
  47. src/restore/config.py +209 -0
  48. src/restore/deleter.py +976 -0
  49. src/restore/dependency.py +254 -0
  50. src/restore/safety.py +115 -0
  51. src/security/__init__.py +0 -0
  52. src/security/checks/__init__.py +0 -0
  53. src/security/checks/base.py +56 -0
  54. src/security/checks/ec2_checks.py +88 -0
  55. src/security/checks/elasticache_checks.py +149 -0
  56. src/security/checks/iam_checks.py +102 -0
  57. src/security/checks/rds_checks.py +140 -0
  58. src/security/checks/s3_checks.py +95 -0
  59. src/security/checks/secrets_checks.py +96 -0
  60. src/security/checks/sg_checks.py +142 -0
  61. src/security/cis_mapper.py +97 -0
  62. src/security/models.py +53 -0
  63. src/security/reporter.py +174 -0
  64. src/security/scanner.py +87 -0
  65. src/snapshot/__init__.py +6 -0
  66. src/snapshot/capturer.py +451 -0
  67. src/snapshot/filter.py +259 -0
  68. src/snapshot/inventory_storage.py +236 -0
  69. src/snapshot/report_formatter.py +250 -0
  70. src/snapshot/reporter.py +189 -0
  71. src/snapshot/resource_collectors/__init__.py +5 -0
  72. src/snapshot/resource_collectors/apigateway.py +140 -0
  73. src/snapshot/resource_collectors/backup.py +136 -0
  74. src/snapshot/resource_collectors/base.py +81 -0
  75. src/snapshot/resource_collectors/cloudformation.py +55 -0
  76. src/snapshot/resource_collectors/cloudwatch.py +109 -0
  77. src/snapshot/resource_collectors/codebuild.py +69 -0
  78. src/snapshot/resource_collectors/codepipeline.py +82 -0
  79. src/snapshot/resource_collectors/dynamodb.py +65 -0
  80. src/snapshot/resource_collectors/ec2.py +240 -0
  81. src/snapshot/resource_collectors/ecs.py +215 -0
  82. src/snapshot/resource_collectors/efs_collector.py +102 -0
  83. src/snapshot/resource_collectors/eks.py +200 -0
  84. src/snapshot/resource_collectors/elasticache_collector.py +79 -0
  85. src/snapshot/resource_collectors/elb.py +126 -0
  86. src/snapshot/resource_collectors/eventbridge.py +156 -0
  87. src/snapshot/resource_collectors/iam.py +188 -0
  88. src/snapshot/resource_collectors/kms.py +111 -0
  89. src/snapshot/resource_collectors/lambda_func.py +139 -0
  90. src/snapshot/resource_collectors/rds.py +109 -0
  91. src/snapshot/resource_collectors/route53.py +86 -0
  92. src/snapshot/resource_collectors/s3.py +105 -0
  93. src/snapshot/resource_collectors/secretsmanager.py +70 -0
  94. src/snapshot/resource_collectors/sns.py +68 -0
  95. src/snapshot/resource_collectors/sqs.py +82 -0
  96. src/snapshot/resource_collectors/ssm.py +160 -0
  97. src/snapshot/resource_collectors/stepfunctions.py +74 -0
  98. src/snapshot/resource_collectors/vpcendpoints.py +79 -0
  99. src/snapshot/resource_collectors/waf.py +159 -0
  100. src/snapshot/storage.py +351 -0
  101. src/storage/__init__.py +21 -0
  102. src/storage/audit_store.py +419 -0
  103. src/storage/database.py +294 -0
  104. src/storage/group_store.py +749 -0
  105. src/storage/inventory_store.py +320 -0
  106. src/storage/resource_store.py +413 -0
  107. src/storage/schema.py +288 -0
  108. src/storage/snapshot_store.py +346 -0
  109. src/utils/__init__.py +12 -0
  110. src/utils/export.py +305 -0
  111. src/utils/hash.py +60 -0
  112. src/utils/logging.py +63 -0
  113. src/utils/pagination.py +41 -0
  114. src/utils/paths.py +51 -0
  115. src/utils/progress.py +41 -0
  116. src/utils/unsupported_resources.py +306 -0
  117. src/web/__init__.py +5 -0
  118. src/web/app.py +97 -0
  119. src/web/dependencies.py +69 -0
  120. src/web/routes/__init__.py +1 -0
  121. src/web/routes/api/__init__.py +18 -0
  122. src/web/routes/api/charts.py +156 -0
  123. src/web/routes/api/cleanup.py +186 -0
  124. src/web/routes/api/filters.py +253 -0
  125. src/web/routes/api/groups.py +305 -0
  126. src/web/routes/api/inventories.py +80 -0
  127. src/web/routes/api/queries.py +202 -0
  128. src/web/routes/api/resources.py +379 -0
  129. src/web/routes/api/snapshots.py +314 -0
  130. src/web/routes/api/views.py +260 -0
  131. src/web/routes/pages.py +198 -0
  132. src/web/services/__init__.py +1 -0
  133. src/web/templates/base.html +949 -0
  134. src/web/templates/components/navbar.html +31 -0
  135. src/web/templates/components/sidebar.html +104 -0
  136. src/web/templates/pages/audit_logs.html +86 -0
  137. src/web/templates/pages/cleanup.html +279 -0
  138. src/web/templates/pages/dashboard.html +227 -0
  139. src/web/templates/pages/diff.html +175 -0
  140. src/web/templates/pages/error.html +30 -0
  141. src/web/templates/pages/groups.html +721 -0
  142. src/web/templates/pages/queries.html +246 -0
  143. src/web/templates/pages/resources.html +2251 -0
  144. src/web/templates/pages/snapshot_detail.html +271 -0
  145. src/web/templates/pages/snapshots.html +429 -0
@@ -0,0 +1,1226 @@
1
+ Metadata-Version: 2.2
2
+ Name: aws-inventory-manager
3
+ Version: 0.13.2
4
+ Summary: AWS Resource Inventory Management & Delta Tracking CLI tool
5
+ Author-email: Troy Larson <troy@calvinware.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/troylar/aws-inventory-manager
8
+ Project-URL: Documentation, https://github.com/troylar/aws-inventory-manager#readme
9
+ Project-URL: Repository, https://github.com/troylar/aws-inventory-manager
10
+ Project-URL: Issues, https://github.com/troylar/aws-inventory-manager/issues
11
+ Keywords: aws,cloud,infrastructure,snapshot,audit,cost-tracking,inventory
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: System Administrators
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: System :: Systems Administration
23
+ Classifier: Topic :: Utilities
24
+ Requires-Python: >=3.8
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Requires-Dist: boto3>=1.28.0
28
+ Requires-Dist: typer>=0.9.0
29
+ Requires-Dist: rich>=13.0.0
30
+ Requires-Dist: pyyaml>=6.0
31
+ Requires-Dist: python-dateutil>=2.8.0
32
+ Provides-Extra: dev
33
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
34
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
35
+ Requires-Dist: pytest-mock>=3.12.0; extra == "dev"
36
+ Requires-Dist: black>=23.0.0; extra == "dev"
37
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
38
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
39
+ Requires-Dist: types-PyYAML>=6.0.0; extra == "dev"
40
+ Requires-Dist: invoke>=2.0.0; extra == "dev"
41
+ Provides-Extra: web
42
+ Requires-Dist: fastapi>=0.109.0; extra == "web"
43
+ Requires-Dist: uvicorn[standard]>=0.27.0; extra == "web"
44
+ Requires-Dist: jinja2>=3.1.0; extra == "web"
45
+ Requires-Dist: python-multipart>=0.0.6; extra == "web"
46
+
47
+ <div align="center">
48
+
49
+ # AWS Inventory Manager
50
+
51
+ ### *Snapshot, Track, Secure, and Clean Up Your AWS Environment*
52
+
53
+ [![CI](https://github.com/troylar/aws-inventory-manager/actions/workflows/ci.yml/badge.svg)](https://github.com/troylar/aws-inventory-manager/actions/workflows/ci.yml)
54
+ [![Coverage](https://codecov.io/gh/troylar/aws-inventory-manager/branch/main/graph/badge.svg)](https://codecov.io/gh/troylar/aws-inventory-manager)
55
+ [![PyPI version](https://img.shields.io/pypi/v/aws-inventory-manager.svg)](https://pypi.org/project/aws-inventory-manager/)
56
+ [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
57
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
58
+
59
+ **Inventory Snapshots** • **Configuration Drift** • **Security Scanning** • **Cost Analysis** • **Resource Cleanup**
60
+
61
+ [Quick Start](#quick-start) • [Features](#features) • [AWS Config](#aws-config-integration) • [Documentation](#documentation)
62
+
63
+ </div>
64
+
65
+ ---
66
+
67
+ ## What It Does
68
+
69
+ AWS Inventory Manager captures a **point-in-time inventory** of your AWS resources, then helps you track changes, find security issues, and clean up unwanted resources.
70
+
71
+ > **Note:** "Snapshot" in this tool means an *inventory snapshot* (a catalog of what exists), not an AWS EBS or RDS snapshot. No AWS snapshots are created.
72
+
73
+ ```bash
74
+ # Capture your current resource inventory
75
+ awsinv snapshot create my-baseline --regions us-east-1,us-west-2
76
+
77
+ # Track what changed since the baseline
78
+ awsinv delta --snapshot my-baseline --show-diff
79
+
80
+ # Find security issues
81
+ awsinv security scan --severity HIGH
82
+
83
+ # Remove resources created after the baseline
84
+ awsinv cleanup preview my-baseline # See what would be deleted
85
+ awsinv cleanup execute my-baseline --confirm # Execute cleanup
86
+ ```
87
+
88
+ ### Why You Need This
89
+
90
+ | Problem | Solution |
91
+ |---------|----------|
92
+ | "What changed in our account?" | Field-level configuration drift detection |
93
+ | "Are we following security best practices?" | Automated CIS Benchmark scanning |
94
+ | "Someone spun up a bunch of test resources" | Delete everything created after a baseline snapshot |
95
+ | "How much is each team spending?" | Per-inventory cost tracking with tag filtering |
96
+ | "I need to clean up a sandbox account" | Purge all resources except those with specific tags |
97
+
98
+ ---
99
+
100
+ ## Key Concepts
101
+
102
+ Before diving in, here's the terminology:
103
+
104
+ | Term | Meaning |
105
+ |------|---------|
106
+ | **Snapshot** | A point-in-time inventory of your AWS resources (stored in local SQLite database). Not an EBS/RDS snapshot. |
107
+ | **Inventory** | A named collection of snapshots. Use inventories to organize snapshots by environment, team, or purpose. |
108
+ | **Cleanup** | Delete resources that were created *after* a snapshot, returning to that baseline state. |
109
+ | **Purge** | Delete all resources *except* those matching protection rules (no snapshot comparison needed). |
110
+ | **Query** | Search and analyze resources across snapshots using SQL or built-in filters. |
111
+
112
+ ---
113
+
114
+ ## Features
115
+
116
+ <table>
117
+ <tr>
118
+ <td width="33%" valign="top">
119
+
120
+ ### Inventory Snapshots
121
+ - 27 AWS services, 80+ resource types
122
+ - Multi-region collection
123
+ - Tag-based filtering
124
+ - Export to JSON/CSV
125
+ - SQLite storage with SQL queries
126
+
127
+ </td>
128
+ <td width="33%" valign="top">
129
+
130
+ ### Change Tracking
131
+ - Field-level drift detection
132
+ - Before/after comparison
133
+ - Configuration + security changes
134
+ - Color-coded terminal output
135
+ - JSON export for CI/CD
136
+
137
+ </td>
138
+ <td width="33%" valign="top">
139
+
140
+ ### Security Scanning
141
+ - 12+ CIS-aligned checks
142
+ - CRITICAL/HIGH/MEDIUM/LOW severity
143
+ - Public S3 buckets, open ports
144
+ - IAM credential age
145
+ - Remediation guidance
146
+
147
+ </td>
148
+ </tr>
149
+ <tr>
150
+ <td width="33%" valign="top">
151
+
152
+ ### Cost Analysis
153
+ - Per-inventory cost tracking
154
+ - Date range filtering
155
+ - Service-level breakdown
156
+ - Tag-based attribution
157
+ - AWS Cost Explorer integration
158
+
159
+ </td>
160
+ <td width="33%" valign="top">
161
+
162
+ ### Resource Cleanup
163
+ - **Cleanup**: Return to a snapshot baseline
164
+ - **Purge**: Delete all except protected
165
+ - Preview mode (dry-run)
166
+ - Dependency-aware deletion
167
+ - 43 deletable resource types*
168
+
169
+ <sub>*Deletion requires service-specific logic; collection supports 80+ types, deletion supports 43.</sub>
170
+
171
+ </td>
172
+ <td width="33%" valign="top">
173
+
174
+ ### AWS Config Integration
175
+ - Automatic detection
176
+ - Up to 5x faster collection
177
+ - Hybrid fallback to direct API
178
+ - Per-resource source tracking
179
+ - Multi-account via Aggregators
180
+
181
+ </td>
182
+ </tr>
183
+ <tr>
184
+ <td width="33%" valign="top">
185
+
186
+ ### Query & Analysis
187
+ - Raw SQL queries on resources
188
+ - Search by type, region, tags
189
+ - Tag coverage analysis
190
+ - Cross-snapshot history
191
+ - Export to JSON/CSV
192
+
193
+ </td>
194
+ <td width="33%" valign="top">
195
+ </td>
196
+ <td width="33%" valign="top">
197
+ </td>
198
+ </tr>
199
+ </table>
200
+
201
+ ---
202
+
203
+ ## Prerequisites
204
+
205
+ Before installing, ensure you have:
206
+
207
+ - **Python 3.8+** (3.8, 3.9, 3.10, 3.11, 3.12, or 3.13)
208
+ - **AWS CLI configured** with credentials (`aws configure` or environment variables)
209
+ - **Sufficient IAM permissions** (see [IAM Permissions](#iam-permissions) below)
210
+
211
+ To verify your setup:
212
+ ```bash
213
+ python3 --version # Should be 3.8+ (use 'python' on some systems)
214
+ aws sts get-caller-identity # Should return your account info
215
+ ```
216
+
217
+ ---
218
+
219
+ ## Quick Start
220
+
221
+ ### Installation
222
+
223
+ ```bash
224
+ pip install aws-inventory-manager
225
+ ```
226
+
227
+ Or with pipx for isolated installation:
228
+ ```bash
229
+ pipx install aws-inventory-manager
230
+ ```
231
+
232
+ ### Your First Snapshot
233
+
234
+ ```bash
235
+ # 1. Capture current state (takes 30-60 seconds depending on resource count)
236
+ awsinv snapshot create my-baseline --regions us-east-1
237
+
238
+ # 2. View what was captured
239
+ awsinv snapshot report
240
+
241
+ # Output:
242
+ # ┌─────────────────────────────────────────┐
243
+ # │ Snapshot: my-baseline │
244
+ # │ Resources: 127 │
245
+ # │ Regions: us-east-1 │
246
+ # ├─────────────────────────────────────────┤
247
+ # │ EC2 Instances: 12 │
248
+ # │ S3 Buckets: 8 │
249
+ # │ Lambda Functions: 23 │
250
+ # │ IAM Roles: 45 │
251
+ # │ ... │
252
+ # └─────────────────────────────────────────┘
253
+ ```
254
+
255
+ ### Common Workflows
256
+
257
+ ```bash
258
+ # Track changes since baseline
259
+ awsinv delta --snapshot my-baseline --show-diff
260
+
261
+ # Find security issues
262
+ awsinv security scan
263
+
264
+ # Clean up resources created after baseline
265
+ awsinv cleanup preview my-baseline # Always preview first!
266
+ awsinv cleanup execute my-baseline --confirm
267
+
268
+ # Clean up a sandbox (keep only tagged resources)
269
+ awsinv cleanup purge --protect-tag "keep=true" --preview
270
+ awsinv cleanup purge --protect-tag "keep=true" --confirm
271
+ ```
272
+
273
+ ---
274
+ ## Environment Variables
275
+
276
+ You can configure most CLI options via environment variables, which is useful for CI/CD pipelines or setting personal defaults.
277
+
278
+ | Variable | Description | Equivalent Flag |
279
+ |----------|-------------|-----------------|
280
+ | `AWSINV_SNAPSHOT_ID` | Default snapshot name for queries | `--snapshot` |
281
+ | `AWSINV_INVENTORY_ID` | Default inventory name | `--inventory` |
282
+ | `AWSINV_REGION` | Comma-separated regions (e.g., `us-east-1,us-west-2`) | `--regions` |
283
+ | `AWSINV_PROFILE` | AWS CLI profile to use | `--profile` |
284
+ | `AWSINV_STORAGE_PATH` | Custom path for SQLite DB and logs | `--storage-path` |
285
+
286
+ Example:
287
+ ```bash
288
+ export AWSINV_INVENTORY_ID="prod-baseline"
289
+ export AWSINV_REGION="us-east-1"
290
+
291
+ # These commands will now use the exported values automatically
292
+ awsinv snapshot create daily-snap
293
+ awsinv delta --snapshot previous-snap
294
+ ```
295
+
296
+ ---
297
+
298
+ ## AWS Config Integration
299
+
300
+ When [AWS Config](https://aws.amazon.com/config/) is enabled, the tool automatically uses it for faster resource collection.
301
+
302
+ ### Why Use AWS Config?
303
+
304
+ | Method | 500 Resources | 2000 Resources |
305
+ |--------|---------------|----------------|
306
+ | Direct API calls | ~45 seconds | ~3 minutes |
307
+ | AWS Config | ~8 seconds | ~20 seconds |
308
+
309
+ AWS Config maintains an indexed inventory of your resources. Instead of calling 27 different AWS service APIs, we query Config's pre-built index.
310
+
311
+ ### How It Works
312
+
313
+ ```
314
+ For each region:
315
+ 1. Check if AWS Config is enabled and recording
316
+ 2. For each resource type:
317
+ ├─ Config supports it? → Query Config API (fast)
318
+ └─ Config doesn't support it? → Call service API directly (Route53, WAF, etc.)
319
+ 3. Merge results into unified snapshot
320
+ ```
321
+
322
+ **No configuration required.** The tool detects Config availability automatically and falls back gracefully.
323
+
324
+ ### Usage
325
+
326
+ ```bash
327
+ # Default behavior: Use Config when available (recommended)
328
+ awsinv snapshot create my-snapshot --regions us-east-1
329
+
330
+ # Force direct API only (skip Config, useful for debugging)
331
+ awsinv snapshot create my-snapshot --regions us-east-1 --no-config
332
+
333
+ # Multi-account via Config Aggregator
334
+ awsinv snapshot create org-snapshot --config-aggregator my-org-aggregator
335
+ ```
336
+
337
+ ### Source Tracking
338
+
339
+ Each resource records how it was collected:
340
+
341
+ ```yaml
342
+ resources:
343
+ - arn: "arn:aws:s3:::my-bucket"
344
+ type: "AWS::S3::Bucket"
345
+ name: "my-bucket"
346
+ source: "config" # Collected via AWS Config
347
+
348
+ - arn: "arn:aws:route53:::hostedzone/Z123"
349
+ type: "AWS::Route53::HostedZone"
350
+ name: "example.com"
351
+ source: "direct_api" # Config doesn't support Route53
352
+ ```
353
+
354
+ ### Requirements
355
+
356
+ To benefit from Config integration:
357
+
358
+ 1. **AWS Config enabled** in target region(s)
359
+ 2. **Configuration Recorder** actively recording
360
+ 3. **Resource types being recorded** (either "all supported types" or specific types)
361
+
362
+ If these aren't met, the tool falls back to direct API calls automatically.
363
+
364
+ ---
365
+
366
+ ## Data Storage
367
+
368
+ ### Where Snapshots Are Stored
369
+
370
+ By default, all data is stored locally in a SQLite database:
371
+
372
+ ```
373
+ ~/.snapshots/
374
+ ├── inventory.db # SQLite database (snapshots, resources, tags)
375
+ └── audit-logs/
376
+ └── cleanup/ # Cleanup operation audit logs
377
+ └── 2026-01-15_cleanup.yaml
378
+ ```
379
+
380
+ The SQLite database provides:
381
+ - **Fast queries**: Search across all snapshots with SQL
382
+ - **Tag analysis**: Normalized tags table for efficient filtering
383
+ - **Cross-snapshot history**: Track resources across multiple snapshots
384
+
385
+ ### Changing Storage Location
386
+
387
+ ```bash
388
+ # Via environment variable
389
+ export AWS_INVENTORY_STORAGE_PATH=/path/to/storage
390
+ awsinv snapshot create my-snapshot
391
+
392
+ # Via CLI flag
393
+ awsinv snapshot create my-snapshot --storage-path /path/to/storage
394
+ ```
395
+
396
+ ### Team Sharing
397
+
398
+ The SQLite database is a single portable file. To share across a team:
399
+
400
+ - Store `inventory.db` in a shared filesystem
401
+ - Sync via S3 or other cloud storage
402
+ - Use separate databases per environment/team
403
+
404
+ ### Database Schema & Power User Queries
405
+
406
+ For advanced usage, including the full SQLite schema and complex analytical SQL queries, please see [DATABASE.md](DATABASE.md).
407
+
408
+ ---
409
+
410
+ ## Multi-Account Support
411
+
412
+ ### Option 1: AWS Config Aggregator (Recommended)
413
+
414
+ If you have a [Config Aggregator](https://docs.aws.amazon.com/config/latest/developerguide/aggregate-data.html) set up (common with AWS Organizations):
415
+
416
+ ```bash
417
+ # Query all accounts via the aggregator
418
+ awsinv snapshot create org-wide --config-aggregator my-aggregator
419
+ ```
420
+
421
+ **Prerequisites:**
422
+ - Config Aggregator already configured in your management account
423
+ - See [Setting Up an Aggregator Using the Console](https://docs.aws.amazon.com/config/latest/developerguide/setup-aggregator-console.html)
424
+ - Appropriate IAM permissions to query the aggregator (see [IAM Permissions](#iam-permissions))
425
+
426
+ ### Option 2: Profile Switching
427
+
428
+ ```bash
429
+ # Snapshot each account separately
430
+ awsinv snapshot create account-dev --profile dev-account
431
+ awsinv snapshot create account-prod --profile prod-account
432
+ ```
433
+
434
+ ### Option 3: Cross-Account Roles
435
+
436
+ Configure your AWS CLI with cross-account role assumption, then use profiles as above.
437
+
438
+ ---
439
+
440
+ ## IAM Permissions
441
+
442
+ The tool requires different permissions depending on which features you use. Combine the policies below based on which features you need, or attach them as separate managed policies.
443
+
444
+ > **Tip:** Start with just "Snapshot Collection" permissions. Add others only when needed.
445
+
446
+ ### Snapshot Collection (Read-Only)
447
+
448
+ For basic snapshot collection, you need read access to the services you want to inventory. The easiest approach is to use the `ReadOnlyAccess` AWS managed policy, but here's a minimal custom policy:
449
+
450
+ ```json
451
+ {
452
+ "Version": "2012-10-17",
453
+ "Statement": [
454
+ {
455
+ "Sid": "SnapshotCollection",
456
+ "Effect": "Allow",
457
+ "Action": [
458
+ "ec2:Describe*",
459
+ "s3:GetBucket*",
460
+ "s3:ListAllMyBuckets",
461
+ "s3:ListBucket",
462
+ "lambda:List*",
463
+ "lambda:GetFunction*",
464
+ "iam:List*",
465
+ "iam:Get*",
466
+ "rds:Describe*",
467
+ "dynamodb:Describe*",
468
+ "dynamodb:List*",
469
+ "ecs:Describe*",
470
+ "ecs:List*",
471
+ "eks:Describe*",
472
+ "eks:List*",
473
+ "sns:List*",
474
+ "sns:GetTopicAttributes",
475
+ "sqs:List*",
476
+ "sqs:GetQueueAttributes",
477
+ "cloudwatch:Describe*",
478
+ "cloudwatch:List*",
479
+ "elasticloadbalancing:Describe*",
480
+ "route53:List*",
481
+ "route53:Get*",
482
+ "secretsmanager:List*",
483
+ "secretsmanager:DescribeSecret",
484
+ "kms:List*",
485
+ "kms:Describe*",
486
+ "apigateway:GET",
487
+ "events:List*",
488
+ "events:Describe*",
489
+ "states:List*",
490
+ "states:Describe*",
491
+ "codepipeline:List*",
492
+ "codepipeline:Get*",
493
+ "codebuild:List*",
494
+ "codebuild:BatchGet*",
495
+ "cloudformation:Describe*",
496
+ "cloudformation:List*",
497
+ "elasticache:Describe*",
498
+ "ssm:DescribeParameters",
499
+ "ssm:GetParameter*",
500
+ "backup:List*",
501
+ "backup:Describe*",
502
+ "efs:Describe*",
503
+ "wafv2:List*",
504
+ "wafv2:Get*"
505
+ ],
506
+ "Resource": "*"
507
+ }
508
+ ]
509
+ }
510
+ ```
511
+
512
+ ### AWS Config Integration (Optional)
513
+
514
+ If you want to use AWS Config for faster collection:
515
+
516
+ ```json
517
+ {
518
+ "Version": "2012-10-17",
519
+ "Statement": [
520
+ {
521
+ "Sid": "ConfigRead",
522
+ "Effect": "Allow",
523
+ "Action": [
524
+ "config:DescribeConfigurationRecorders",
525
+ "config:DescribeConfigurationRecorderStatus",
526
+ "config:GetDiscoveredResourceCounts",
527
+ "config:ListDiscoveredResources",
528
+ "config:BatchGetResourceConfig"
529
+ ],
530
+ "Resource": "*"
531
+ }
532
+ ]
533
+ }
534
+ ```
535
+
536
+ For Config Aggregators (multi-account):
537
+
538
+ ```json
539
+ {
540
+ "Version": "2012-10-17",
541
+ "Statement": [
542
+ {
543
+ "Sid": "ConfigAggregator",
544
+ "Effect": "Allow",
545
+ "Action": [
546
+ "config:DescribeConfigurationAggregators",
547
+ "config:SelectAggregateResourceConfig"
548
+ ],
549
+ "Resource": "*"
550
+ }
551
+ ]
552
+ }
553
+ ```
554
+
555
+ ### Cost Analysis
556
+
557
+ For the `awsinv cost` command:
558
+
559
+ ```json
560
+ {
561
+ "Version": "2012-10-17",
562
+ "Statement": [
563
+ {
564
+ "Sid": "CostExplorer",
565
+ "Effect": "Allow",
566
+ "Action": [
567
+ "ce:GetCostAndUsage",
568
+ "ce:GetCostForecast"
569
+ ],
570
+ "Resource": "*"
571
+ }
572
+ ]
573
+ }
574
+ ```
575
+
576
+ ### Resource Cleanup
577
+
578
+ ⚠️ **Warning:** These permissions allow resource deletion. Use with extreme caution.
579
+
580
+ ```json
581
+ {
582
+ "Version": "2012-10-17",
583
+ "Statement": [
584
+ {
585
+ "Sid": "ResourceCleanup",
586
+ "Effect": "Allow",
587
+ "Action": [
588
+ "ec2:TerminateInstances",
589
+ "ec2:DeleteVolume",
590
+ "ec2:DeleteVpc",
591
+ "ec2:DeleteSubnet",
592
+ "ec2:DeleteSecurityGroup",
593
+ "ec2:DeleteInternetGateway",
594
+ "ec2:DeleteNatGateway",
595
+ "ec2:DeleteRouteTable",
596
+ "ec2:DeleteVpcEndpoints",
597
+ "ec2:DetachInternetGateway",
598
+ "ec2:DisassociateRouteTable",
599
+ "ec2:ReleaseAddress",
600
+ "ec2:DeleteKeyPair",
601
+ "s3:DeleteBucket",
602
+ "s3:DeleteObject",
603
+ "s3:DeleteObjectVersion",
604
+ "lambda:DeleteFunction",
605
+ "iam:DeleteRole",
606
+ "iam:DeleteRolePolicy",
607
+ "iam:DetachRolePolicy",
608
+ "iam:DeleteUser",
609
+ "iam:DeleteUserPolicy",
610
+ "iam:DetachUserPolicy",
611
+ "iam:DeleteAccessKey",
612
+ "iam:DeleteLoginProfile",
613
+ "iam:DeactivateMFADevice",
614
+ "iam:DeletePolicy",
615
+ "rds:DeleteDBInstance",
616
+ "rds:DeleteDBCluster",
617
+ "dynamodb:DeleteTable",
618
+ "ecs:DeleteCluster",
619
+ "ecs:DeleteService",
620
+ "ecs:DeregisterTaskDefinition",
621
+ "eks:DeleteCluster",
622
+ "sns:DeleteTopic",
623
+ "sqs:DeleteQueue",
624
+ "cloudwatch:DeleteAlarms",
625
+ "elasticloadbalancing:DeleteLoadBalancer",
626
+ "elasticloadbalancing:DeleteTargetGroup",
627
+ "route53:DeleteHostedZone",
628
+ "route53:ChangeResourceRecordSets",
629
+ "secretsmanager:DeleteSecret",
630
+ "kms:ScheduleKeyDeletion",
631
+ "apigateway:DELETE",
632
+ "events:DeleteRule",
633
+ "events:RemoveTargets",
634
+ "states:DeleteStateMachine",
635
+ "codepipeline:DeletePipeline",
636
+ "codebuild:DeleteProject",
637
+ "cloudformation:DeleteStack",
638
+ "elasticache:DeleteCacheCluster",
639
+ "ssm:DeleteParameter",
640
+ "backup:DeleteBackupPlan",
641
+ "backup:DeleteBackupVault",
642
+ "backup:DeleteRecoveryPoint",
643
+ "efs:DeleteFileSystem",
644
+ "efs:DeleteMountTarget",
645
+ "wafv2:DeleteWebACL",
646
+ "wafv2:DeleteRuleGroup",
647
+ "wafv2:DisassociateWebACL"
648
+ ],
649
+ "Resource": "*"
650
+ }
651
+ ]
652
+ }
653
+ ```
654
+
655
+ **Recommendation:** For production accounts, use separate IAM roles for read-only operations (snapshots) and cleanup operations. Never give cleanup permissions to everyday users.
656
+
657
+ ---
658
+
659
+ ## Documentation
660
+
661
+ ### Resource Cleanup
662
+
663
+ The `cleanup` command has two modes:
664
+
665
+ **Execute Mode** - Delete resources created *after* a baseline snapshot:
666
+ ```bash
667
+ # Preview what would be deleted
668
+ awsinv cleanup preview my-baseline
669
+
670
+ # Execute (requires confirmation)
671
+ awsinv cleanup execute my-baseline --confirm
672
+ ```
673
+
674
+ **Purge Mode** - Delete *all* resources except those matching protection rules:
675
+ ```bash
676
+ # Preview what would be deleted (everything except keep=true tagged resources)
677
+ awsinv cleanup purge --protect-tag "keep=true" --preview
678
+
679
+ # Execute
680
+ awsinv cleanup purge --protect-tag "keep=true" --confirm
681
+ ```
682
+
683
+ > **Note:** `cleanup execute` compares to a snapshot and deletes newer resources. `cleanup purge` ignores snapshots and deletes everything except protected resources.
684
+
685
+ ### Protection Rules
686
+
687
+ Prevent accidental deletion of important resources:
688
+
689
+ ```bash
690
+ # Protect by tag (OR logic - any match protects)
691
+ awsinv cleanup preview my-snapshot --protect-tag "env=prod" --protect-tag "keep=true"
692
+
693
+ # Filter to specific resource type (only delete this type)
694
+ awsinv cleanup preview my-snapshot --type AWS::EC2::Instance
695
+
696
+ # Use a config file for complex rules
697
+ awsinv cleanup preview my-snapshot --config .awsinv-cleanup.yaml
698
+ ```
699
+
700
+ Example `.awsinv-cleanup.yaml`:
701
+ ```yaml
702
+ # Protection Rules Configuration
703
+ # Resources matching ANY rule are protected from deletion
704
+
705
+ protection:
706
+ # Tag-based protection (OR logic - any matching tag protects)
707
+ tags:
708
+ - key: env
709
+ value: prod # Protect production resources
710
+ - key: keep
711
+ value: "true" # Protect explicitly marked resources
712
+ - key: Owner
713
+ value: "*" # Protect anything with an Owner tag (any value)
714
+
715
+ # Type-based protection
716
+ types:
717
+ - AWS::IAM::Role # Never delete IAM roles
718
+ - AWS::IAM::User # Never delete IAM users
719
+ - AWS::S3::Bucket # Never delete S3 buckets
720
+
721
+ # Age-based protection
722
+ age_days_minimum: 7 # Keep resources older than 7 days
723
+ ```
724
+
725
+ **Config file schema:**
726
+ | Field | Type | Description |
727
+ |-------|------|-------------|
728
+ | `protection.tags[]` | Array | Tag key/value pairs. `value: "*"` matches any value. |
729
+ | `protection.types[]` | Array | Full resource type names (e.g., `AWS::EC2::Instance`) |
730
+ | `protection.age_days_minimum` | Integer | Protect resources older than N days |
731
+
732
+ ### Safety Features
733
+
734
+ - **Preview mode**: Always see what would happen before execution
735
+ - **Confirmation required**: `--confirm` flag mandatory for destructive operations
736
+ - **Dependency ordering**: Deletes in correct order (instances before VPCs, etc.)
737
+ - **Audit logging**: Every deletion logged to `~/.snapshots/audit-logs/`
738
+
739
+ ### Deletion Behavior Notes
740
+
741
+ Some resources have special deletion behavior:
742
+
743
+ | Resource | Behavior |
744
+ |----------|----------|
745
+ | **KMS Keys** | Scheduled for deletion (minimum 7-day wait, not immediate) |
746
+ | **S3 Buckets** | Automatically emptied before deletion (including versioned objects) |
747
+ | **IAM Roles** | Attached policies detached, instance profiles removed first |
748
+ | **Route53 Zones** | All records deleted except NS/SOA before zone deletion |
749
+
750
+ ---
751
+
752
+ ## Supported Resource Types
753
+
754
+ <details>
755
+ <summary><b>Full list of 80+ supported resource types</b></summary>
756
+
757
+ ### Compute
758
+ | Service | Resource Types |
759
+ |---------|---------------|
760
+ | EC2 | Instances, Volumes, VPCs, Subnets, Security Groups, ENIs, Internet Gateways, NAT Gateways, Route Tables, Key Pairs, Elastic IPs, VPC Endpoints |
761
+ | Lambda | Functions, Layers, Event Source Mappings |
762
+ | ECS | Clusters, Services, Task Definitions |
763
+ | EKS | Clusters, Node Groups, Fargate Profiles |
764
+
765
+ ### Storage
766
+ | Service | Resource Types |
767
+ |---------|---------------|
768
+ | S3 | Buckets (with policies, encryption, versioning config) |
769
+ | EBS | Volumes, Snapshots |
770
+ | EFS | File Systems, Mount Targets |
771
+
772
+ ### Database
773
+ | Service | Resource Types |
774
+ |---------|---------------|
775
+ | RDS | DB Instances, DB Clusters, DB Subnet Groups |
776
+ | DynamoDB | Tables |
777
+ | ElastiCache | Clusters, Replication Groups |
778
+
779
+ ### Networking
780
+ | Service | Resource Types |
781
+ |---------|---------------|
782
+ | ELB | Application Load Balancers, Network Load Balancers, Classic Load Balancers, Target Groups |
783
+ | Route53 | Hosted Zones, Record Sets |
784
+ | API Gateway | REST APIs, HTTP APIs, Stages |
785
+
786
+ ### Security & Identity
787
+ | Service | Resource Types |
788
+ |---------|---------------|
789
+ | IAM | Users, Roles, Groups, Policies, Instance Profiles |
790
+ | KMS | Keys, Aliases |
791
+ | Secrets Manager | Secrets |
792
+ | WAF | WebACLs, Rule Groups, IP Sets |
793
+
794
+ ### Management & Monitoring
795
+ | Service | Resource Types |
796
+ |---------|---------------|
797
+ | CloudWatch | Alarms, Log Groups, Dashboards |
798
+ | CloudFormation | Stacks |
799
+ | EventBridge | Rules, Event Buses |
800
+ | SSM | Parameters |
801
+
802
+ ### Developer Tools
803
+ | Service | Resource Types |
804
+ |---------|---------------|
805
+ | CodePipeline | Pipelines |
806
+ | CodeBuild | Projects |
807
+ | Step Functions | State Machines |
808
+
809
+ ### Messaging
810
+ | Service | Resource Types |
811
+ |---------|---------------|
812
+ | SNS | Topics, Subscriptions |
813
+ | SQS | Queues |
814
+
815
+ ### Backup
816
+ | Service | Resource Types |
817
+ |---------|---------------|
818
+ | AWS Backup | Backup Plans, Backup Vaults |
819
+
820
+ </details>
821
+
822
+ ---
823
+
824
+ ## Command Reference
825
+
826
+ ```bash
827
+ # ─────────────────────────────────────────────────────────────
828
+ # SNAPSHOTS
829
+ # ─────────────────────────────────────────────────────────────
830
+ awsinv snapshot create <name> --regions <region1,region2>
831
+ [--use-config/--no-config] # AWS Config usage (default: enabled)
832
+ [--config-aggregator <name>] # Config Aggregator for multi-account
833
+ [--resource-types <svc1,svc2>] # Filter services (e.g., ec2,s3,lambda)
834
+ [--include-tags <key=value>] # Only include tagged resources
835
+ [--inventory <name>] # Assign to inventory group
836
+
837
+ awsinv snapshot list # List all snapshots
838
+ awsinv snapshot report # Summary of current/specified snapshot
839
+ [--snapshot <name>]
840
+ [--detailed] # Show all resources
841
+ [--export <file.json|csv>]
842
+
843
+ # ─────────────────────────────────────────────────────────────
844
+ # ANALYSIS
845
+ # ─────────────────────────────────────────────────────────────
846
+ awsinv delta # Changes since active snapshot
847
+ [--snapshot <name>] # Compare to specific snapshot
848
+ [--show-diff] # Show field-level changes
849
+
850
+ awsinv security scan # Run security checks
851
+ [--severity <CRITICAL|HIGH|MEDIUM|LOW>]
852
+ [--export <file.json>]
853
+
854
+ awsinv cost # Cost analysis
855
+ [--start-date YYYY-MM-DD]
856
+ [--end-date YYYY-MM-DD]
857
+ [--show-services]
858
+
859
+ # ─────────────────────────────────────────────────────────────
860
+ # RESOURCE CLEANUP
861
+ # ─────────────────────────────────────────────────────────────
862
+ # Cleanup: Delete resources created AFTER a snapshot
863
+ awsinv cleanup preview <snapshot> # Dry-run (safe)
864
+ awsinv cleanup execute <snapshot> --confirm
865
+
866
+ # Purge: Delete ALL resources EXCEPT protected ones
867
+ awsinv cleanup purge --protect-tag <key=value> --preview
868
+ awsinv cleanup purge --protect-tag <key=value> --confirm
869
+
870
+ # Common options for both:
871
+ [--type <AWS::Service::Type>] # Filter by resource type
872
+ [--region <region>] # Filter by region
873
+ [--protect-tag <key=value>] # Protect matching resources (repeatable)
874
+ [--config <path>] # Protection rules file
875
+ [-y, --yes] # Skip interactive prompts
876
+
877
+ # ─────────────────────────────────────────────────────────────
878
+ # QUERY & ANALYSIS
879
+ # ─────────────────────────────────────────────────────────────
880
+ awsinv query sql "<SQL>" # Run raw SQL query
881
+ [--format table|json|csv]
882
+
883
+ awsinv query resources # Search resources
884
+ [--type <AWS::Service::Type>] # Filter by type
885
+ [--region <region>] # Filter by region
886
+ [--tag <Key=Value>] # Filter by tag
887
+ [--snapshot <name>] # Limit to snapshot
888
+ [--limit <n>] # Max results
889
+
890
+ awsinv query history <arn> # Resource history across snapshots
891
+
892
+ awsinv query stats # Resource statistics
893
+ [--snapshot <name>] # Specific snapshot
894
+ [--group-by type|region|service] # Grouping
895
+
896
+ awsinv query diff <snap1> <snap2> # Compare two snapshots
897
+ [--type <AWS::Service::Type>]
898
+
899
+ # Example queries:
900
+ awsinv query sql "SELECT resource_type, COUNT(*) FROM resources GROUP BY resource_type"
901
+ awsinv query resources --type "AWS::S3::Bucket" --tag "Environment=prod"
902
+ awsinv query stats --group-by region
903
+
904
+ # ─────────────────────────────────────────────────────────────
905
+ # GLOBAL OPTIONS
906
+ # ─────────────────────────────────────────────────────────────
907
+ --profile <aws-profile> # AWS CLI profile to use
908
+ --storage-path <path> # Custom storage location
909
+ --help # Show help for any command
910
+ ```
911
+
912
+ ---
913
+
914
+ ## Use Cases
915
+
916
+ ### Development Environment Reset
917
+
918
+ > ⚠️ **Warning:** Only use this in dedicated development/sandbox accounts. Never run cleanup commands in production without extensive testing and protection rules.
919
+
920
+ ```bash
921
+ # Morning: Capture clean state
922
+ awsinv snapshot create morning-baseline --regions us-east-1
923
+
924
+ # Evening: Clean up everything created during the day
925
+ awsinv cleanup preview morning-baseline # Always preview first!
926
+ awsinv cleanup execute morning-baseline --confirm
927
+ ```
928
+
929
+ ### Sandbox Account Cleanup
930
+
931
+ > ⚠️ **Warning:** Purge mode deletes ALL resources except protected ones. Triple-check your protection rules before executing.
932
+
933
+ ```bash
934
+ # Tag your permanent infrastructure with "baseline=true"
935
+ # Then periodically purge everything else
936
+
937
+ awsinv cleanup purge --protect-tag "baseline=true" --preview
938
+ # Review the preview output carefully!
939
+ awsinv cleanup purge --protect-tag "baseline=true" --confirm
940
+ ```
941
+
942
+ ### Pre/Post Deployment Comparison
943
+ ```bash
944
+ # Before deploy
945
+ awsinv snapshot create pre-deploy-v2.3 --regions us-east-1,us-west-2
946
+
947
+ # Deploy your changes...
948
+
949
+ # After deploy - see exactly what changed
950
+ awsinv delta --snapshot pre-deploy-v2.3 --show-diff
951
+ ```
952
+
953
+ ### Security Audit
954
+ ```bash
955
+ # Weekly security scan
956
+ awsinv snapshot create weekly-audit --regions us-east-1
957
+ awsinv security scan --export security-report-$(date +%Y%m%d).json
958
+ ```
959
+
960
+ ### Cost Attribution by Team
961
+ ```bash
962
+ # Snapshot resources per team
963
+ awsinv snapshot create team-platform --include-tags "team=platform"
964
+ awsinv snapshot create team-data --include-tags "team=data"
965
+
966
+ # Compare costs
967
+ awsinv cost --snapshot team-platform
968
+ awsinv cost --snapshot team-data
969
+ ```
970
+
971
+ ---
972
+
973
+ ## Architecture
974
+
975
+ ```
976
+ ┌──────────────────────────────────────────────────────────────┐
977
+ │ AWS Inventory Manager │
978
+ ├──────────────────────────────────────────────────────────────┤
979
+ │ │
980
+ │ CLI Commands │
981
+ │ ┌─────────┐ ┌─────────┐ ┌──────────┐ ┌──────┐ ┌─────────┐ │
982
+ │ │snapshot │ │ delta │ │ security │ │ cost │ │ cleanup │ │
983
+ │ └────┬────┘ └────┬────┘ └────┬─────┘ └──┬───┘ └────┬────┘ │
984
+ │ │ │ │ │ │ │
985
+ ├───────┴───────────┴───────────┴──────────┴──────────┴────────┤
986
+ │ │
987
+ │ Collection Layer │
988
+ │ ┌────────────────────────┐ ┌────────────────────────────┐ │
989
+ │ │ AWS Config API │ │ Direct Service APIs │ │
990
+ │ │ (auto-detected, fast) │ │ (fallback, 27 collectors) │ │
991
+ │ └────────────────────────┘ └────────────────────────────┘ │
992
+ │ │
993
+ ├──────────────────────────────────────────────────────────────┤
994
+ │ │
995
+ │ Analysis Engines │
996
+ │ • Configuration Differ (field-level change detection) │
997
+ │ • Security Scanner (CIS Benchmark checks) │
998
+ │ • Cost Analyzer (AWS Cost Explorer) │
999
+ │ • Dependency Resolver (deletion ordering) │
1000
+ │ │
1001
+ ├──────────────────────────────────────────────────────────────┤
1002
+ │ │
1003
+ │ Storage: ~/.snapshots/ │
1004
+ │ • inventory.db (SQLite: snapshots, resources, tags) │
1005
+ │ • audit-logs/**/*.yaml (cleanup operation logs) │
1006
+ │ │
1007
+ └──────────────────────────────────────────────────────────────┘
1008
+ ```
1009
+
1010
+ ---
1011
+
1012
+ ## Development
1013
+
1014
+ ```bash
1015
+ # Clone and install
1016
+ git clone https://github.com/troylar/aws-inventory-manager.git
1017
+ cd aws-inventory-manager
1018
+ pip install -e ".[dev]"
1019
+
1020
+ # Run tests
1021
+ invoke test # All tests with coverage
1022
+ invoke test-unit # Unit tests only (faster)
1023
+
1024
+ # Code quality
1025
+ invoke quality # Lint + typecheck
1026
+ invoke quality --fix # Auto-fix issues
1027
+
1028
+ # Build
1029
+ invoke build # Build distributable package
1030
+ ```
1031
+
1032
+ **Test Coverage:** 1550+ tests, 79% overall coverage. Cleanup module: 98%+ coverage.
1033
+
1034
+ ---
1035
+
1036
+ ## Troubleshooting
1037
+
1038
+ ### Common Issues
1039
+
1040
+ #### "AccessDenied" or "UnauthorizedOperation" errors
1041
+
1042
+ **Problem:** The tool returns permission errors during snapshot collection.
1043
+
1044
+ **Solution:** Ensure your IAM user/role has the required permissions. See [IAM Permissions](#iam-permissions) for the minimum required policies.
1045
+
1046
+ ```bash
1047
+ # Verify your current identity
1048
+ aws sts get-caller-identity
1049
+
1050
+ # Test if you have basic access
1051
+ aws ec2 describe-instances --region us-east-1
1052
+ ```
1053
+
1054
+ #### Snapshot takes a long time
1055
+
1056
+ **Problem:** Creating a snapshot takes several minutes.
1057
+
1058
+ **Solutions:**
1059
+ 1. **Enable AWS Config** for faster collection (up to 5x faster). The tool detects it automatically.
1060
+ 2. **Limit regions:** Only scan regions you use with `--regions us-east-1,us-west-2`
1061
+ 3. **Limit resource types:** Filter to specific services with `--resource-types ec2,s3,lambda`
1062
+
1063
+ ```bash
1064
+ # Faster: Only scan what you need
1065
+ awsinv snapshot create quick-snap --regions us-east-1 --resource-types ec2,lambda
1066
+ ```
1067
+
1068
+ #### "No resources found" in snapshot
1069
+
1070
+ **Problem:** Snapshot completes but shows 0 resources.
1071
+
1072
+ **Possible causes:**
1073
+ 1. **Wrong region:** You may be scanning a region with no resources. Check with `aws ec2 describe-instances --region <region>`
1074
+ 2. **Tag filtering:** If you used `--include-tags`, ensure resources have those tags
1075
+ 3. **Permission issues:** Some describe APIs may silently return empty results instead of errors
1076
+
1077
+ #### Config Aggregator not working
1078
+
1079
+ **Problem:** `--config-aggregator` flag doesn't return cross-account resources.
1080
+
1081
+ **Solutions:**
1082
+ 1. Verify the aggregator exists: `aws configservice describe-configuration-aggregators`
1083
+ 2. Ensure you have `config:SelectAggregateResourceConfig` permission
1084
+ 3. Check that source accounts are properly linked in the aggregator
1085
+ 4. Run from the aggregator's account/region (typically management account)
1086
+
1087
+ #### Cleanup preview shows unexpected resources
1088
+
1089
+ **Problem:** The cleanup preview shows resources you didn't expect to be deleted.
1090
+
1091
+ **Explanation:** Cleanup deletes resources that exist now but didn't exist in the snapshot. This includes:
1092
+ - Resources created after the snapshot
1093
+ - Resources in regions not included in the original snapshot
1094
+ - AWS-managed resources that get auto-created
1095
+
1096
+ **Solutions:**
1097
+ 1. Use `--protect-tag` to protect resources by tag
1098
+ 2. Use `--type` to limit to specific resource types
1099
+ 3. Create a more comprehensive baseline snapshot
1100
+
1101
+ #### Rate limiting / API throttling
1102
+
1103
+ **Problem:** Errors like "Rate exceeded" or "Throttling" during snapshot.
1104
+
1105
+ **Explanation:** The tool includes built-in retry logic with exponential backoff for AWS API rate limits. Most throttling is handled automatically.
1106
+
1107
+ **If you still see issues:**
1108
+ 1. Use `--no-config` to skip Config detection (reduces API calls)
1109
+ 2. Limit regions with `--regions`
1110
+ 3. Limit resource types with `--resource-types`
1111
+ 4. For very large accounts, consider running during off-peak hours
1112
+
1113
+ #### Large accounts (50k+ resources)
1114
+
1115
+ **Problem:** Scanning accounts with tens of thousands of resources.
1116
+
1117
+ **Considerations:**
1118
+ - **Memory:** Snapshot data is held in memory during collection; very large accounts may need 2-4GB RAM
1119
+ - **Database size:** SQLite database grows with resources but handles large datasets efficiently
1120
+ - **Time:** Direct API collection may take 10-15 minutes; AWS Config reduces this significantly
1121
+ - **Recommendation:** Use AWS Config + limit to specific regions/types for large accounts
1122
+
1123
+ ### Frequently Asked Questions
1124
+
1125
+ #### Q: Does this create actual AWS snapshots (EBS, RDS)?
1126
+
1127
+ **No.** "Snapshot" in this tool means an *inventory snapshot* — a catalog of what resources exist. It does not create EBS snapshots, RDS snapshots, or any AWS resources. All data is stored locally in a SQLite database.
1128
+
1129
+ #### Q: Is my AWS data sent anywhere?
1130
+
1131
+ **No.** All data stays local. The tool only makes read API calls to AWS (and delete calls if you use cleanup). All data is stored in a SQLite database at `~/.snapshots/inventory.db` on your local machine.
1132
+
1133
+ #### Q: Can I use this with AWS Organizations?
1134
+
1135
+ **Yes.** Use one of these approaches:
1136
+ 1. **Config Aggregator:** Query all accounts from your management account with `--config-aggregator`
1137
+ 2. **Profile switching:** Create snapshots per account using `--profile`
1138
+ 3. **Cross-account roles:** Configure role assumption in AWS CLI profiles
1139
+
1140
+ #### Q: What happens if AWS Config is only partially enabled?
1141
+
1142
+ The tool handles partial Config coverage gracefully:
1143
+ - **Region has Config:** Uses Config for supported types, direct API for others
1144
+ - **Region lacks Config:** Falls back to direct API for all types
1145
+ - **Type not recorded:** Falls back to direct API for that specific type
1146
+
1147
+ You can see which method was used per resource via the `source` field in snapshots.
1148
+
1149
+ #### Q: How do I undo a cleanup operation?
1150
+
1151
+ **You can't.** Deleted resources are permanently deleted. Always:
1152
+ 1. Use `cleanup preview` first
1153
+ 2. Review the output carefully
1154
+ 3. Consider creating a fresh snapshot before cleanup
1155
+ 4. Use `--protect-tag` to safeguard important resources
1156
+
1157
+ #### Q: Can I schedule automatic snapshots?
1158
+
1159
+ The tool itself doesn't include scheduling, but you can easily add it:
1160
+
1161
+ ```bash
1162
+ # Cron example (daily at midnight)
1163
+ 0 0 * * * /usr/local/bin/awsinv snapshot create daily-$(date +\%Y\%m\%d) --regions us-east-1
1164
+
1165
+ # Or use AWS EventBridge + Lambda to trigger from within AWS
1166
+ ```
1167
+
1168
+ #### Q: Where should I run this tool?
1169
+
1170
+ The tool works anywhere with Python and AWS credentials:
1171
+
1172
+ | Environment | Pros | Cons |
1173
+ |-------------|------|------|
1174
+ | **Local laptop** | Easy setup, interactive preview | Credentials on laptop, network latency |
1175
+ | **EC2 with instance role** | No credential management, low latency | Snapshots stored on instance (back up!) |
1176
+ | **CI/CD pipeline** | Automated, auditable | Credential setup, snapshot storage strategy needed |
1177
+ | **CloudShell** | Zero setup, in-browser | Session timeouts, ephemeral storage |
1178
+
1179
+ For team use, consider storing snapshots in a shared location (see [Data Storage](#data-storage)).
1180
+
1181
+ #### Q: Why does cleanup delete my VPC?
1182
+
1183
+ When you run cleanup execute against a baseline, the tool deletes resources created after that baseline. If the VPC was created after your snapshot, it will be marked for deletion.
1184
+
1185
+ **Best practice:** Always include networking infrastructure in your baseline snapshot, or protect it with tags:
1186
+
1187
+ ```bash
1188
+ awsinv cleanup execute my-baseline --protect-tag "layer=network" --confirm
1189
+ ```
1190
+
1191
+ ---
1192
+
1193
+ ## Contributing
1194
+
1195
+ 1. Fork the repository
1196
+ 2. Create a feature branch (`git checkout -b feature/my-feature`)
1197
+ 3. Run tests: `invoke test`
1198
+ 4. Run quality checks: `invoke quality`
1199
+ 5. Submit a pull request
1200
+
1201
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.
1202
+
1203
+ ---
1204
+
1205
+ ## License
1206
+
1207
+ MIT License - see [LICENSE](LICENSE)
1208
+
1209
+ ---
1210
+
1211
+ ## Support
1212
+
1213
+ - **Issues:** [GitHub Issues](https://github.com/troylar/aws-inventory-manager/issues)
1214
+ - **Discussions:** [GitHub Discussions](https://github.com/troylar/aws-inventory-manager/discussions)
1215
+
1216
+ ---
1217
+
1218
+ <div align="center">
1219
+
1220
+ **Built for AWS practitioners who need visibility and control**
1221
+
1222
+ [![Star on GitHub](https://img.shields.io/github/stars/troylar/aws-inventory-manager?style=social)](https://github.com/troylar/aws-inventory-manager)
1223
+
1224
+ Version 0.9.0 • Python 3.8 - 3.13
1225
+
1226
+ </div>