AliasRecord for CloudFront distribution

Create AliasRecord for CloudFront distribution using CloudFormation

8

Votes

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "CloudFront Stack with AliasRecord",
  "Outputs": {
    "Distribution": {
      "Value": { "Ref": "Distribution" }
    }
  },
  "Parameters": {
    "DnsName": {
      "Description": "My DNS name",
      "Type": "String"
    },
    "DnsZoneName": {
      "Description": "My DNS zone",
      "Type": "String"
    },
    "OriginDnsName": {
      "Description": "DNS of the web origin",
      "Type": "String"
    }
  },
  "Resources": {
    "Distribution": {
      "Properties": {
        "DistributionConfig": {
          "Aliases": [ { "Ref": "DnsName" } ],
          "DefaultCacheBehavior": {
            "ForwardedValues": {
              "QueryString": "true"
            },
            "TargetOriginId": "Origin",
            "ViewerProtocolPolicy": "allow-all"
          },
          "Enabled": "true",
          "Origins": [
            {
              "CustomOriginConfig": {
                "OriginProtocolPolicy": "match-viewer"
              },
              "DomainName": { "Ref": "OriginDnsName" },
              "Id": "Origin"
            }
          ]
        }
      },
      "Type": "AWS::CloudFront::Distribution"
    },
    "DnsRecord": {
      "Properties": {
        "AliasTarget": {
          "DNSName": { "Fn::GetAtt": [ "Distribution", "DomainName" ] },
          "HostedZoneId": "Z2FDTNDATAQYW2"
        },
        "HostedZoneName": { "Ref": "ZoneName" },
        "Name": { "Ref": "DnsName" },
        "Type": "A"
      },
      "Type": "AWS::Route53::RecordSet"
    }
  }
}

Vote Here

You must earn at least 1 vote on your snippets to be allowed to vote

Terms Of Use

Privacy Policy

Featured snippets are MIT license

Gears & Masters

Advertise

DevOpsnipp.com © 2020

medium.png