Creating DNS records

Follow these steps to create your DNS records:

  1. Now that we have a hosted zone, we can go ahead and create DNS records for it. For this, we use the AWS resource type known as AWS::Route53::RecordSetGroup.
  2. We're going to create an A record for our domain's root/apex entry, and we'll make it an alias. This alias will be configured to point to the AWS endpoint for S3-hosted websites in the particular region we choose to run this CloudFormation in.
  3. To achieve region portability in our template, we'll use a mapping to provide all the endpoints. The values in this map are published by AWS in their API endpoints documentation. You won't need to look these up, however, because our code sample provides the most up-to-date endpoints (at the time of writing). The endpoints tend not to change, but the list obviously grows when AWS adds more regions.
  4. The mapping will look like this:
        us-east-1: 
S3HostedZoneID: Z3AQBSTGFYJSTF
S3AliasTarget: s3-website-us-east-1.amazonaws.com
us-east-2:
S3HostedZoneID: Z2O1EMRO9K5GLX
S3AliasTarget: s3-website.us-east-2.amazonaws.com

We'll also need a CNAME for wwwwhich will point at our WWWBucket so that redirection can take place. The final resource for our DNS records will look like this:

        DNSRecords: 
Type: "AWS::Route53::RecordSetGroup"
Properties:
HostedZoneId:
Ref: DNSHostedZone
RecordSets:
- Name:
Ref: DomainName
Type: A
AliasTarget:
HostedZoneId:
Fn::FindInMap: [ RegionMap, Ref: "AWS::Region",
S3HostedZoneID ]
DNSName:
Fn::FindInMap: [ RegionMap, Ref: "AWS::Region",
S3AliasTarget ]
- Name:
Fn::Join: [ ., [ www, Ref: DomainName ] ]
Type: CNAME
TTL: 300
ResourceRecords:
- Fn::GetAtt: WWWBucket.DomainName
  1. Now, we're ready for launch. It's time to create our CloudFormation stack. You can download the complete template file from the GitHub repository for this book. Create the stack using the following CLI command:
      aws cloudformation create-stack  
--stack-name static-website-1
--template-body file://03-01-Website.yaml
--parameters
ParameterKey=DomainName,ParameterValue=<your-domain-name>

Once the stack completes, you will be able to add some content to your new website.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset