Skip to main content

Module cleanup

Module cleanup 

Source
Expand description

Phase 3: delete resources that --tag-session stamped during a session.

Discovery runs through AWS Resource Groups Tagging API, which is the canonical cross-service way to list resources by tag. We then dispatch per-service delete-* calls keyed off the ARN.

Credentials: this module shells out to the user’s aws CLI, which picks up ambient credentials (AWS_PROFILE, env vars, instance role, etc.). Cleanup runs OUTSIDE the expired session — by definition, the short-lived STS creds are already gone by the time the user asks to clean up.

Structs§

CleanupReport
Summary of a cleanup run.
CleanupState
On-disk record of an in-flight cleanup. Written before any deletion happens, updated after each attempt, removed once nothing is left.
CleanupStateStore
Manages cleanup state files keyed by session id.
DailyCostHint
Rough daily-cost hint for a single tagged resource, used in the pre-delete preview so users can see “oh wait, that’s a $40/day RDS instance”.
OrphanedSession
One stale-session entry: the session already ended (expired / completed / failed / revoked) but still has resources tagged tryaudex-session that are alive in the account.
TaggedResource
A single tagged resource returned by Resource Groups Tagging API.

Enums§

DeleteOutcome
The outcome of attempting to delete one resource.

Functions§

cleanup_session
Run delete() over every discovered resource and aggregate results.
delete
Attempt to delete a single resource. dry_run=true skips the actual call.
delete_command
Build the aws-CLI argv to delete this resource. None if unsupported.
delete_tier
Delete priority for dependency ordering. Lower tiers are leaf resources (nothing else in our set refers to them) and get deleted first. Higher tiers sit upstream and must be torn down only after their dependents.
discover
Query Resource Groups Tagging API for every resource bearing tryaudex-session=<session_id>. Returns the raw list (may be empty).
estimate_daily_cost
Look up a daily cost hint for the given resource, or None if it’s free / unknown. Prices are approximate us-east-1 list prices circa 2025 — precise to within “right order of magnitude”, nothing more.
estimate_daily_cost_total
Sum the known daily-cost floors across a set of resources. Returns (total_usd_per_day, any_usage_dependent).
find_orphans
Cross-reference the local session store with the tagging API to find every non-active session that still has billing resources. Each entry can be drained with tryaudex cleanup <session_id>.
sort_for_deletion
Stable-sort resources into delete order. Same-tier ordering is preserved from the caller’s input (discovery order).