Guide · Amazon Kinesis Video Streams · WebRTC Signaling Channels

Kinesis Video Streams WebRTC Signaling for MCP Servers — Signaling Channels, ICE Config, and Real-Time Video Agents

KVS WebRTC signaling channels let your MCP server or AI agent establish a real-time peer-to-peer video connection with any device — robot camera, factory sensor, IoT gateway — without maintaining a persistent RTMP or HTTP connection. The signaling channel handles the WebRTC handshake (SDP offer/answer exchange and ICE candidate discovery) while the actual media flows peer-to-peer. For AI agents that need to "see" a live feed without polling S3 for archived fragments, WebRTC provides sub-second latency and no storage cost.

TL;DR

Create a signaling channel with CreateSignalingChannelCommand. Get WSS endpoints per role with GetSignalingChannelEndpointCommand (roles: MASTER for the camera/sender, VIEWER for the agent/receiver). Get TURN/STUN credentials with GetIceServerConfigCommand (from the @aws-sdk/client-kinesis-video-signaling package, using the signaling endpoint as the client endpoint, not the regional endpoint). Then use amazon-kinesis-video-streams-webrtc-sdk-js to manage the WebRTC peer connection lifecycle. KVS WebRTC supports a single-master / multi-viewer topology only — one MASTER sends video, up to 10 VIEWERs receive it concurrently.

Signaling channel concepts

A signaling channel is a named resource that acts as a rendezvous point for WebRTC peers. It is distinct from a KVS stream: streams store video fragments; signaling channels just relay SDP messages and ICE candidates between peers. No video is stored in the signaling channel itself.

Creating and describing signaling channels

import {
  KinesisVideoClient,
  CreateSignalingChannelCommand,
  DescribeSignalingChannelCommand,
  ListSignalingChannelsCommand,
  DeleteSignalingChannelCommand,
  ChannelType,
} from "@aws-sdk/client-kinesis-video";

const kv = new KinesisVideoClient({ region: "us-east-1" });

// Create a signaling channel
const { ChannelARN } = await kv.send(new CreateSignalingChannelCommand({
  ChannelName: "factory-cam-01-webrtc",
  ChannelType: "SINGLE_MASTER",   // only supported type currently
  SingleMasterConfiguration: {
    MessageTtlSeconds: 60,  // how long SDP messages are retained if the recipient hasn't connected yet
  },
  Tags: [
    { Key: "CameraId", Value: "factory-cam-01" },
    { Key: "Environment", Value: "production" },
  ],
}));
console.log("Channel ARN:", ChannelARN);

// Describe an existing channel
const { ChannelInfo } = await kv.send(new DescribeSignalingChannelCommand({
  ChannelName: "factory-cam-01-webrtc",
}));
console.log("Status:", ChannelInfo.ChannelStatus); // "CREATING" | "ACTIVE" | "UPDATING" | "DELETING"
console.log("ARN:", ChannelInfo.ChannelARN);

// List all signaling channels (optional prefix filter)
const { ChannelInfoList } = await kv.send(new ListSignalingChannelsCommand({
  ChannelNameCondition: {
    ComparisonOperator: "BEGINS_WITH",
    ComparisonValue: "factory-",
  },
}));

Getting the signaling endpoint and ICE server config

Like KVS streams, signaling channels require a data-endpoint lookup before the actual signaling connection. Additionally, the ICE server config (STUN/TURN credentials) must be fetched using a client pointed at the signaling endpoint, not the regional endpoint:

import {
  KinesisVideoClient,
  GetSignalingChannelEndpointCommand,
} from "@aws-sdk/client-kinesis-video";
import {
  KinesisVideoSignalingClient,
  GetIceServerConfigCommand,
} from "@aws-sdk/client-kinesis-video-signaling";

const kv = new KinesisVideoClient({ region: "us-east-1" });

// Get WSS endpoints for VIEWER role (agent receiving video)
const { ResourceEndpointList } = await kv.send(new GetSignalingChannelEndpointCommand({
  ChannelARN: ChannelInfo.ChannelARN,
  SingleMasterChannelEndpointConfiguration: {
    Protocols: ["WSS", "HTTPS"],
    Role: "VIEWER",   // "MASTER" for the camera device, "VIEWER" for the agent
  },
}));

const signalingEndpoint = ResourceEndpointList.find(e => e.Protocol === "WSS")?.ResourceEndpoint;
const httpsEndpoint    = ResourceEndpointList.find(e => e.Protocol === "HTTPS")?.ResourceEndpoint;
console.log("WSS endpoint:", signalingEndpoint);
// e.g. "wss://v-a1b2c3d4e5.kinesisvideo.us-east-1.amazonaws.com"
console.log("HTTPS endpoint:", httpsEndpoint);

// Get ICE server config using the HTTPS endpoint, not the regional endpoint
const kvSignaling = new KinesisVideoSignalingClient({
  region: "us-east-1",
  endpoint: httpsEndpoint,  // critical: use channel-specific endpoint
});

const { IceServerList } = await kvSignaling.send(new GetIceServerConfigCommand({
  ChannelARN: ChannelInfo.ChannelARN,
  ClientId: "agent-viewer-" + Date.now(), // unique per VIEWER session
  Service: "TURN",
  Username: undefined, // omit for temporary credentials (auto-generated)
}));

console.log("ICE servers:", IceServerList);
// Each entry has: Uris (string[]), Username, Password, Ttl (seconds)
// Convert to RTCIceServer format for WebRTC:
const iceServers = IceServerList.map(server => ({
  urls: server.Uris,
  username: server.Username,
  credential: server.Password,
}));
// Also add Google STUN for discovery without NAT traversal
iceServers.unshift({ urls: "stun:stun.kinesisvideo.us-east-1.amazonaws.com:443" });

WebRTC peer connection with the KVS SDK

Once you have the signaling endpoint and ICE servers, use the amazon-kinesis-video-streams-webrtc-sdk-js package to handle the WebRTC signaling protocol over WSS. This SDK wraps the raw WebSocket connection and handles SDP offer/answer serialization:

npm install amazon-kinesis-video-streams-webrtc-sdk-js
import { SignalingClient, Role } from "amazon-kinesis-video-streams-webrtc-sdk-js";
import { KinesisVideoSignalingClient } from "@aws-sdk/client-kinesis-video-signaling";
import { fromEnv } from "@aws-sdk/credential-providers";

// Build credentials for the SignalingClient
const credentials = await fromEnv()();

const signalingClient = new SignalingClient({
  channelARN: ChannelInfo.ChannelARN,
  channelEndpoint: signalingEndpoint, // WSS endpoint from GetSignalingChannelEndpoint
  role: Role.VIEWER,
  region: "us-east-1",
  credentials: {
    accessKeyId: credentials.accessKeyId,
    secretAccessKey: credentials.secretAccessKey,
    sessionToken: credentials.sessionToken,
  },
  clientId: "agent-viewer-" + Date.now(),
  // systemClockOffset: kv.config.systemClockOffset, // optional: sync clock
});

// Set up event handlers
let peerConnection;

signalingClient.on("open", async () => {
  console.log("[VIEWER] Signaling channel open, creating peer connection...");

  peerConnection = new RTCPeerConnection({ iceServers });

  // Handle incoming video track from MASTER
  peerConnection.ontrack = (event) => {
    console.log("[VIEWER] Received track:", event.track.kind);
    // event.streams[0] is the MediaStream — attach to video element or pipe to AI pipeline
    const remoteStream = event.streams[0];
    // In a browser: videoElement.srcObject = remoteStream;
    // In Node.js: use a WebRTC library like node-webrtc or wrtc
  };

  // Forward ICE candidates to MASTER via signaling channel
  peerConnection.onicecandidate = ({ candidate }) => {
    if (candidate) {
      signalingClient.sendIceCandidate(candidate);
    }
  };

  // Create SDP offer and send to MASTER
  const offer = await peerConnection.createOffer({
    offerToReceiveVideo: true,
    offerToReceiveAudio: true,
  });
  await peerConnection.setLocalDescription(offer);
  signalingClient.sendSdpOffer(peerConnection.localDescription);
});

signalingClient.on("sdpAnswer", async (answer) => {
  console.log("[VIEWER] Received SDP answer from MASTER");
  await peerConnection.setRemoteDescription(answer);
});

signalingClient.on("iceCandidate", async (candidate) => {
  console.log("[VIEWER] Received ICE candidate from MASTER");
  await peerConnection.addIceCandidate(candidate);
});

signalingClient.on("close", () => {
  console.log("[VIEWER] Signaling channel closed");
});

signalingClient.on("error", (err) => {
  console.error("[VIEWER] Signaling error:", err);
});

// Connect — starts the WSS handshake
signalingClient.open();

MASTER role: the camera/device side

For completeness, here's the MASTER side pattern. In production deployments, the MASTER runs on the IoT device using the KVS C SDK or Python SDK. If you need a Node.js MASTER (e.g., for a software-defined camera or screen-capture use case), the pattern is symmetric but reversed — the MASTER waits for SDP offers from VIEWERs:

const masterSignalingClient = new SignalingClient({
  channelARN: ChannelInfo.ChannelARN,
  channelEndpoint: masterWSSEndpoint, // from GetSignalingChannelEndpoint with Role: "MASTER"
  role: Role.MASTER,
  region: "us-east-1",
  credentials: { accessKeyId, secretAccessKey, sessionToken },
});

const peerByClientId = {};

masterSignalingClient.on("open", () => {
  console.log("[MASTER] Ready — waiting for viewers...");
});

masterSignalingClient.on("sdpOffer", async (offer, remoteClientId) => {
  console.log("[MASTER] Received offer from viewer:", remoteClientId);

  const pc = new RTCPeerConnection({ iceServers });
  peerByClientId[remoteClientId] = pc;

  pc.onicecandidate = ({ candidate }) => {
    if (candidate) {
      masterSignalingClient.sendIceCandidate(candidate, remoteClientId);
    }
  };

  // Add local video/audio tracks to the peer connection
  // const stream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true });
  // stream.getTracks().forEach(track => pc.addTrack(track, stream));

  await pc.setRemoteDescription(offer);
  const answer = await pc.createAnswer();
  await pc.setLocalDescription(answer);
  masterSignalingClient.sendSdpAnswer(pc.localDescription, remoteClientId);
});

masterSignalingClient.on("iceCandidate", async (candidate, remoteClientId) => {
  const pc = peerByClientId[remoteClientId];
  if (pc) await pc.addIceCandidate(candidate);
});

masterSignalingClient.open();

WebRTC storage ingestion (KVS + WebRTC)

The @aws-sdk/client-kinesis-video-webrtc-storage package enables a device to simultaneously send video over WebRTC AND store it in a KVS stream. This is useful when you want both real-time viewing and archived retrieval from the same camera feed:

import {
  KinesisVideoWebRTCStorageClient,
  JoinStorageSessionCommand,
} from "@aws-sdk/client-kinesis-video-webrtc-storage";

// Get the storage endpoint (requires GetDataEndpoint with API_NAME: "JOIN_STORAGE_SESSION")
const { DataEndpoint: storageEndpoint } = await kv.send(new GetDataEndpointCommand({
  StreamARN: stream.StreamARN,
  APIName: "JOIN_STORAGE_SESSION",
}));

const kvWebRTCStorage = new KinesisVideoWebRTCStorageClient({
  region: "us-east-1",
  endpoint: storageEndpoint,
});

// Called on the MASTER/device side to start joint WebRTC+storage session
await kvWebRTCStorage.send(new JoinStorageSessionCommand({
  channelArn: ChannelInfo.ChannelARN,
}));

When JoinStorageSession is active, the MASTER's video track is ingested into the associated KVS stream with full retention. VIEWERs receive the live feed via WebRTC at the same time. The KVS stream must be associated with the signaling channel — do this when creating the stream by passing the channel ARN in the stream metadata.

Pricing and limits

Key gotchas

Continue in this series

Related AWS guides: AWS IoT Core for MCP servers · Kinesis Data Streams for MCP servers · Rekognition for MCP servers