Serverless · Freelance

Event-driven Call-Recording Transcoding and Transcription

S3-triggered Lambdas unzip batches of WAV recordings, transcode to MP3, transcribe, and write results to a relational database.

  • S3
  • Lambda
  • Elastic Transcoder
  • Amazon Transcribe
  • SNS
  • MySQL
  • Python / boto3

// Why this matters

An S3 event-driven audio transcoding and transcription pipeline is one of those jobs that looks like a script and turns into an operations burden. Someone drops a few hundred call recordings in a shared folder, someone else runs ffmpeg by hand, pastes files into a transcription console and tries to line the results up with a spreadsheet of call metadata. It works once, and then it is a weekly chore with a high error rate.

The business value is not the transcode itself but the linkage: each recording must end up as a compressed file and a transcript attached to the correct call record, so downstream teams can search what was said. That linkage is exactly what manual processing loses.

Doing this serverlessly means no idle capacity, natural parallelism per file, and a clean failure story, provided you design around Lambda limits (15 minute timeout, ephemeral disk, at-least-once events) rather than pretending it is a long-running server.

// The problem

Raw WAV recordings are large. Batches arrive as zip archives with a CSV manifest describing each call: identifiers, timestamps, participants and the file name. The manifest and the archive do not always agree, rows can be duplicated, and the manifest can land in the bucket slightly before or after the zip.

The processing steps have wildly different durations. Unzipping takes seconds, transcoding takes tens of seconds per file, transcription takes minutes. A single function that does everything in sequence will hit the Lambda timeout on any large batch, and a function that polls for job completion burns money while it waits.

S3 notifications are at-least-once, services are eventually consistent (a row inserted a moment ago may not be visible to the update that follows), and a partially processed batch that nobody notices is worse than a loudly failed one. The design has to be idempotent, retry-tolerant and noisy about failure.

// The solution

We split the work into two Lambda functions with a clear contract. The start function is triggered by the S3 upload of the archive (with prefix and suffix filters so only the intended objects trigger it). It loads the manifest, de-duplicates rows, extracts WAV files back to a temporary prefix, matches manifest rows to files, and creates one transcode job and one transcription job per file. Then it invokes the finish function asynchronously with maps of file to job id.

The finish function owns the database. On the hand-off invocation it inserts the call rows and transcript placeholder rows, recording the transcode and transcription job ids. Later, job-completion events (the transcoder publishes state changes to SNS; Transcribe completion arrives through EventBridge or an S3 notification on the JSON output) invoke the same function, which looks the row up by job id and fills in the MP3 location or the transcript text.

The key decision is correlating by job id instead of waiting. The start function never blocks on a job; the database row is the join point. This is why retry with backoff exists around the update: the completion event can beat the insert, so the updater retries until the row is visible.

Alternatives we rejected: Step Functions with a wait-and-poll loop (more states and cost than a simple event model needed for this scale, though it is a good choice if you need visual audit of each batch); a single long-running container task (idle cost, and ffmpeg per file parallelism is free in Lambda); and S3 Batch Operations (no manifest matching). If you build this today use MediaConvert instead of Elastic Transcoder, which is no longer available to new customers; the correlation design is identical.

How it flows flow1. S3 upload → 2. Manifest load → 3. Unzip → 4. Match → 5. Transcode → 6. Transcribe → 7. Hand-off → 8. DB insert → 9. Completion events → 10. Status01S3 upload02Manifest load03Unzip04Match05Transcode06Transcribe07 · GATEHand-off08DB insert09Completion events10Status
How it flows. End-to-end flow. Dashed pink nodes are gates: points where a human or a check must pass before the next stage runs.
  1. S3 uploadzip and CSV manifest trigger the start Lambda (prefix/suffix filtered)
  2. Manifest loadpolling with retry, then de-duplication
  3. UnzipWAV files extracted and written back to S3
  4. Matchmetadata rows associated with audio files
  5. Transcodeone job per file to MP3, 3 retries
  6. Transcribeone speech-to-text job per file, JSON to S3
  7. Hand-off gateasync invoke of the finish Lambda with job-id maps
  8. DB insertcall and transcript records written
  9. Completion eventsjob state updates the audio path and transcript, then cleans temporary JSON
  10. Statussuccess or error published to SNS
S3Start LambdaMedia servicesFinish LambdaDatabaseObjectCreated for the zipread manifest, extract WAV filesstart transcode and transcription jobsasync invoke with job-id mapsinsert call and transcript rowsjob state event (completed)update by job id, retry until row visible
One batch from upload to transcript. The start function fans out and exits; completion events finish the job.
IngressUpload bucketPrefix and suffix filterOrchestrationStart LambdaFinish LambdaMediaTranscoder or MediaConvertTranscribeStateRelational DBJob-id columnsSignallingSNS status topicCompletion events
Pipeline layers. Each layer has one reason to change.

// Before you start

  • An AWS account with permissions for S3, Lambda, Transcribe, MediaConvert or Elastic Transcoder, SNS, EventBridge and IAM.
  • Python 3.9+ with boto3; a MySQL-compatible database reachable from the Lambda VPC subnets.
  • A secrets store (Secrets Manager or SSM Parameter Store) for database credentials. Never put them in code or environment variables in plain text.
  • Familiarity with S3 event notification filters and Lambda asynchronous invocation semantics.
  • A small sample zip with three or four WAV files and a matching CSV for testing.

// Step-by-step implementation

  1. 01 Provision buckets, topic and the S3 trigger

    Use one bucket with distinct prefixes: an inbox for uploads, a temp prefix for extracted WAV files, and an output prefix for MP3 and transcripts. Restrict the notification by prefix and suffix so only archives in the inbox start a run; otherwise your own writes to the temp prefix retrigger the function and you create a recursion bill.

  2. 02 Load the manifest with retry and de-duplicate it

    The manifest can arrive a moment after the archive, and S3 reads right after a write elsewhere can lag in cross-service flows. Poll for it with a bounded retry rather than failing immediately. Then de-duplicate rows by a stable key (we used the audio file name) so a re-uploaded batch cannot create duplicate calls.

  3. 03 Unzip into a temp prefix and match files to rows

    Stream each member out of the archive and write it back to S3 under the temp prefix, never to local disk if you can avoid it. After extraction, build a dictionary from manifest row to S3 key. Files with no row and rows with no file are both reported (not silently skipped), because they usually mean a truncated upload.

  4. 04 Create transcode and transcription jobs with retries

    One job per file, started in a loop. Transcribe job names must be unique, so use a UUID rather than a timestamp: two files started in the same millisecond collide with a timestamp. Wrap each creation in a small retry with exponential backoff, since the service can throttle at batch scale, and record failures per file instead of aborting the batch.

    Bitrate is an input, not a constant: expose a preset map so operators can trade size for fidelity without a code change.

  5. 05 Hand off to the finish Lambda asynchronously

    After all jobs are created, the start function sends the correlation maps (file key to transcode id, file key to transcription id, and the matched manifest rows) to the finish function using the Event invocation type. Lambda queues it and returns 202 immediately, so the start function exits well before its own timeout. If the hand-off itself fails, publish an error to SNS because the jobs are now running with no database rows to receive them.

  6. 06 Insert rows first, then update them from completion events

    The finish function has two modes selected by a "kind" field or by the event source. In batch-created mode it inserts one call row and one transcript row per file with the job ids stored. In completion mode it receives either a transcoder state notification (SNS) or a Transcribe job state change (EventBridge) and updates the row whose job id matches.

    Because a completion event can arrive before the insert is visible, the update retries until it affects a row, with a bounded number of attempts. Use parameterised statements throughout, and fetch credentials from your secrets store on cold start, never from source.

  7. 07 Subscribe the completion events and clean up temporary files

    Wire the transcoder topic (or an EventBridge rule on MediaConvert job state change) and an EventBridge rule on Transcribe job state change to the finish function. When a transcript finishes, read the JSON from S3, extract the transcript text, update the database, then delete the temporary JSON so the output prefix does not grow forever.

  8. 08 Define the tables and test with a sample batch

    The schema only needs the job-id columns indexed, because every completion update is a lookup by job id. Without those indexes the retry loop does table scans. Test by uploading a small zip with a manifest that includes a deliberate duplicate row and one missing file, and confirm the status message lists both.

// How to verify it works

  • Upload the sample zip and manifest to the inbox prefix; the start function log should show manifest loaded, N files extracted and N jobs created.
  • aws transcribe list-transcription-jobs --status COMPLETED should show one job per recording within a few minutes.
  • Query SELECT COUNT(*) FROM calls WHERE audio_file IS NOT NULL and the transcripts table: both should reach the batch size.
  • Check the SNS status email: a clean batch says ok; the test batch with a duplicate and a missing file should list both under "needs attention".
  • Re-upload the same archive: the unique key must prevent duplicate call rows.

// Design decisions and trade-offs

  • Lambda-to-Lambda async invoke decouples long-running work.
  • Retry and backoff absorb eventual-consistency delays.
  • Job-id correlation tables instead of waiting on jobs.
  • Configurable bitrate presets.

// Pitfalls and lessons learned

  • Triggering on the whole bucket makes the function react to its own extracted files. Always filter notifications by prefix and suffix.
  • Using a timestamp as the transcription job name causes collisions inside one loop; use a UUID.
  • Completion events can beat the database insert. Retry updates, or delay events through a queue.
  • Unbounded retries burn Lambda minutes. Cap attempts and publish a failure when exhausted.
  • Writing temp files to /tmp without sizing ephemeral storage fails oddly on big archives.
  • Leaving transcript JSON in the output prefix forever creates a silent storage cost; delete after ingest.
  • Credentials in function code or plain environment variables will leak through logs and zips. Use a secrets store.

// Frequently asked questions

How do I process a zip file uploaded to S3 with Lambda?

Trigger the function from the object-created event, read the object, iterate the zip members and write each back to S3. Mind memory and ephemeral storage, and stream for very large archives.

How do I run AWS Transcribe from Lambda without waiting?

Start the job and return. Subscribe to the Transcribe job state change event in EventBridge and handle the result in a separate invocation.

Why invoke the second Lambda asynchronously?

The Event invocation type returns immediately and queues the work, so the first function can finish within its timeout and long database work is decoupled.

Is Elastic Transcoder still a good choice?

For new builds use MediaConvert. The correlation-by-job-id design in this article works the same with either.

How do I keep a batch from being silently half-processed?

Publish a structured success or failure message to SNS at each stage, including unmatched files and duplicate rows. See Automated IAM Compromise Detection and Credential Revocation for another event-to-notification pattern.

// The outcome

Hands-off batch processing from upload to queryable transcripts.

// Where to take it next

// Keep reading