Search code examples
rubyamazon-web-servicesvideo-streamingrtmpamazon-cloudfront

Private video streaming for Amazon CloudFront in ruby


How does signed URLs work for streamed videos in Amazon CloudFront?

I'm using aws_cf_signer gem, but can't get signed urls work for rtmp streamed mp4-file. For static files, like text.txt it works fine, but not when I have streaming distribution.

Example:

I have file named test.mp4 so how do I get signed url out of signer.sign()?

E.g. signed_url = signer.sign('rtmp://xyz.cloudfront.net/test', :ending => Time.now + 3600) does not produce working url. I have tested URLs with VLC player and rtmpdump

The distribution itself is created with boto like this:

stream_dist = cf.create_streaming_distribution(origin=origin, enabled=True, trusted_signers=["Self"], comment="test distribution")


Solution

  • According to the AWS: Restricting End User Access doc, the format for signed RTMP urls is different from HTTP:

    With HTTP, a full URL uniquely describes an object. You can include the URL in the signature. The content of a streaming distribution, however, cannot always be described by a valid URL. In a streaming distribution, you only use the stream name to create a signature. For example, if your stream including the signature is:

    example/mp3_name.mp3?Expires=1258237200&Signature=TBD&Key-Pair-Id=PK12345EXAMPLE

    The value for RESOURCE is:

    example/mp3_name

    For streaming distributions, you do not include a prefix, such as mp3: or mp4:, for the resource name in the policy.

    Also, when referencing an MPEG file, you might have to omit the file extension for the URL enclosed in the signature. For example, you use mp3_name instead of mp3_name.mp3.

    I'm not sure whether aws_cf_signer gem supports signing RTMP urls, unfortunately. If you find out, please let me know!