'Trying to password protect my static website hosted on S3

I have a cloudfront distributing which is linked to my S3 bucket on which my website is hosted.I wanted to password protect my website so I created a lambda function with authorization code and attached it to my cloud front distribution. Now When I open my website I get prompted to type user and password but when I type user and password I get again prompted to type the user and password and I am not able to access my website. This is very strange. This is the link to the tutorial which I followed

https://hackernoon.com/serverless-password-protecting-a-static-website-in-an-aws-s3-bucket-bfaaa01b8666

Anyone has any idea what could be the cause of this? Any help would be appreciated.



Solution 1:[1]

The only way to get this done is to put CloudFront on top of your S3 bucket and use Lambda@Edge to authorise requests.

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 Tomek Klas