Search code examples
amazon-web-servicesamazon-cloudfrontaws-lambda-edge

AWS CloudFront and Lambda@Edge return 403


I use AWS CloudFront Distribution with Lambda@Edge

enter image description here

viewer-request set S3 number 1 or S3 number 2 (random). In my S3, I have an Angular app. My cloudfront redirect to index.html and my angular router redirect to https://----cloufront-url----/account/login This case work.

But my problem is if I use directly https://----cloufront-url----/account/login

I have AWS 403 error page

<Error>
    <Code>AccessDenied</Code>
    <Message>Access Denied</Message>
    <RequestId>RPKQVNA4Z91730HP</RequestId>
    <HostId>GfLv+WDdqd1vUqtxk71Dc7hgVCwQFvr9Zm7oL7v2jIOppEfGRammRWpD/VXt+UuAe3F/Mpy6K70=</HostId>
</Error>

I find lot of pepole with same problem and I add 403 configuration to my cloudfront (redirect to index.html), but in my case I have Lambda@Edge so the cas is different.

My cloudFront behavior configuration:

path pattern: Default (*)

enter image description here

I try follow this https://medium.com/@peatiscoding/here-is-how-easy-it-is-to-deploy-an-angular-spa-single-page-app-as-a-static-website-using-s3-and-6aa446db38ef

enter image description here

work it without Lambda@Edge, but not with.


Solution

  • my error was on the version of the "viewer request" which goes up during deploy but which is not taken into account in the "Behaviors" configuration of the cloudFront distribution