How to Create CloudFront on Amazon Web Service

Amazon CloudFront is a content delivery network operated by Amazon Web Services. Content delivery networks provide a globally-distributed network of proxy servers that cache content, such as web videos or other bulky media, more locally to consumers, thus improving access speed for downloading the content.

CloudFront works seamlessly with any AWS origin, such as Amazon S3, Amazon EC2, Elastic Load Balancing, or with any custom HTTP origin. You can customize your content delivery through CloudFront using the secure and programmable edge computing features CloudFront Functions and AWS Lambda@Edge.

 

  • Login to aws portal.
  • Click on Services.

 

Fig 1

 

  • Under Networking & Content Delivery select CloudFront.

 

Fig 2

 

  • Click on Create Distribution.

 

Fig. 3

 

  • Click on Get Started.

 

Fig. 4

 

  • Specify the domain name for your origin – the Amazon S3 bucket, AWS MediaPackage channel endpoint, AWS MediaStore container endpoint, or web server from which you want CloudFront to get your web content.
  • Provide Origin Path.If you want CloudFront to request your content from a directory in your Amazon S3 bucket or your custom origin,
  • Provide custom header keys name and values you specify here will be included in every request to this origin. If a header was already supplied in the client request, it is overridden.
  • Set Viewer Protocol policy.If you want CloudFront to allow viewers to access your web content using either HTTP or HTTPS.
  • Set Allowed HTTP methods you want to allow for this cache behavior.

 

Fig. 4

 

 

Fig. 6

 

  • Enable this option to use Smooth Streaming to stream a live event, unless your server uses Microsoft IIS. CloudFront cannot use a Microsoft IIS Server as an origin if you enable Smooth Streaming here.
  • Choose whether you want CloudFront to require viewers to access your content using signed URLs or signed cookies.
  • Choose whether you want CloudFront to automatically compress content when the viewer requests it (indicated in the Accept-Encoding header in the viewer request).
  • Select an edge function to associate with this cache behavior, and the CloudFront event that invokes the function.
  • Enable real-time logs then provide real-time logs name.

 

Fig. 7

 

  • Select HTTP/2,HTTP/1.1 & HTTP/1.0 support HTTP versions.

 

Fig. 8

 

  • Enable standard logging to receive logs of every viewer request sent to your distribution. Log files are delivered to the Amazon S3 bucket.
  • Leave all other settings.
  • Click on create distribution.

 

Fig 9

 

  • After sometime New CloudFront Distribution created successfully.

 

Fig 10

 

 

Create CloudFront Distribution using Shell

To create a CloudFront distribution

aws cloudfront create-distribution –origin-domain-name awsexamplebucket.s3.amazonaws.com

We can provide the distribution configuration in a JSON file, as shown in the following example:

aws cloudfront create-distribution  –distribution-config /path/of/dist-config.json-file.

The file dist-config.json is a JSON format is given below:

{
“CallerReference”: “cli-example”,
“Aliases”: {
“Quantity”: 0
},
“DefaultRootObject”: “index.html”,
“Origins”: {
“Quantity”: 1,
“Items”: [
{
“Id”: “awsexamplebucket.s3.amazonaws.com-cli-example”,
“DomainName”: “awsexamplebucket.s3.amazonaws.com”,
“OriginPath”: “”,
“CustomHeaders”: {
“Quantity”: 0
},
“S3OriginConfig”: {
“OriginAccessIdentity”: “”
}
}
]
},
“OriginGroups”: {
“Quantity”: 0
},
“DefaultCacheBehavior”: {
“TargetOriginId”: “awsexamplebucket.s3.amazonaws.com-cli-example”,
“ForwardedValues”: {
“QueryString”: false,
“Cookies”: {
“Forward”: “none”
},
“Headers”: {
“Quantity”: 0
},
“QueryStringCacheKeys”: {
“Quantity”: 0
}
},
“TrustedSigners”: {
“Enabled”: false,
“Quantity”: 0
},
“ViewerProtocolPolicy”: “allow-all”,
“MinTTL”: 0,
“AllowedMethods”: {
“Quantity”: 2,
“Items”: [
“HEAD”,
“GET”
],
“CachedMethods”: {
“Quantity”: 2,
“Items”: [
“HEAD”,
“GET”
]
}
},
“SmoothStreaming”: false,
“DefaultTTL”: 86400,
“MaxTTL”: 31536000,
“Compress”: false,
“LambdaFunctionAssociations”: {
“Quantity”: 0
},
“FieldLevelEncryptionId”: “”
},
“CacheBehaviors”: {
“Quantity”: 0
},
“CustomErrorResponses”: {
“Quantity”: 0
},
“Comment”: “”,
“Logging”: {
“Enabled”: false,
“IncludeCookies”: false,
“Bucket”: “”,
“Prefix”: “”
},
“PriceClass”: “PriceClass_All”,
“Enabled”: true,
“ViewerCertificate”: {
“CloudFrontDefaultCertificate”: true,
“MinimumProtocolVersion”: “TLSv1”,
“CertificateSource”: “cloudfront”
},
“Restrictions”: {
“GeoRestriction”: {
“RestrictionType”: “none”,
“Quantity”: 0
}
},
“WebACLId”: “”,
“HttpVersion”: “http2”,
“IsIPV6Enabled”: true
}

 

Leave a Reply