AWS CLI commands

  1. Create a CloudFront distribution config JSON file. Specify a caller reference to uniquely reference our request, as follows:
{
"CallerReference": "qnatime-distribution-2019-01-12-07-45",

Specify the domains that will point to this CloudFront domain, as follows:

"Aliases": {
"Quantity": 2,
"Items": ["qnatime.net", "www.qnatime.net"]
},

You can only add a CNAME or alias to your domain record for CloudFront domain if it is added as Aliases for that CloudFront domain.

Specify the default root object and the origin details, as follows:

"DefaultRootObject": "index.html",
"Origins": {
"Quantity": 1,
"Items": [
{
"Id": "my-origin",
"DomainName": "qnatime.com.s3.amazonaws.com",
"S3OriginConfig": {
"OriginAccessIdentity": ""
}
}
]
},

You can have multiple CloudFront distributions pointing to the same bucket. 

Specify the other mandatory parameters, DefaultCacheBehaviour, Comment, and Enabled, as follows:

"DefaultCacheBehavior": {
"TargetOriginId": "my-origin",
"ForwardedValues": {
"QueryString": true,
"Cookies": {
"Forward": "none"
}
},
"TrustedSigners": {
"Enabled": false,
"Quantity": 0
},
"ViewerProtocolPolicy": "allow-all",
"MinTTL": 3600
},
"Comment": "",
"Enabled": true
}
  1. Create the distribution with the preceding config JSON file, as follows:
aws cloudfront create-distribution 
--distribution-config file://resources/distribution-config.json
--profile admin

This will return immediately with a response, including the Etag, Id, and other defaults, as follows:

The complete response has not been shown.

It might take some time for the status to get changed to Deployed. You can check the status by using the aws cloud-formation get-distribution command. Once the status turns to Deployed, you can run the CloudFront domain from a browser, and check whether you can see the results from the qnatime.com bucket.

  1. To create DNS A records for a domain, record we need to first create a change resource record sets JSON file as below and then execute it. First, create a change record set for the naked domain (qnatime.net):
{
"Comment": "change batch request for qnatime.net",
"Changes": [
{
"Action": "CREATE",
"ResourceRecordSet": {
"Name": "qnatime.net",
"Type": "A",
"AliasTarget": {
"HostedZoneId": "Z2FDTNDATAQYW2",
"DNSName": "d1obzjrl8ac1no.cloudfront.net",
"EvaluateTargetHealth": false
}
}
},

DNSName is the domain name of your CloudFront distribution. You have to specify the hosted zone name for the domain. This is the domain name, followed by a dot. For CloudFront distribution domains, we use a constant hosted zone ID: Z2FDTNDATAQYW2

Similarly, add a change record for the WWW sub-domain. You can also create a CNAME record for the sub-domain.

  1. Execute the change-resource-record-sets sub-command with the preceding JSON file, in order to create the DNS A records:
aws route53 change-resource-record-sets 
--hosted-zone-id Z3G50MON7IDA18
--change-batch file://resources/change-resource-record-sets.json
--profile admin

Here, hosted-zone-id is the ID of the HostedZone for qnatime.net. This command will immediately return a response, with the status as PENDING:

You can check the status by using the aws route53 get-change command, until it changes to INSYNC:

  1. Execute qnatime.net to obtain the following: 

Executing www.qnatime.net will produce the following result:

As we can see, we no longer have the restriction of using the same S3 bucket name and domain name. Note that we are not using the WWW redirect bucket (www.qnatime.com). Here, www.qname.net is also pointing to the same CloudFront domain, and there is no redirection from the bucket to the naked domain bucket behind the scenes. 

If there is a Not Secure message in the browser, this is because we are using an HTTP request, and there are no valid certificates for our domain.
..................Content has been hidden....................

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