Created
July 11, 2017 03:05
-
-
Save ahmetkizilay/4fa8df305bd4aa30a1d8f92c68137626 to your computer and use it in GitHub Desktop.
Setting up S3 Hosting over http custom domain
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
{ | |
"Statement": [ | |
{ | |
"Effect": "Allow", | |
"Principal": "*", | |
"Action": "s3:GetObject", | |
"Resource": "arn:aws:s3:::kizil.io/*" | |
} | |
] | |
} |
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
{ | |
"CallerReference": "2017-06-19 00:22:00", | |
"Aliases": { | |
"Quantity": 2, | |
"Items": [ | |
"kizil.io", | |
"www.kizil.io" | |
] | |
}, | |
"DefaultRootObject": "index.html", | |
"Origins": { | |
"Quantity": 1, | |
"Items": [ | |
{ | |
"Id": "s3-kizil.io", | |
"DomainName": "kizil.io.s3.amazonaws.com", | |
"S3OriginConfig": { | |
"OriginAccessIdentity": "" | |
} | |
} | |
] | |
}, | |
"ViewerCertificate": { | |
"CloudFrontDefaultCertificate": false, | |
"ACMCertificateArn": "arn:aws:acm:us-east-1:255349765101:certificate/64afaa8d-7f49-4dfb-a677-f55112da9ffb", | |
"SSLSupportMethod": "sni-only", | |
"MinimumProtocolVersion": "TLSv1", | |
"CertificateSource": "acm" | |
}, | |
"CustomErrorResponses": { | |
"Quantity": 1, | |
"Items": [ | |
{ | |
"ErrorCode": 404, | |
"ResponsePagePath": "/404.html", | |
"ResponseCode": "404", | |
"ErrorCachingMinTTL": 300 | |
} | |
] | |
}, | |
"DefaultCacheBehavior": { | |
"TargetOriginId": "s3-kizil.io", | |
"ViewerProtocolPolicy": "redirect-to-https", | |
"AllowedMethods": { | |
"Quantity": 2, | |
"Items": ["GET", "HEAD"] | |
}, | |
"ForwardedValues": { | |
"Headers": { | |
"Quantity": 0 | |
}, | |
"Cookies": { | |
"Forward": "none" | |
}, | |
"QueryString": true | |
}, | |
"TrustedSigners": { | |
"Enabled": false, | |
"Quantity": 0 | |
}, | |
"MinTTL": 0 | |
}, | |
"Comment": "", | |
"Enabled": true | |
} |
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
export BUCKET_NAME=kizil.io | |
# create the bucket | |
aws \ | |
--profile personal \ | |
--region us-east-1 \ | |
s3api create-bucket \ | |
--acl public-read \ | |
--bucket $BUCKET_NAME | |
# set policy to make it public readonly | |
aws \ | |
--profile personal \ | |
--region us-east-1 \ | |
s3api put-bucket-policy \ | |
--bucket $BUCKET_NAME \ | |
--policy file://bucket-policy.json | |
# create cloudfront distribution | |
aws \ | |
--profile personal \ | |
--region us-east-1 \ | |
cloudfront create-distribution \ | |
--distribution-config file://cloudfront-config.json | |
# configure record sets to serve the distribution over custom domain | |
aws \ | |
--profile personal \ | |
--region us-east-1 \ | |
route53 change-resource-record-sets \ | |
--hosted-zone-id Z2VQTJ5DTVI7XB \ | |
--change-batch file://record-set-config.json |
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
{ | |
"Comment": "some comment", | |
"Changes": [ | |
{ | |
"Action": "CREATE", | |
"ResourceRecordSet": { | |
"Name": "kizil.io.", | |
"Type": "A", | |
"AliasTarget": { | |
"HostedZoneId": "Z2FDTNDATAQYW2", | |
"DNSName": "d2bhsy5q2tl84k.cloudfront.net", | |
"EvaluateTargetHealth": false | |
} | |
} | |
}, | |
{ | |
"Action": "CREATE", | |
"ResourceRecordSet": { | |
"Name": "www.kizil.io.", | |
"Type": "A", | |
"AliasTarget": { | |
"HostedZoneId": "Z2FDTNDATAQYW2", | |
"DNSName": "d2bhsy5q2tl84k.cloudfront.net", | |
"EvaluateTargetHealth": false | |
} | |
} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment