← All posts

How to Automate Monthly S3 Zips with a Script

Updated 2026-10-21

Many teams produce a monthly archive — invoices, statements, backups, compliance bundles — and email the link to a handful of people. Doing that by hand is tedious and easy to forget. Automating it takes one small script and a scheduler.

The workflow

  1. Generate the files into a predictable prefix, e.g. my-bucket/statements/2026-10/.
  2. Start a zip job for that prefix.
  3. Wait for the result and send the signed link to the recipients.

A tiny shell script

#!/usr/bin/env bash
set -euo pipefail

BASE="https://api.s3zipper.com"
TOKEN=$(curl -s -X POST "$BASE/gentoken" \
  -d "userKey=$S3Z_KEY" -d "userSecret=$S3Z_SECRET" | jq -r .token)

MONTH=$(date -d "last month" +%Y-%m)
START=$(curl -s -X POST "$BASE/v1/zipstart" \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d "{\"awsKey\":\"$AWS_ACCESS_KEY_ID\",\"awsSecret\":\"$AWS_SECRET_ACCESS_KEY\",
       \"awsBucket\":\"my-bucket\",\"awsRegion\":\"us-east-1\",
       \"filePaths\":[\"my-bucket/statements/$MONTH\"],
       \"zipFileName\":\"statements-$MONTH.zip\",
       \"resultsEmail\":\"billing@example.com\"}")

echo "$START" > /tmp/zip-job.json

Passing resultsEmail means you do not have to poll at all: the API sends the link when the archive is ready.

Scheduling it

  • cron on a small VM — one line, runs forever.
  • GitHub Actions — a scheduled workflow with the script; secrets stored as repository secrets.
  • AWS EventBridge — schedule a small task that runs the same call.

Practical details

  • Make the job idempotent: rerunning for the same month should replace the archive, not duplicate it.
  • Keep expiry generous for emailed links (a week), and log when you sent it rather than the URL itself.
  • Alert on failure — check State is SUCCESS before assuming the email went out.

Try it on your own bucket

Create a free account and zip S3 files on the fly — no downloads, no local disk.

Create free account API docs

← All posts