- CloudFront の origin を static website hosting のドメインにする(foobar.s3-website-ap-northeast-1.amazonaws.com みたいなやつ)
- S3 の bucket を設定すると static website hosting ではないのでリダイレクトルールが適応されない
- S3 の policy の Principal は
"AWS": "*"
でないと 403 - redirect_rule.xml は 404 だったら your.domain にリダイレクト
- path を維持したい場合は
<ReplaceKeyWith/>
を削除 - https にしたければ
<Redirect></Redirect>
に<Protocol>https</Protocol>
を追加
- path を維持したい場合は
- POST を受けたい場合は API Gateway + Lambda を使う
- Origin を API Gateway の endpoint にする
- (当然だが)Host ヘッダを透過させると動かない
Last active
August 2, 2017 01:48
-
-
Save tkuchiki/88efd01f4e1d9f5c43f9a5b8dfe0c93e to your computer and use it in GitHub Desktop.
CloudFront + S3 で static website hosting のリダイレクトルールを使用するときの注意点 & API Gateway
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<RoutingRules> | |
<RoutingRule> | |
<Condition> | |
<HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals> | |
</Condition> | |
<Redirect> | |
<HostName>your.domain</HostName> | |
<ReplaceKeyWith/> | |
</Redirect> | |
</RoutingRule> | |
</RoutingRules> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Version": "2008-10-17", | |
"Id": "PolicyForCloudFrontStaticWebsiteHosting", | |
"Statement": [ | |
{ | |
"Sid": "1", | |
"Effect": "Allow", | |
"Principal": { | |
"AWS": "*" | |
}, | |
"Action": "s3:GetObject", | |
"Resource": "arn:aws:s3:::your_bucket/*" | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment