Search code examples
c#amazon-web-servicesamazon-cloudfront

cloudfront private time limited url


I have a client that wants to sell tutorial videos online. I already got previews of his tutorials streaming from CF (This is public). Now I want to use the c# sdk to generate private, time limited URLs to allow customers who purchased the tutorials to download them for a limited time period. Once the payment has been confirmed, I want to generate a URL and send it to the client via email.

Does CF/.NET SDK support this? Can someone point me at a sample. I have searched Google, and got a little information overload. Different examples from different versions of sdk/management console. Please help me make sense of it all :)


Solution

  • If you look at the class Amazon.CloudFront.AmazonCloudFrontUrlSigner that has helper methods for creating presigned URL to private distributions. For example this code snippet creates a url that is valid for one day.

    var url = AmazonCloudFrontUrlSigner.GetCannedSignedURL(AmazonCloudFrontUrlSigner.Protocol.http, domainName, cloudFrontPrivateKey, file, cloudFrontKeyPairID, DateTime.Now.AddDays(1));
    

    There are other utility methods in that class for adding more specific access rules.

    Note this class was added in version 1.5.2.0 of the SDK which came out in late Augest