'How to add Content-Disposition response header for AWS CloudFront

I have a Content Distribution Network served by AWS CloudFront. Some of my clients want to download this file with a specific filename, so I guess that the natural solution will be injecting a Content-Disposition response header.

For example, I can use a query parameter filename for my CloudFront URL so that this file can be downloaded with the name awesome.png

https://XXX.cloudfront.net/abc.png?filename=awesome.png

Then all I have to do is to add the Content-Disposition header to its response.

I thought that it can be easily handled by CloudFront Function or Lambda@Edge, but I found that they cannot solve my problem. It's because the query string filename is in the HTTP request, but the Content-Disposition header must be injected in the HTTP header.

Can anyone suggest a working solution?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source