I would like to configure an AWS CloudFront CDN to serve HTML static content from two AWS S3 buckets. One bucket should host the objects in the root, the second one should host objects in a specific subpath.
The first bucket, myapp.home
, should host the home page and all other objects directly under "/".
The second bucket, myapp.subpage
, should be used for the same purpose but for a specific set of URLs starting with "/subpage/".
Both buckets have been configured with "static website hosting" option enabled and with a default document "index.html", which has been uploaded to both.
Both buckets have been made public using the following policy (in the case of myapp.subpage
the Resource has been adapted accordingly)
{
"Version": "2012-10-17",
"Id": "Policy1529690634746",
"Statement": [
{
"Sid": "Stmt1529690623267",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::myapp.home/*"
}
]
}
The CDN is configured to respond to a name "host.domain.tld".
The CDN is configured having 2 origins:
myapp.home
, having these properties:
myapp.home.s3.amazonaws.com
myapp.subpage
, having these properties:
myapp.subpage.s3.amazonaws.com
These origins are linked to 2 Cache Behaviors:
myapp.subpage
:myapp.home
:The myapp.home
origin seems to work correctly, but myapp.subpath
instead always returns an AccessDenied error using all of the following URIs:
Update : I also tried substituting the origins using the S3 website domains, eg myapp.subpath.s3-website-eu-west-1.amazonaws.com , instead of the plain buckets domains: the homepage still works anyway, but the subpath this time returns a 404 with Message: "The specified key does not exist" for all URIs above.
What am i doing wrong?
Thanks in advance
The "subpage/*" in first behaviors is the directory in myapp.subpage
.
Make a directory named subpage
in the bucket, then put index.html into this bucket.
Like below:
* myapp.subpage <bucket name>
* subpage <directory>
* index.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.