AWS: CloudFront Distribution Viewer Policy




What is CloudFront ?

-- CloudFront is a content delivery network service provided by AWS. It helps deliver static and dynamic web content, including videos, images, and applications, to end-users with low latency and high transfer speeds.


-- CloudFront uses a global network of edge locations to cache and serve content from the location closest to the end-user, reducing the distance and improving overall performance. It also offers features like SSL/TLS encryption, DDoS protection, and integration with other AWS services, making it a popular choice for accelerating content delivery across the globe.



Example -- To change the CloudFront viewer policy using boto3


-- CloudFront Distribution Viewer Policy:

CloudFront allows you to control access to your content by specifying a viewer policy. The viewer policy defines who can access your content based on various criteria such as IP address, HTTP headers, cookies, and more. It helps you restrict access and implement fine-grained access controls for your CloudFront distributions.


Changing Viewer Policy using Boto3:

   import boto3

   # Set up the CloudFront client

   cloudfront_client = boto3.client('cloudfront')

   distribution_id = '<<Any ID>>'

   response = cloudfront_client.get_distribution_config(

       Id=distribution_id

   )

   distribution_config = response['DistributionConfig']

   distribution_config['DefaultCacheBehavior']['ViewerProtocolPolicy'] = 'https-only'

   response = cloudfront_client.update_distribution(

       DistributionConfig=distribution_config,

       Id=distribution_id,

       IfMatch=response['ETag']

   )


That's it! CloudFront distribution viewer policy is successfully updated.




-- Please note that making changes to CloudFront distributions can have an impact on the availability and performance of your content delivery, so it's essential to test and validate any modifications before applying them to production environments.


Will discuss the case study on S3 tags with an example in next week's Blog.

Thank You

Comments

Popular posts from this blog

Data analysis with R

Machine learning in Python

AWS: Config Rule & Compliance Check