AWS: Cloudfront Viewer Policy
--- Python code that uses the `boto3` library to update the viewer policy of a CloudFront distribution to redirect HTTP requests to HTTPS:
import boto3
def update_cloudfront_distribution(distribution_id):
client = boto3.client('cloudfront')
response = client.get_distribution_config(Id=distribution_id)
distribution_config = response['DistributionConfig']
distribution_config['DefaultCacheBehavior']['ViewerProtocolPolicy'] = 'redirect-to-https'
response = client.update_distribution(DistributionConfig=distribution_config, Id=distribution_id, IfMatch=response['ETag'])
print("Distribution updated with HTTPS redirection")
update_cloudfront_distribution(<<Distribution ID>>)
Make sure to replace `'<<Distribution ID>>` with the actual ID of the CloudFront distribution you want to update. ViewerProtocolPolicy 'redirect-to-https', and after the modification update the distribution with the modified configuration.
Cloudfront WebAcl ID short note and how to change WebAcl ID of a particular Cloudfront Distribution using Boto3 module will be discussed in my next week's blog.
Thank you 🙂
Comments
Post a Comment