The CloudFormation template

Unlike with the CLI commands, there is no shorthand way to create a CloudFront distribution with a CloudFormation template without specifying the distribution config parameters. I will, however, only add the essential parameters in this recipe:

  1. Start the template with the template version and a description (optional).
  2. Create a resource of the type AWS::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 for S3 Bucket'
DefaultRootObject: index.html
DefaultCacheBehavior:
TargetOriginId: myS3Origin
ForwardedValues:
QueryString: 'false'
Cookies:
Forward: none
ViewerProtocolPolicy: allow-all
  1. Add an Outputs section to return the CloudFront distribution ID and the CloudFront domain name:
Outputs:
CloudFrontDistributionId:
Value: !Ref MyCloudFrontDistribution
Description: 'CloudFront distribution id'
CloudFrontDomain:
Value: !GetAtt MyCloudFrontDistribution.DomainName
Description: 'CloudFront distribution domain name'
  1. Execute the stack, using the create-stack command.

It will take some time for the distribution to be created. You can check the status by using the describe-stacks command. Once it has completed, you will get a response with the Outputs section, as follows:

  1. Execute the CloudFront domain name in a browser, and verify whether the S3 static website has loaded:
..................Content has been hidden....................

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