AWS Cloudfront can't access S3 files deployed with CodeBuild - amazon-web-services

I'm working on getting a static website deployed with AWS Codebuild, hosted in an S3 bucket, and accessed via Cloudfront. Everything seems to work except from accessing from Cloudfront. From Cloudfront, I can access files that I manually upload, and using the bucket URL, I can access all the files. Looking through the individual file settings/permissions, they all look to be the same, regardless of whether they were manually uploaded, or deployed via Codebuild. I've tried invalidating the Cloudfront cache, and re-deployed via Codebuild several times.
Additional Information:
I provided the S3 bucket as an origin when setting up the Cloudfront distribution.
Accessing via Cloudfront gives the following error:
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>0211CBE618946F</RequestId>
<HostId>
7sRZhaJS4x2W7Iaeo4y8KAjvsOJcNWh3PxCdgnhXPE22oyp1RxZhwpjrqbsWapsUSaqBK+jqE=
</HostId>
</Error>
What else should I check?

For some reason, adding a default root object fixed the issue.
FWIW, I initially changed the value to dist/index.html, which allowed me to access the deployed bucket contents via the Cloudfront URL, but required the index.html suffix. Once I changed it to index.html, everything worked fine.

Related

Unable to access S3 objects via Cloudfront URL

I am unable to access S3 objects and Bucket via cloud front URL.
I have created CLOUDFRONT Distribution ( Web ) and setup origin path to media folder in my S3 bucket. ( /media)
CF url is pointing to bucket/media , but i am unable to access it from my web application as well as browser.
I am trying to access like below:
http://d1xdpXXXXX.cloudfront.net/media/images/Tiger.jpg
Tiger.jpg can be accessed via s3 url.
I also tried http://d1xdpXXXXX.cloudfront.net but i am getting below error:
<Error>
<Code>NoSuchBucket</Code>
<Message>The specified bucket does not exist</Message>
<BucketName>d1xdpwiqgrffrd.cloudfront.net</BucketName>
<RequestId>484BBB2F7907172F</RequestId>
<HostId>+bLr4Qx+uawbq4YNIOuKGCQVDGQQQsifGnNt9J5Pn+r3mqbDiVYcpNZRUfnCyPnHxewfMVp3QYc=</HostId>
</Error>
Please help.
CF Distribution settings
Access denied error
You have already added the path in cloudfront origin.
So, you don't have to add that in cloudfront url you are using to download.
Just use
http://d1xdpXXXXX.cloudfront.net/images/Tiger.jpg
as /media is already part of the distribution.

AWS S3 Bucket - Access Denied on Sub-Pages

So I have an AWS S3 Bucket hosting the files for a react application I've built. I use CodePipeline to build and compile the React app and store the files on an S3 bucket which is served through a CloudFront CDN.
Everything seems to be working fine when I access the url from the root https://website.com. When I click "login" on that page I get directed to the following route https://website.com/auth/login and it works awesome.
The Problem
If I try to access the page https://website.com/auth/login directly I get the following error:
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>66CE67E2E5DA0B7B</RequestId>
<HostId>Spfhgnlygx05eugycEy5ew4e8oSn/ccNX21Iy/6qaAxI8glXljDjgKmUPvMzRd8+NktQsNietpg=</HostId>
</Error>
I set the default resource in the cloudfront CDN to the /index.html which is why the root domain works, but how do I get all there urls to point to /index.html so the app routes it properly?
I needed to set a rule for 403 Forbidden in my cloudfront configuration as posted here: Receive AccessDenied when trying to access a reload or refresh or one in new tab in angular 5

"The specified key does not exist" while creating CloudFront distribution

I have created an s3 bucket and uploaded an image in it. My s3 url is working and fine but when I try this with cloudfront url it shows me this error.
<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
<Key>s3://avanish2302/justice.jpg/</Key>
<RequestId>B8BF8D5981519FF9</RequestId>
<HostId>RQ2CwxcujOp648JZD9dg6HD/4DVOtEs7/sJ86qWvR0oVfQn7FtAzH0+XN7mwwtwEdOriOJQ/V6w=</HostId>
</Error>
I have tried copying the object path from the s3 and pasted in the object path while creating cloudfront.
Its strange that when I tried it before using the same steps, it used to work fine but now when I follow the same steps, it shows me this error.
My s3 bucket and object are set to public. Does anyone have this problem?
They key should not have s3:// in front of it. You configured that as your origin already. The key is location of the file in the bucket (justice.jpg, no trailing slash). Also, see this https://www.fernandomc.com/posts/amazon-s3-static-sites-and-cloudfront-configuration/

GCP static website returns Error: NoSuchBucket

I created a GCP storage bucket named for a domain managed by Google Domains. I have uploaded the files, created a CNAME record for c.storage.googleapis.com, and changed the ACLs to public-read. However, I'm still getting the error:
<Error>
<Code>NoSuchBucket</Code>
<Message>The specified bucket does not exist.</Message>
</Error>
Note that I wasn't asked to verify the domain when I created the bucket. I assume this is normal for a domain managed by Google Domains as it says "automatically verified."
I'm not sure how to debug this issue.
I got it. I just needed to add www. to the beginning of the bucket name.
In other words:
www.domain.com instead of domain.com

Cloudfront url synchronized with s3 path

I was using s3 for for my static websites, we had three websites/paths in s3:
example.com
example.com/website1
example.com/website2
Website1 and Website2 were folders inside the bucket example.com as expected. But now we need https urls so we decided to go with aws cloudfront for the redirects. Cloudfront generated for example a url like this, https://123455678.cloudfront.net .
When I navigate to the url, it gets the example.com correctly, but when I try to put like https://123455678.cloudfront.net/website1 it seems like its not entering the /website1 path in the s3. So it gives me this error because it's not finding the index.html inside the /website1 path.
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>C5259E1658595A69</RequestId>
<HostId>
B1HYQsr0Xv4M1avKlJ3G8t0rkVfCvbOoJadxm5z1BwapblBeERm3c6Ni+jZWxB8FlXEaF6bUAik=
</HostId>
</Error>
I guess I have to do something in the origins and behaviours of my cloudfront distribution, but I can't figure out what to do there...
I fixed my problem by changing the origin domain name in my cloudfront distribution to my s3 bucket endpoint, located in the properties of my bucket in Static Website Hosting area.
Saved, waited for cloudfront to use the updated changes and it worked. Also my Default Root Object is set to index.html .
Hope it helps someone =)