How to do it...

The first (and only) thing we need to do is configure a CloudFront distribution as shown in the following diagram:

  1. Create a new CloudFormation template and add the following code:
      AWSTemplateFormatVersion: '2010-09-09'
Parameters:
OriginDomainName:
Description: The hostname of your origin
(i.e. www.example.org.s3-website-ap-southeast-2.amazonaws.com)
Type: String
Aliases:
Description: Comma delimited list of aliases
(i.e. example.org,www.example.org)
Type: CommaDelimitedList
Resources:
DistributionALogBucket:
Type: AWS::S3::Bucket
DistributionA:
Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Origins:
- DomainName:
Ref: OriginDomainName
Id: OriginA
CustomOriginConfig:
OriginProtocolPolicy: http-only
Enabled: true
Logging:
IncludeCookies: false
Bucket:
Fn::GetAtt: DistributionALogBucket.DomainName
Prefix: cf-distribution-a
Aliases:
Ref: Aliases
DefaultCacheBehavior:
TargetOriginId: OriginA
ForwardedValues:
QueryString: false
ViewerProtocolPolicy: allow-all
PriceClass: PriceClass_100
Outputs:
DistributionDomainName:
Description: The domain name of the CloudFront Distribution
Value:
Fn::GetAtt: DistributionA.DomainName
LogBucket:
Description: Bucket where CloudFront logs will be stored
Value:
Ref: DistributionALogBucket
  1. Using the template we created above, go ahead and create your CloudFront distribution. Expect to wait around 20-25 minutes for this stack to finish creating. It takes a while for your distribution configuration to be pushed out to all the AWS CloudFront locations:
        aws cloudformation create-stack  
--stack-name cloudfont-cache-1
--template-body file://03-caching-a-website.yaml
--parameters
ParameterKey=OriginDomainName,ParameterValue=<your-domain-name>
ParameterKey=Aliases,ParameterValue='<alias-1>,<alias-2>'
..................Content has been hidden....................

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