CloudFront

 CloudFront


Amazon CloudFront is a content delivery network (CDN) that securely delivers data, videos, applications, and APIs to customers globally with low latency and high transfer speeds. Here is an example of how to create a CloudFront distribution using the AWS SDK for Python (boto3):

python


import boto3


cloudfront_client = boto3.client('cloudfront')


origin_domain_name = 'my-bucket.s3.amazonaws.com'


distribution_config = {

    'CallerReference': 'my-reference',

    'Origins': {

        'Quantity': 1,

        'Items': [

            {

                'Id': 'my-origin',

                'DomainName': origin_domain_name,

                'S3OriginConfig': {

                    'OriginAccessIdentity': ''

                }

            }

        ]

    },

    'DefaultCacheBehavior': {

        'TargetOriginId': 'my-origin',

        'ForwardedValues': {

            'QueryString': False

        },

        'ViewerProtocolPolicy': 'redirect-to-https',

        'MinTTL': 0

    },

    'Enabled': True,

    'Comment': 'An example distribution'

}


response = cloudfront_client.create_distribution(

    DistributionConfig=distribution_config

)


distribution_id = response['Distribution']['Id']


print(f"CloudFront distribution created with ID {distribution_id}")

This code creates a CloudFront distribution with a single origin that points to an S3 bucket. The distribution configuration includes a default cache behavior that redirects HTTP requests to HTTPS, with no query string forwarding. The distribution ID is printed to the console.

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...