The CloudFront distribution stack

Prepare a CloudFormation template using the following components:

  1. Start the template with the template version and a description (optional).
  2. We will define a Parameters section, to accept a comma-separated list of domain name aliases:
Parameters:
DomainNameAliases:
Description: Domain name aliases for your website (quizzercloud.com,www.quizzercloud.com)
Type: CommaDelimitedList
  1. In the Resources section, we will define our CloudFront distribution:
Resources:
MyCloudFrontDistribution:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Origins:
- DomainName: quizzer.cloud.s3.amazonaws.com
Id: myS3Origin
S3OriginConfig:
OriginAccessIdentity: ''
Enabled: 'true'
Comment: 'CloudFront Distribution with Domain'
DefaultRootObject: index.html
Aliases: !Ref DomainNameAliases
DefaultCacheBehavior:
TargetOriginId: myS3Origin
ForwardedValues:
QueryString: 'false'
Cookies:
Forward: none
ViewerProtocolPolicy: allow-all

Note that we can reference the parameter DomainNameAliases as a list.

  1. We will also create an Outputs section, to return the CloudFront distribution ID and the domain name. We will also export the domain name and then import it later, into our RecordSet stack:
Outputs:
CloudFrontDistributionId:
Value: !Ref MyCloudFrontDistribution
Description: 'CloudFront distribution id'
CloudFrontDomain:
Value: !GetAtt MyCloudFrontDistribution.DomainName
Description: 'CloudFront distribution domain name'
Export:
Name: CloudFrontDomainName
  1. Create the stack. We will first create a JSON file to pass the parameter string, since passing a list through the CLI may require additional workarounds in a number of command prompts:
[
{
"ParameterKey": "DomainNameAliases",
"ParameterValue": "quizzercloud.com,www.quizzercloud.com"
}

]

Execute the stack, specifying the preceding parameters in JSON:

aws cloudformation create-stack 
--stack-name mycloudfrontstackwithdomain
--template-body file://resources/create-cloud-front-distribution-with-domain.yml
--parameters file://resources/create-cloud-front-parameters.json
--region ap-south-1
--profile admin

After executing the create-stack command, check the status by using the describe-stacks sub-command. Once it has completed successfully, it should return a response with the following Outputs section:

Note that the complete describe-stacks output is not shown here, but only the Outputs section.

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

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