app.start, behind an API Gateway HTTP API with a JWT authorizer, starts the job for a signed-in user and writes an item.app.webhook, on a Lambda Function URL, receives Importly’s signed webhook and fills in the item.app.sweep, on an EventBridge schedule, finishes any item whose webhook never arrived.
boto3, which the Lambda Python runtime already includes, so there’s nothing to package. Tested on Python 3.11 against a mocked DynamoDB (moto) and a mocked API.
1. The table and settings
Create a DynamoDB table namedtranscripts with the partition key job_id (string). Give the function’s role dynamodb:PutItem, UpdateItem and Scan on it.
Create your key on the API key page (it is shown once), and copy the Webhook signing secret (it starts with whsec_) from the same page. Set these environment variables on the function, or load them from Secrets Manager:
2. The handlers
save_job is shared: the webhook and the sweep both read the job from the status endpoint with your key, and a conditional update only writes an item that is still queued or running. A second delivery, or the sweep finding a job the webhook already saved, does nothing.
app.py
start sends "mode": "auto", which uses the video’s captions and falls back to speech-to-text when there are none. A rejected request (a bad link, a key problem, or a low balance) comes back with its HTTP status, an error and a code, and no item is written. See Error handling.
webhook checks the signature against the raw body. Function URLs and API Gateway can deliver it base64-encoded, so it decodes first when isBase64Encoded is set. It takes only the jobId from the payload and reads the result from the API with your key. Right after you rotate the signing secret, Importly sends two v1 signatures for 24 hours, and this check accepts either. See Webhooks.
segments is saved as a JSON string with start and end times in seconds, for captions, chapters or search. A job that fails later, for example because the video is private, is saved with status: "failed" and its error_code and error_message.
3. Wire it up
Create one function with the Python 3.11 runtime (or newer), uploadapp.py, and point three entry points at it:
- An API Gateway HTTP API route
POST /transcriptswith a JWT authorizer from your auth provider, integrated with a function whose handler isapp.start. - A function with handler
app.webhookand a Function URL with auth typeNONE. Set its URL asIMPORTLY_WEBHOOK_URL. The signature check is what keeps other callers out. - An EventBridge Scheduler schedule
rate(5 minutes)that invokes a function with handlerapp.sweep.
status and query it instead.
Your app calls the route with the user’s token and reads the item back (through your own API) until status is completed or failed.
Downloading the file instead
For the video or audio file itself, startPOST /import the same way and save mediaUrl from GET /import/status in save_job. That link is valid for 7 days, so store the file if your app needs it longer: with store: true, each import is copied to your own S3 bucket (recipe). Set includeVideo: false for audio only. See Downloads.
For a long-running Python server instead of Lambda, see Python (FastAPI), or Celery for task queues.
A transcript from captions costs $0.003. Speech-to-text for a video without captions is $0.01 per minute, and
maxCostDollars stops a long one before it’s charged. Try it free, no card required. See Pricing & credits.