Ignitify.dev
Tutorials

Launch event: stream and record

Stream a launch video live, and keep the recording in your own bucket. Two integrations write the settings, so you write only the task code.

nodeintegrationsbidirectionalffmpegabout 30 minPro tier

What this tutorial shows

  • Each integration shows a plan and changes nothing before you say yes.
  • A task with no network gets no open egress: egress_allow holds only the hosts that you add.
  • A value that conflicts is refused, never overwritten. The network type and the preset are only raised, and lists are joined.
  • A host that is different for each user is left for you to add ("you add").
  • task:validate finds a hand edit that breaks an integration, before you deploy.

What you build

A task for a product launch:

  1. It gives the viewer link in the run's progress, two minutes before the stream starts.
  2. It streams the launch video live. Viewers open the link in a browser.
  3. When the stream ends, it uploads the recording to your bucket and returns download links.

Two integrations write the settings for this: stream and s3-storage. You write the task code.

The journey

You run a product launch. You want a live video that people can watch in a browser, and a recording in your own bucket after the event. Without help, that is a lot of work that is not your product: a live encoder, a player, a web server, S3 request signing, and the right network and machine settings.

Integrations do that work for you. Each one is a tested package plus the settings it needs. You add it with one command, and you write only what is yours.

~20lines of task code that you write
~800lines of tested code that you do not write
7settings written for you by integration:add

Without integrations, you build

  • The ffmpeg command for live HLS, and a clean stop on cancel
  • A web server, a player page and a video player script
  • S3 request signing, uploads and expiring download links
  • The network, inbound route, machine size and packages, found by trial and error

With integrations, you write

ignitify integration:add stream
ignitify integration:add s3-storage

await stream(ctx, { source: video })
await store.putAndLink(file)

Two commands and two calls are the core of the task. The full code is in step 5.

The motion shows the stream part of this task from start to end: write it, deploy it, start a run, watch it live, and the clean-up.

Write a task with the stream integration, deploy it, start a run, watch it live, and see the clean-up.Open full screen ↗

Why integrations matter

Less code

You keep only your own logic. The hard parts are in packages that are tested and kept up to date.

Correct settings

Each integration shows a plan and writes nothing until you say yes. task:validate finds a hand edit that breaks it, before you deploy.

Safe by default

The network stays closed: you add each host. Secrets are names in task.yaml, never values in your code.

One-command upgrades

Run integration:add again to get the latest version. The plan shows only what is new.

The steps

  1. Create a task. You get a folder with task.yaml and package.json.
  2. Add the integrations. Each one shows a plan of the settings it needs, and writes them when you say yes.
  3. Finish task.yaml. You add two hosts: the host of the video and the host of your bucket.
  4. Write the code. About 20 lines: stream, upload, return.
  5. Deploy and run. Share the viewer link. The recording links come back in the run's result.

Before you start

  • A plan that allows inbound traffic and the std.medium preset. This tutorial uses Pro.
  • The CLI, installed and signed in. See Install.
  • An S3-compatible bucket and an access key for it.
  • The launch video at an https:// address.

Step 1: Create the task

Create a Node task. task:create also writes the package.json that the integrations need.

terminal
$ ignitify task:create launch-event

The task already has some settings of its own: a system package, a preset and an interaction value. Make task.yaml look like this:

task.yaml (before integrations)
schema_version: 1
slug: launch-event
runtime: node
execution:
  interaction: boundary-only
build:
  system_packages: [imagemagick]
run:
  payload: {}
  preset: std.small
  timeout_sec: 7200

Step 2: Add stream

The first try is refused:

terminal
$ ignitify integration:add stream --task launch-event@ignitify-integrations/stream@0.1.3 · settings + code · runs ffmpeg✗ execution.interaction is boundary-only but @ignitify-integrations/stream needs continuous: change it by hand or use another task

Nothing is written. The stream sends progress while it runs, so it needs interaction: continuous. In task.yaml, change interaction: boundary-only to interaction: continuous, and run the command again:

terminal
$ ignitify integration:add stream --task launch-event@ignitify-integrations/stream@0.1.3 · settings + code · runs ffmpeg  execution.network.type: none -> bidirectional  run.preset: std.small -> std.medium  + execution: duration long  + execution.network: inbound_port 8080  + execution.network.inbound_routes: /live/  + build.system_packages: ffmpegyou add:  egress host: the host of an https source (for example raw.githubusercontent.com); none for a local fileApply? [y/N] y✓ @ignitify-integrations/stream@0.1.3 installed✓ task.yaml updated

The network type and the preset go up. ffmpeg is added to your system packages, and imagemagick stays. The task had no network, so egress_allow is written as []: the task cannot connect to a host until you add one.

Step 3: Add s3-storage

terminal
$ ignitify integration:add s3-storage --task launch-event@ignitify-integrations/s3-storage@0.1.1 · settings + code  + secrets: S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEYyou add:  secret S3_ACCESS_KEY_ID (new): ignitify secret:set S3_ACCESS_KEY_ID --stdin  secret S3_SECRET_ACCESS_KEY (new): ignitify secret:set S3_SECRET_ACCESS_KEY --stdin  egress host: your bucket host: <bucket>.s3.<region>.amazonaws.com on AWS, or the host of your custom endpointApply? [y/N] y✓ @ignitify-integrations/s3-storage@0.1.1 installed✓ task.yaml updated

Add stream again. The plan has no changes, and task.yaml, package.json and the lockfile stay the same:

terminal
$ ignitify integration:add stream --task launch-event@ignitify-integrations/stream@0.1.3 · settings + code · runs ffmpegyou add:  egress host: the host of an https source (for example raw.githubusercontent.com); none for a local filetask.yaml already has every setting this integration needs; nothing to write

Step 4: Finish task.yaml

Replace egress_allow: [] with the two "you add" hosts: the host of the video, and the host of your bucket. The integrations wrote everything else.

task.yaml
schema_version: 1
slug: launch-event
runtime: node
execution:
  interaction: continuous
  duration: long
  network:
    type: bidirectional
    egress_allow:
      - media.example.com # you added: the video source
      - acme-rec.s3.eu-west-1.amazonaws.com # you added: the bucket
    inbound_port: 8080
    inbound_routes:
      - prefix: /live/
build:
  system_packages: [imagemagick, ffmpeg]
run:
  payload:
    video: https://media.example.com/launch.mp4 # the default video; a run can send another
    start_delay_sec: 120 # the viewer link is in the progress this long before the video starts
  preset: std.medium
  timeout_sec: 7200
secrets:
  - S3_ACCESS_KEY_ID
  - S3_SECRET_ACCESS_KEY

package.json now lists @ignitify-integrations/stream and @ignitify-integrations/s3-storage.

Step 5: Write the code

The code has three parts: stream, upload, return. startDelaySec serves the player page and puts the viewer link in the run's progress before the video starts (120 s by default). after: 'stop' makes stream() return when the video ends, with the recording left on the disk.

The video and the delay come from the payload, so one deployment serves a rehearsal and the real event. The defaults are in run.payload in task.yaml.

index.ts
import { stream } from '@ignitify-integrations/stream';
import { storage } from '@ignitify-integrations/s3-storage';
import { readdir, writeFile } from 'node:fs/promises';
import { join } from 'node:path';

const WEEK_SEC = 7 * 86400; // the longest a download link can be valid

// payload (defaults in task.yaml run.payload): { video, start_delay_sec }
export async function run(payload, ctx) {
  const { video, start_delay_sec = 120 } = payload;

  // 1. Stream. The player page is served at once; the video starts after the delay,
  //    so viewers can open the link first.
  const live = await stream(ctx, { source: video, startDelaySec: start_delay_sec, after: 'stop' });
  if (live.cancelled) return live;

  // 2. Upload. after: 'stop' leaves the recording (a playlist and its segment files) in $HOME/hls
  const store = storage(ctx, { bucket: 'acme-rec', region: 'eu-west-1' });
  const dir = join(process.env.HOME, 'hls');
  const lines = [];
  for (const file of (await readdir(dir)).sort()) {
    const url = await store.putAndLink(join(dir, file), { expiresSec: WEEK_SEC });
    lines.push(`${file} ${url}`);
  }

  // 3. Return. A run result is small, so the download links go into one file, and the result links to that file.
  const list = join(process.env.HOME, 'recording-links.txt');
  await writeFile(list, lines.join('\n') + '\n');
  const recording = await store.putAndLink(list, { expiresSec: WEEK_SEC, contentType: 'text/plain' });

  return { watch: live.watch, files: lines.length, recording };
}

Step 6: Store the secrets

Each command reads the value from stdin, so it stays out of your shell history. See Use secrets.

terminal
$ ignitify secret:set S3_ACCESS_KEY_ID --stdin
terminal
$ ignitify secret:set S3_SECRET_ACCESS_KEY --stdin

Step 7: Validate

task:validate also checks that task.yaml covers every integration of the task.

terminal
$ ignitify task:validate launch-event✓ task config valid

Step 8: Deploy and run

The build installs ffmpeg and the packages from your lockfile.

terminal
$ ignitify task:deploy launch-event

Run a rehearsal first, with another video and a 10-second delay. --payload replaces the whole default payload for this run only, so give every key:

terminal
$ ignitify task:run launch-event --payload '{"video":"https://media.example.com/rehearsal.mp4","start_delay_sec":10}'

For the event, run with the defaults from task.yaml:

terminal
$ ignitify task:run launch-event

Each command prints the run id. A new deploy is needed only when you change the code or task.yaml, not for another video.

During the wait before the stream starts, the viewer link is in the run's progress. progress holds the last chunk that the task sent, so copy the watch link during the wait:

terminal
$ ignitify run:get <run-id> --full
run:get --full (part)
{
  "status": "RUNNING",
  "progress": {
    "status": "waiting",
    "start_in_s": 120,
    "watch": "https://<route-id>--<tenant-id>.ignitify.app/live/"
  }
}

Open the link in a browser. Keep the / at the end. The page waits for the stream and starts to play when the video starts. Send the same link to your viewers.

While the video plays, progress shows the stream's state: "status": "streaming", the seconds streamed, and the encode speed.

Step 10: Get the recording

When the video ends, the task uploads the recording and returns. Read the result:

terminal
$ ignitify run:get <run-id>
Result
{
  "watch": "https://<route-id>--<tenant-id>.ignitify.app/live/",
  "files": <n>,
  "recording": "<download link of recording-links.txt>"
}

Open the recording link. It is a text file with one download link for each file of the recording.

Stop early or debug

To stop the stream before the video ends, cancel the run. stream() stops ffmpeg and returns cancelled: true, and the task returns before the upload:

terminal
$ ignitify run:cancel <run-id> --yes

The task's console output (the ffmpeg log and the stream's messages):

terminal
$ ignitify run:logs <run-id>

All runs of the task:

terminal
$ ignitify run:list --task-name launch-event

See Troubleshoot for the common errors.

Later: a hand edit breaks the task

Months later, someone deletes the secret names and lowers the preset to save money. task:validate finds it before a deploy, not when ffmpeg runs out of memory during the event:

terminal
$ ignitify task:validate launch-event✗ @ignitify-integrations/s3-storage: secret S3_ACCESS_KEY_ID is missing from secrets✗ @ignitify-integrations/s3-storage: secret S3_SECRET_ACCESS_KEY is missing from secrets✗ @ignitify-integrations/stream: run.preset is std.small, needs at least std.medium

Later: upgrade an integration

When a new version of an integration comes out, task:validate warns that your version is obsolete and names the latest one. The warning does not change the exit code.

To upgrade, run integration:add again. It installs the latest version, and the plan shows only the new settings:

terminal
$ ignitify integration:add stream --task launch-event

Then run task:validate. It now checks task.yaml against the new version. Then deploy.

Clean up

Delete what you no longer need. The files in your bucket stay until you delete them there.

terminal
$ ignitify deployment:delete <deployment-id> --yes
terminal
$ ignitify task:delete launch-event --yes

Next steps