Skip to content

Commit 26f7cd9

Browse files
committed
add include_s3_name to input
1 parent 5cb2f4a commit 26f7cd9

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,28 @@ A simple AWS Lambda function that downloads multiple files from S3 and creates a
1111
- **Progress Tracking**: Logs progress every 10,000 files processed
1212
- **KMS Encryption**: Supports server-side encryption with KMS keys
1313
- **Concurrent Downloads**: Configurable worker threads for parallel processing
14+
- **Flexible Path Structure**: Option to include or exclude S3 bucket names in zip paths
1415

1516
## Event Structure
1617

1718
```json
1819
{
1920
"input_s3_manifest_url": "s3://bucket/manifest.txt",
2021
"output_s3_url": "s3://bucket/archive.zip",
21-
"delete_source_files": false
22+
"delete_source_files": false,
23+
"include_s3_name": true
2224
}
2325
```
2426

27+
### Parameters
28+
29+
- `input_s3_manifest_url`: S3 URL to a text file containing a list of files to archive
30+
- `output_s3_url`: S3 URL where the final zip archive will be stored
31+
- `delete_source_files`: Whether to delete source files after successful archiving (default: false)
32+
- `include_s3_name`: Whether to include S3 bucket names in the zip archive paths (default: true)
33+
34+
When `include_s3_name` is `true`, files will be stored in the zip with paths like `bucket-name/path/to/file.txt`. When `false`, files will be stored with just their S3 key path like `path/to/file.txt`.
35+
2536
## Prerequisites
2637
(for building and just lambda deployment)
2738
- [Rust](https://rustup.rs/) (rustup)

events/compress-event.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"input_s3_manifest_url": "s3://s3-log-compressor-sourcebucket-rkeoqdxsxu2w/example_manifest.txt",
33
"output_s3_url": "s3://s3-log-compressor-targetbucket-rigrlmvweehm/compressed/archive.zip",
4-
"delete_source_files": false
4+
"delete_source_files": false,
5+
"include_s3_name": true
56
}

rust-compressor/src/main.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ async fn handle_zip_creation(client: &Client, event: &Value) -> Result<Value, Er
7373
.to_string();
7474

7575
let delete_source_files = event["delete_source_files"].as_bool().unwrap_or(false);
76+
77+
let include_s3_name = event["include_s3_name"].as_bool().unwrap_or(true);
7678

7779
let (target_bucket, final_key) = parse_s3_url(&output_s3_url)?;
7880

@@ -84,7 +86,7 @@ async fn handle_zip_creation(client: &Client, event: &Value) -> Result<Value, Er
8486

8587
info!(
8688
input_s3_manifest_url,
87-
output_s3_url, delete_source_files, "Configuration"
89+
output_s3_url, delete_source_files, include_s3_name, "Configuration"
8890
);
8991

9092
// Create temporary directory for processing
@@ -119,7 +121,7 @@ async fn handle_zip_creation(client: &Client, event: &Value) -> Result<Value, Er
119121
// Step 4: Download files and create zip archive
120122
let start_zip = Instant::now();
121123
let downloaded_size =
122-
download_and_create_zip(client, &files_to_process, &tmp_dir, max_workers).await?;
124+
download_and_create_zip(client, &files_to_process, &tmp_dir, max_workers, include_s3_name).await?;
123125
let zip_duration = start_zip.elapsed();
124126
info!("Downloaded and zipped all files in {:.2?}", zip_duration);
125127

@@ -424,6 +426,7 @@ async fn download_and_create_zip(
424426
files_to_process: &[(String, String)],
425427
tmp_dir: &tempfile::TempDir,
426428
max_workers: usize,
429+
include_s3_name: bool,
427430
) -> Result<u64, Error> {
428431
// Create zip file in the temporary directory
429432
let zip_path = tmp_dir.path().join("archive.zip");
@@ -451,7 +454,11 @@ async fn download_and_create_zip(
451454
content.extend_from_slice(&bytes?);
452455
}
453456

454-
let zip_path = Path::new(&bucket).join(&key).to_str().unwrap().to_string();
457+
let zip_path = if include_s3_name {
458+
Path::new(&bucket).join(&key).to_str().unwrap().to_string()
459+
} else {
460+
key.clone()
461+
};
455462

456463
let mut size_guard = total_downloaded_size.lock().unwrap();
457464
*size_guard += content.len() as u64;

0 commit comments

Comments
 (0)