For signed cookies, refer here
from cloudfront_signed_url import generate_cloudfront_signed_url
generate_cloudfront_signed_url("https://your-cf-domain.com/path/to/file.txt", 3600)
- Configured CloudFront Distribution
- An Origin access identity and a CloudFront key
- Origin and Behavior configured to Restrict Viewer Access
Reference: http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/PrivateContent.html
- Make sure you have a CloudFront key pair and key group created and associated with distribution behavior, details here)
- Replace newlines with
\\n
in private key and save the result to an SSM Parameter Store paramater namedCF_SIGNED_URL_PRIVATE_KEY
- Save key ID (key pair ID) to a parameter named
CF_SIGNED_URL_KEY_ID
- Unlike S3 pre-signed URLs, you can use a link generated once multiple times, as long as it is still valid (TTL).
- You can modify
make_policy
to make other policies (not per-url, but broader clauses), or even signed cookies (Policy, Signature, Key-Pair-Id are generated in the same way for cookies too).
- cryptography
- boto3 (only for SSM)
This works for me on my proof on concept project for Cloudfront Signed URLs. Thank you!