Set up notifications in Kinesis Video Streams
When a media fragment is available for consumption, Kinesis Video Streams notifies customers using Amazon Simple Notification Service (Amazon SNS) notifications.
Note
Amazon Kinesis Video Streams uses Amazon SNS Standard Topics for the communication. FIFO topics aren't currently supported.
The following topics explain how to get started with notifications.
Manage notification configurations
To manage notification configurations, use UpdateNotificationConfiguration
and DescribeNotificationConfiguration
. See below for more information.
UpdateNotificationConfiguration
Use this API operation to update the notification information for a stream. For more
information about the UpdateNotificationConfiguration
feature, see UpdateNotificationConfiguration in the
Amazon Kinesis Video Streams Developer Guide.
Note
It takes at least one minute to initiate the notification after updating the notification
configuration. Wait at least one minute before invoking PutMedia
after the update call.
DescribeNotificationConfiguration
Use this API to describe a notification configuration attached to a stream. For more
information about the DescribeNotificationConfiguration
feature, see DescribeNotificationConfiguration in the
Amazon Kinesis Video Streams Developer Guide.
About producer MKV tags
You can use the Kinesis Video Streams producer SDK to tag specific fragments of interest by exposing an API operation in
the SDK. See a sample of how this works in this section of code
Any fragment metadata provided along with the Notification MKV tags will be published as part of the Amazon SNS topic payload.
Syntax for producer MKV tags
|+ Tags | + Tag | // MANDATORY: Predefined MKV tag to trigger the notification for the fragment | + Simple | + Name: AWS_KINESISVIDEO_NOTIFICATION | + String | // OPTIONAL: Key value pairs that will be sent as part of the Notification payload | + Simple | + Name:
CUSTOM_KEY_1
// Max 128 bytes | + String:CUSTOM_VALUE_1
// Max 256 bytes | + Simple | + Name:CUSTOM_KEY_2
// Max 128 bytes | + String:CUSTOM_VALUE_2
// Max 256 bytes
MKV tag limits
The following table lists the limitations associated with the metadata tags. If the metadata tag limit is adjustable, you can request an increase through your account manager.
Limit | Max value | Adjustable |
---|---|---|
Optional metadata key length |
128 |
No |
Optional metadata value length |
256 |
No |
Max number of optional metadata |
10 |
Yes |
Amazon SNS messages
This topic contains more information about Amazon SNS messages and topic payloads.
Amazon SNS topic payload
Any notification initiated through the previous workflow will deliver the Amazon SNS topic payload, as shown in the following example. This example is an Amazon SNS message that occurs after consuming notification data from an Amazon Simple Queue Service (Amazon SQS) queue.
{ "Type" : "Notification", "MessageId" :
Message ID
, "TopicArn" :SNS ARN
, "Subject" : "Kinesis Video Streams Notification", "Message" : "{\"StreamArn\":\Stream Arn
,\"FragmentNumber\":\Fragment Number
,\"FragmentStartProducerTimestamp\":FragmentStartProducerTimestamp
, \"FragmentStartServerTimestamp\":FragmentStartServerTimestamp
,\"NotificationType\":\"PERSISTED\",\"NotificationPayload\":{\CUSTOM_KEY_1
:\CUSTOM_VALUE_1
, \CUSTOM_KEY_2
:\CUSTOM_VALUE_2
}}", "Timestamp" : "2022-04-25T18:36:29.194Z", "SignatureVersion" :Signature Version
, "Signature" :Signature
, "SigningCertURL" :Signing Cert URL
, "UnsubscribeURL" :Unsubscribe URL
}
Subject: "Kinesis Video Streams Notification" Message: { "StreamArn":
Stream Arn
, "FragmentNumber":Fragment Number
, "FragmentStartProducerTimestamp":Fragment Start Producer Timestamp
, "FragmentStartServerTimestamp":Fragment Start Server Timestamp
, "NotificationType":"PERSISTED", "NotificationPayload":{CUSTOM_KEY_1
:CUSTOM_VALUE_1
,CUSTOM_KEY_2
:CUSTOM_VALUE_2
} }
View your Amazon SNS messages
You cannot read messages directly from an Amazon SNS topic because there's no API for doing so. To view the messages, subscribe an SQS queue to the SNS topic, or choose any other Amazon SNS supported destination. However, the most efficient option for viewing messages is to use Amazon SQS.
To view your Amazon SNS messages using Amazon SQS
-
Create an Amazon SQS queue.
-
From the AWS Management Console, open the Amazon SNS topic set as a destination under
NotificationConfiguration
. -
Choose Create Subscription, and then choose the Amazon SQS queue created in the first step.
-
Run a
PutMedia
session with the Notification configuration enabled and with the Notification MKV tags added to the fragments. -
Choose the Amazon SQS queue in the Amazon SQS console, and then select Send and receive messages for the Amazon SQS queue.
-
Poll for messages. This command should show all notifications generated by the
PutMedia
session. For information about polling, see Amazon SQS short and long polling.