1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*!
# s3rm-rs
s3rm-rs is a fast Amazon S3 object deletion tool.
It can be used to delete objects from S3 buckets with powerful filtering,
safety features, and versioning support.
**NOTE: s3rm-rs library is assumed to be used like a way that you use s3rm-rs CLI. If you want to control more finely, instead of using s3rm-rs library, we recommend using AWS SDK for Rust or aws-s3-transfer-manager-rs(developer preview) directly.**
## Features
- **High Performance**: Parallel deletion using S3 batch API (up to 1000 objects per request)
with configurable worker pools (1–65,535 concurrent workers).
- **Flexible Filtering**: Regex patterns on keys/content-type/metadata/tags, size ranges,
time ranges, and Lua script-based custom filtering.
- **Safety First**: Dry-run mode, confirmation prompts, force flag, max-delete threshold.
- **Versioning Support**: Delete markers, all-versions deletion for versioned buckets.
- **Library-First**: All CLI features available as a Rust library for programmatic use.
- **s3sync Compatible**: Reuses s3sync's proven infrastructure (~90% code reuse).
## Architecture
s3rm-rs uses a streaming pipeline architecture:
```text
ObjectLister → [Filter Stages] → ObjectDeleter Workers (MPMC) → Terminator
```
All core functionality resides in this library crate. The CLI binary is a thin
wrapper that parses arguments, builds a [`Config`], and runs a [`DeletionPipeline`].
## Quick Start (Library Usage)
```toml
[dependencies]
s3rm-rs = "1"
tokio = { version = "1", features = ["full"] }
```
The easiest way is [`build_config_from_args`] — pass CLI-style arguments
and get a ready-to-run [`Config`]:
```no_run
use s3rm_rs::{build_config_from_args, DeletionPipeline, create_pipeline_cancellation_token};
#[tokio::main]
async fn main() {
// Same arguments you would pass to the s3rm CLI.
let config = build_config_from_args([
"s3rm",
"s3://my-bucket/logs/2024/",
"--dry-run",
"--force",
]).expect("invalid arguments");
let token = create_pipeline_cancellation_token();
let mut pipeline = DeletionPipeline::new(config, token).await;
// The pipeline sends real-time stats to a channel for progress reporting.
// Close the sender if you aren't reading from get_stats_receiver(),
// otherwise the channel fills up and the pipeline stalls.
pipeline.close_stats_sender();
pipeline.run().await;
// --- Error checking ---
if pipeline.has_error() {
if let Some(messages) = pipeline.get_error_messages() {
for msg in &messages {
eprintln!("Error: {msg}");
}
}
std::process::exit(1);
}
let stats = pipeline.get_deletion_stats();
println!("Deleted {} objects ({} bytes)",
stats.stats_deleted_objects, stats.stats_deleted_bytes);
}
```
You can also build a [`Config`] with [`Config::for_target`], but note that
**command-line validation checks are not performed** (e.g. conflicting flags,
rate-limit vs batch-size). Prefer [`build_config_from_args`] when possible:
```no_run
# use s3rm_rs::Config;
let mut config = Config::for_target("my-bucket", "logs/2024/");
config.dry_run = true; // preview without deleting
config.worker_size = 100; // more concurrent workers
config.max_delete = Some(5000); // stop after 5 000 deletions
```
## Lua Scripting
Lua filter and event callbacks can be registered via script paths in the [`Config`]:
```no_run
# let mut config: s3rm_rs::Config = todo!();
config.filter_callback_lua_script = Some("path/to/filter.lua".to_string());
config.event_callback_lua_script = Some("path/to/event.lua".to_string());
```
Lua scripts run in a sandboxed VM by default (no OS or I/O library access).
Use `allow_lua_os_library` and `allow_lua_unsafe_vm` on [`Config`] to relax restrictions.
For more information, see the [s3sync documentation](https://github.com/nidor1998/s3sync)
as s3rm-rs shares the same Lua integration.
**NOTE: Each type of callback is registered only once. Lua scripting support CLI arguments are disabled if you use custom callbacks.**
*/
// ---------------------------------------------------------------------------
// Module declarations
// ---------------------------------------------------------------------------
pub
pub
pub
pub
pub
pub
pub
pub
pub
pub
// ---------------------------------------------------------------------------
// Root-level re-exports for convenient access
// ---------------------------------------------------------------------------
// Core pipeline
pub use DeletionPipeline;
// Configuration
pub use Config;
pub use ;
// Statistics
pub use ;
// Object types
pub use ;
// Error types
pub use ;
/// Per-object deletion error returned when an individual object fails to delete.
pub use DeletionError;
/// Per-object deletion event emitted for each processed object (success or failure).
pub use DeletionEvent;
/// Outcome of a single object deletion attempt (success with metadata, or error).
pub use DeletionOutcome;
// Cancellation token
pub use ;
// Callback traits
pub use ;
pub use FilterCallback;
// Callback managers
pub use EventManager;
pub use FilterManager;