📝
Amazon Interactive Video Service を CDK で使ってみた
インタラクティブなライブストリーミング – Amazon Interactive Video Service – Amazon Web Services
チュートリアルレベルの内容です。
前提
- 開発環境: Cloud9 (Amazon Linux 2023)
1. CDK プロジェクト作成
$ mkdir -p ~/.npm-global
$ npm config set prefix '~/.npm-global'
$ echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
$ source ~/.bashrc
$ npm install -g typescript
$ mkdir ivs-cdk-project
$ cd ivs-cdk-project
$ cdk init app --language typescript
2. CDK ファイル作成
lib/ivs-cdk-project-stack.ts
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as ivs from '@aws-cdk/aws-ivs-alpha';
export class IvsCdkProjectStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// IVS チャンネルを作成
const channel = new ivs.Channel(this, 'MyIvsChannel', {
channelName: 'my-first-ivs-channel',
type: ivs.ChannelType.STANDARD,
});
// ストリームキーを作成
const streamKey = new ivs.StreamKey(this, 'MyStreamKey', {
channel: channel,
});
// ストリームキーとチャンネル情報を出力
new cdk.CfnOutput(this, 'ChannelArn', {
value: channel.channelArn,
description: 'IVS Channel ARN',
});
new cdk.CfnOutput(this, 'IngestEndpoint', {
value: channel.channelIngestEndpoint,
description: 'IVS Ingest Endpoint',
});
new cdk.CfnOutput(this, 'PlaybackUrl', {
value: channel.channelPlaybackUrl,
description: 'IVS Playback URL',
});
new cdk.CfnOutput(this, 'StreamKeyValue', {
value: streamKey.streamKeyValue,
description: 'IVS Stream Key (Keep this secret!)',
});
}
}
3. デプロイ
$ cdk synth
$ cdk deploy
4. FFmpeg のインストール
$ cd ~/environment
$ wget https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz
$ tar xvf ffmpeg-release-amd64-static.tar.xz
$ sudo ln -s ~/environment/ffmpeg-*-static/ffmpeg /usr/local/bin/ffmpeg
$ ffmpeg -version
5. 映像配信
$ ffmpeg -re -f lavfi -i testsrc=size=1280x720:rate=30 -f lavfi -i sine=frequency=1000 -c:v libx264 -preset veryfast -b:v 3000k -maxrate 3000k -bufsize 6000k -pix_fmt yuv420p -g 60 -c:a aac -b:a 128k -f flv rtmps://ac9f9fbe9815.global-contribute.live-video.net:443/app/sk_ap-northeast-1_9DKuvAFwtGZi_69giuaxmmGqRO9mdEtfVJWyh2uHTOy
上記コマンド実行後、IVS コンソールのチャネルで以下のような映像が再生されていれば OK です。

まとめ
今回は Amazon Interactive Video Service を CDK で使ってみました。
どなたかの参考になれば幸いです。
Discussion