{"id":881,"date":"2022-01-06T14:03:00","date_gmt":"2022-01-06T20:03:00","guid":{"rendered":"https:\/\/www.joshualyman.com\/?p=881"},"modified":"2022-01-05T13:03:28","modified_gmt":"2022-01-05T19:03:28","slug":"add-http-basic-authentication-to-cloudfront-distributions","status":"publish","type":"post","link":"https:\/\/www.joshualyman.com\/2022\/01\/add-http-basic-authentication-to-cloudfront-distributions\/","title":{"rendered":"Add HTTP Basic Authentication to CloudFront Distributions"},"content":{"rendered":"\n
I have a static site hosted in an S3 bucket (old 8mm family videos) that I wanted to make available to a limited number of folks, but I didn’t want to bother with worrying about doing any sort of federated authentication or limiting via IP or VPN access. A very simple yet effective means of doing this is to just use HTTP Basic Authentication, where the browser itself will prompt the visitor for a username and password and pass it to the server for authentication.<\/p>\n\n\n\n
The site in the bucket is served by a CloudFront distribution. There’s no option in either S3 or CloudFront to enable HTTP Basic Auth, but luckily it can be done by writing a function that is executed on each request for an asset in the distribution.<\/p>\n\n\n\n