Skip to content

Instantly share code, notes, and snippets.

@pataiji
Last active February 29, 2020 22:46
Show Gist options
  • Save pataiji/6a4206af288da466619d to your computer and use it in GitHub Desktop.
Save pataiji/6a4206af288da466619d to your computer and use it in GitHub Desktop.
S3 + CloudFront で特定のパスへのアクセスをリダイレクトさせる
  1. S3の'Static Website Hosting'を有効にする
  2. 'Edit Redirection Rules'を編集する
  3. 'bucket policy'を編集する
  4. CLoudFrontのOriginにS3の'Static Website Hosting'のEndpointを指定する
{
"Version": "2008-10-17",
"Id": "PolicyForCloudFrontPrivateContent",
"Statement": [
{
"Sid": "1",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::bucket-name/*",
"Condition": {
"StringEquals": {
"aws:UserAgent": "Amazon CloudFront"
}
}
}
]
}
<RoutingRules>
<RoutingRule>
<Condition>
<KeyPrefixEquals>source_path/</KeyPrefixEquals>
</Condition>
<Redirect>
<Protocol>https</Protocol>
<HostName>redirect domain</HostName>
<ReplaceKeyWith>redirect path</ReplaceKeyWith>
<HttpRedirectCode>301</HttpRedirectCode>
</Redirect>
</RoutingRule>
</RoutingRules>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment