Skip to content

Latest commit

 

History

History

aws-ivs-alpha

AWS::IVS Construct Library


cdk-constructs: Experimental

The APIs of higher level constructs in this module are experimental and under active development. They are subject to non-backward compatible changes or removal in any future version. These are not subject to the Semantic Versioning model and breaking changes will be announced in the release notes. This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package.


Amazon Interactive Video Service (Amazon IVS) is a managed live streaming solution that is quick and easy to set up, and ideal for creating interactive video experiences. Send your live streams to Amazon IVS using streaming software and the service does everything you need to make low-latency live video available to any viewer around the world, letting you focus on building interactive experiences alongside the live video. You can easily customize and enhance the audience experience through the Amazon IVS player SDK and timed metadata APIs, allowing you to build a more valuable relationship with your viewers on your own websites and applications.

This module is part of the AWS Cloud Development Kit project.

Channels

An Amazon IVS channel stores configuration information related to your live stream. You first create a channel and then contribute video to it using the channel’s stream key to start your live stream.

You can create a channel

const myChannel = new ivs.Channel(this, 'Channel');

You can use Advanced Channel type by setting the type property to ivs.ChannelType.ADVANCED_HD or ivs.ChannelType.ADVANCED_SD.

Additionally, when using the Advanced Channel type, you can set the preset property to ivs.Preset.CONSTRAINED_BANDWIDTH_DELIVERY or ivs.Preset.HIGHER_BANDWIDTH_DELIVERY.

For more information, see Amazon IVS Streaming Configuration.

const myChannel = new ivs.Channel(this, 'myChannel', {
  type: ivs.ChannelType.ADVANCED_HD,
  preset: ivs.Preset.CONSTRAINED_BANDWIDTH_DELIVERY,
});

If you want to use RTMP ingest, set insecureIngest property to true. By default, insecureIngest is false which means using RTMPS ingest.

⚠ Note: RTMP ingest might result in reduced security for your streams. AWS recommends that you use RTMPS for ingest, unless you have specific and verified use cases. For more information, see Encoder Settings.

const myRtmpChannel = new ivs.Channel(this, 'myRtmpChannel', {
  type: ivs.ChannelType.STANDARD,
  insecureIngest: true, // default value is false
});

Importing an existing channel

You can reference an existing channel, for example, if you need to create a stream key for an existing channel

const myChannel = ivs.Channel.fromChannelArn(this, 'Channel', myChannelArn);

Stream Keys

A Stream Key is used by a broadcast encoder to initiate a stream and identify to Amazon IVS which customer and channel the stream is for. If you are storing this value, it should be treated as if it were a password.

You can create a stream key for a given channel

const myStreamKey = myChannel.addStreamKey('StreamKey');

Private Channels

Amazon IVS offers the ability to create private channels, allowing you to restrict your streams by channel or viewer. You control access to video playback by enabling playback authorization on channels and generating signed JSON Web Tokens (JWTs) for authorized playback requests.

A playback token is a JWT that you sign (with a playback authorization key) and include with every playback request for a channel that has playback authorization enabled.

In order for Amazon IVS to validate the token, you need to upload the public key that corresponds to the private key you use to sign the token.

const keyPair = new ivs.PlaybackKeyPair(this, 'PlaybackKeyPair', {
  publicKeyMaterial: myPublicKeyPemString,
});

Then, when creating a channel, specify the authorized property

const myChannel = new ivs.Channel(this, 'Channel', {
  authorized: true, // default value is false
});

Recording Configurations

An Amazon IVS Recording Configuration stores settings that specify how a channel's live streams should be recorded. You can configure video quality, thumbnail generation, and where recordings are stored in Amazon S3.

For more information about IVS recording, see IVS Auto-Record to Amazon S3 | Low-Latency Streaming.

You can create a recording configuration:

// create an S3 bucket for storing recordings
const recordingBucket = new s3.Bucket(this, 'RecordingBucket');

// create a basic recording configuration
const recordingConfiguration = new ivs.RecordingConfiguration(this, 'RecordingConfiguration', {
  bucket: recordingBucket,
});

Renditions of a Recording

When you stream content to an Amazon IVS channel, auto-record-to-s3 uses the source video to generate multiple renditions.

For more information, see Discovering the Renditions of a Recording.

declare const recordingBucket: s3.Bucket;

const recordingConfiguration= new ivs.RecordingConfiguration(this, 'RecordingConfiguration', {
  bucket: recordingBucket,

  // set rendition configuration
  renditionConfiguration: ivs.RenditionConfiguration.custom([ivs.Resolution.HD, ivs.Resolution.SD]),
});

Thumbnail Generation

You can enable or disable the recording of thumbnails for a live session and modify the interval at which thumbnails are generated for the live session.

Thumbnail intervals may range from 1 second to 60 seconds; by default, thumbnail recording is enabled, at an interval of 60 seconds.

For more information, see Thumbnails.

declare const recordingBucket: s3.Bucket;

const recordingConfiguration = new ivs.RecordingConfiguration(this, 'RecordingConfiguration', {
  bucket: recordingBucket,

  // set thumbnail settings
  thumbnailConfiguration: ivs.ThumbnailConfiguration.interval(ivs.Resolution.HD, [ivs.Storage.LATEST, ivs.Storage.SEQUENTIAL], Duration.seconds(30)),
});

Merge Fragmented Streams

The recordingReconnectWindow property allows you to specify a window of time (in seconds) during which, if your stream is interrupted and a new stream is started, Amazon IVS tries to record to the same S3 prefix as the previous stream.

In other words, if a broadcast disconnects and then reconnects within the specified interval, the multiple streams are considered a single broadcast and merged together.

For more information, see Merge Fragmented Streams.

declare const recordingBucket: s3.Bucket;

const recordingConfiguration= new ivs.RecordingConfiguration(this, 'RecordingConfiguration', {
  bucket: recordingBucket,

  // set recording reconnect window
  recordingReconnectWindow: Duration.seconds(60),
});

Attaching Recording Configuration to a Channel

To enable recording for a channel, specify the recording configuration when creating the channel:

declare const recordingConfiguration: ivs.RecordingConfiguration;

const channel = new ivs.Channel(this, 'Channel', {
  // set recording configuration
  recordingConfiguration: recordingConfiguration,
});