cloudformation.json 3.55 KB
Newer Older
Adam Hawkins's avatar
Adam Hawkins committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "Blog: S3 bucket, Cloudfront, & DNS",
  "Parameters": {
    "Subdomain": {
      "Type": "String",
      "Default": "blog"
    },
    "TLD": {
      "Type": "String",
      "Default": "slashdeploy.com"
    }
  },
  "Resources": {
    "Bucket": {
      "Type": "AWS::S3::Bucket",
      "Properties": {
        "BucketName": "slashdeploy-blog",
        "WebsiteConfiguration": {
          "ErrorDocument": "error.html",
          "IndexDocument": "index.html"
        }
      }
    },
    "Policy": {
      "Type": "AWS::S3::BucketPolicy",
      "Properties": {
        "Bucket": { "Ref": "Bucket" },
        "PolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [{
            "Sid": "PublicReadGetObject",
            "Effect": "Allow",
            "Principal": "*",
            "Action": [ "s3:GetObject" ],
            "Resource": [{
              "Fn::Join": [ "", [
                "arn:aws:s3:::",
                { "Ref": "Bucket" },
                "/*"
              ]]
            }]
          }]
        }
      }
    },
    "Distribution": {
      "Type": "AWS::CloudFront::Distribution",
      "Properties": {
        "DistributionConfig": {
          "Aliases": [
            {
              "Fn::Join": [ ".", [
                { "Ref": "Subdomain" },
                { "Ref": "TLD" }
              ]]
            }
          ],
          "Comment": "Blog",
          "DefaultRootObject": "index.html",
          "Enabled": "true",
          "Origins": [
            {
              "Id": "blog-s3-website",
              "DomainName": {
                "Fn::Join": [ ".", [
                  { "Ref": "Bucket" },
                  { "Fn::Join": [ "-", [ "s3-website", { "Ref": "AWS::Region" } ]] },
                  "amazonaws.com"
                ]]
              },
              "CustomOriginConfig": {
                "OriginProtocolPolicy": "http-only"
              }
            }
          ],
          "DefaultCacheBehavior": {
78
            "DefaultTTL": 300,
79
            "Compress": "true",
Adam Hawkins's avatar
Adam Hawkins committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
            "ForwardedValues": {
              "Cookies": {
                "Forward": "none"
              },
              "QueryString": "false"
            },
            "TargetOriginId": "blog-s3-website",
            "ViewerProtocolPolicy": "allow-all"
          },
          "PriceClass": "PriceClass_All",
          "ViewerCertificate": {
            "CloudFrontDefaultCertificate": "true"
          }
        }
      }
    },
    "DNS": {
      "Type": "AWS::Route53::RecordSet",
      "Properties": {
        "HostedZoneName": {
          "Fn::Join": [ "", [ { "Ref": "TLD" }, "." ] ]
        },
        "Name": {
          "Fn::Join": [ ".", [
            { "Ref": "Subdomain" },
            { "Ref": "TLD" }
          ]]
        },
        "Type": "A",
        "AliasTarget": {
          "HostedZoneId": "Z2FDTNDATAQYW2",
          "DNSName": { "Fn::GetAtt": [ "Distribution", "DomainName" ] }
112 113
        },
        "Comment": "CloudFront Distrobution alias"
Adam Hawkins's avatar
Adam Hawkins committed
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
      }
    }
  },
  "Outputs": {
    "Bucket": {
      "Description": "S3 Bucket",
      "Value": { "Ref": "Bucket" }
    },
    "OriginURL": {
      "Description": "S3 Website URL",
      "Value": { "Fn::GetAtt": [ "Bucket", "WebsiteURL" ] }
    },
    "DistributionURL": {
      "Description": "Cloudfront URL",
      "Value": { "Fn::GetAtt": [ "Distribution", "DomainName" ] }
Adam Hawkins's avatar
Adam Hawkins committed
129 130 131 132 133 134 135
    },
    "PublicURL": {
      "Description": "Public URL",
      "Value": { "Fn::Join": [ ".", [
        { "Ref": "Subdomain" },
        { "Ref": "TLD" }
      ]]}
Adam Hawkins's avatar
Adam Hawkins committed
136 137 138
    }
  }
}