IoT Lab KVS WebRTC WorkShop
View the Project on GitHub iotlabtpe/Amazon-KVS-WebRTC-WorkShop
We just test Amazon KVS WebRTC with IAM user but it is not recommended. With AWS IoT Thing credentials, it can be managed more securely. To use AWS IoT credential, you need to create an Amazon IAM role to grant your policy.






kinesisvideo:DescribeSignalingChannel in the following JSON.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"kinesisvideo:DescribeSignalingChannel",
"kinesisvideo:CreateSignalingChannel",
"kinesisvideo:GetSignalingChannelEndpoint",
"kinesisvideo:GetIceServerConfig",
"kinesisvideo:ConnectAsMaster"
],
"Resource": "arn:aws:kinesisvideo:*:*:channel/${credentials-iot:ThingName}/*"
}
]
}



{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "credentials.iot.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}

You can use AWS IoT Thing Name as Signaling Channel Name and AWS IoT Certificate ID as Signaling Channel Name. The example here is to use AWS IoT Thing Name as Signaling Channel Name, including IAM Role you created above.











your_region, your_id and your_policy_alias with your own information. You can find your_region and your_id in thing information you created above. And your_policy_alias is the alias you created above.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iot:Connect"
],
"Resource": "arn:aws:iot:your_region:your_id:rolealias/your_policy_alias"
},
{
"Effect": "Allow",
"Action": [
"iot:AssumeRoleWithCertificate"
],
"Resource": "arn:aws:iot:your_region:your_id:rolealias/your_policy_alias"
}
]
}





To adopt AWS IoT Credential to connect Amazon KVS WebRTC service, you should modify the related codes.
scp ~/Downloads/xxxxxxx-certificate.pem.crt pi@your_RPi_IP:~/Downloads/
scp ~/Downloads/xxxxxxx-private.pem.key pi@your_RPi_IP:~/Downloads/
scp ~/Downloads/xxxxxxx-public.pem.key pi@your_RPi_IP:~/Downloads/
cd ~/amazon-kinesis-video-streams-webrtc-sdk-c/
#Use your familiar editor to modify code
vim.tiny samples/Common.c
createStaticCredentialProvider and comment the whole lines out.
CHK_STATUS(lookForSslCert(&pSampleConfiguration));
// Set the logger log level
if (NULL == (pLogLevel = getenv(DEBUG_LOG_LEVEL_ENV_VAR)) || (STATUS_SUCCESS != STRTOUI32(pLogLevel, NULL, 10, &logLevel))) {
logLevel = LOG_LEVEL_WARN;
}
SET_LOGGER_LOG_LEVEL(logLevel);
//CHK_STATUS(
// createStaticCredentialProvider(pAccessKey, 0, pSecretKey, 0, pSessionToken, 0, MAX_UINT64, &pSampleConfiguration->pCredentialProvider));
SET_LOGGER_LOG_LEVEL(logLevel);
//CHK_STATUS(
// createStaticCredentialProvider(pAccessKey, 0, pSecretKey, 0, pSessionToken, 0, MAX_UINT64, &pSampleConfiguration->pCredentialProvider));
//Tec add for IoT
CHK_STATUS(
createLwsIotCredentialProvider(
"cxxxxxxx.credentials.iot.ap-northeast-1.amazonaws.com", // IoT credentials endpoint
"/home/pi/Downloads/xxxxxxx-certificate.pem.crt", // path to iot certificate
"/home/pi/Downloads/xxxxxxx-private.pem.key", // path to iot private key
"/home/pi/amazon-kinesis-video-streams-webrtc-sdk-c/certs/cert.pem", // path to CA cert
"your_policy_alias", // IoT role alias
channelName, // iot thing name, recommended to be same as your channel name
&pSampleConfiguration->pCredentialProvider));
if (IS_VALID_CVAR_VALUE(pSampleConfiguration->cvar)) {
CVAR_FREE(pSampleConfiguration->cvar);
}
//freeStaticCredentialProvider(&pSampleConfiguration->pCredentialProvider);
//Tec add for releasing
freeIotCredentialProvider(&pSampleConfiguration->pCredentialProvider);
cd build
make -j4
#....
#....
#You can export your AK/SK to whatever value to verify.
./kvsWebrtcClientMaster your_thing_name