Skip to content

Instantly share code, notes, and snippets.

@hirobert
Last active December 21, 2023 20:38
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hirobert/1200126f01362e24d9b9 to your computer and use it in GitHub Desktop.
Save hirobert/1200126f01362e24d9b9 to your computer and use it in GitHub Desktop.
response-content-disposition and cloudfront
1) Log in to aws console.
2) Click cloudfront
3) Click behaviors
4) Select pattern and edit
5) Set Forward Query Strings - Yes
6) click "Yes, edit" to save your edits
7) It may take some time for cloudfront cache to expire, so that these changes take effect
8) Your code should do something like below.
Add the escaped string as a query string to the url before signing it.
from boto.cloudfront.distribution import Distribution
d = Distribution()
encoded_headers = 'response-content-disposition=attachment%3B%20filename%3Dname_of_file_here.txt'
url = d.create_signed_url('%s%s?%s' % (hostname, filepath, encoded_headers),
key_id,
private_key_string=private_key_string,
expire_time=ttl)
@samuel-cloete
Copy link

This was helpful, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment