不同 CloudFront 分发中的重复备用域名 (CNAMEs)
创始人
2025-01-08 05:30:22
0

在 CloudFront 中,您可以为不同分发配置相同的备用域名 (CNAME)。这样,当一个分发不可用时,请求将转发到备用域名上。

以下是使用 AWS SDK for Python (Boto3) 配置 CloudFront 分发的代码示例:

import boto3

def create_cloudfront_distribution():
    cloudfront_client = boto3.client('cloudfront')

    origin_domain = 'example-origin-domain.com'
    alternate_domains = ['example-cname1.com', 'example-cname2.com']
    distribution_comment = 'Example CloudFront Distribution'

    try:
        response = cloudfront_client.create_distribution(
            DistributionConfig={
                'CallerReference': 'example-caller-reference',
                'Comment': distribution_comment,
                'DefaultRootObject': 'index.html',
                'Enabled': True,
                'Origins': {
                    'Quantity': 1,
                    'Items': [
                        {
                            'DomainName': origin_domain,
                            'Id': 'example-origin',
                            'CustomOriginConfig': {
                                'HTTPPort': 80,
                                'HTTPSPort': 443,
                                'OriginProtocolPolicy': 'http-only',
                                'OriginSslProtocols': {
                                    'Quantity': 3,
                                    'Items': ['TLSv1', 'TLSv1.1', 'TLSv1.2']
                                }
                            }
                        }
                    ]
                },
                'Aliases': {
                    'Quantity': len(alternate_domains),
                    'Items': alternate_domains
                },
                'DefaultCacheBehavior': {
                    'TargetOriginId': 'example-origin',
                    'ForwardedValues': {
                        'QueryString': False,
                        'Cookies': {'Forward': 'none'},
                        'Headers': {'Quantity': 0},
                        'QueryStringCacheKeys': {'Quantity': 0}
                    },
                    'TrustedSigners': {'Enabled': False, 'Quantity': 0},
                    'ViewerProtocolPolicy': 'allow-all',
                    'MinTTL': 0
                },
                'PriceClass': 'PriceClass_100',
                'ViewerCertificate': {
                    'CloudFrontDefaultCertificate': True,
                    'MinimumProtocolVersion': 'TLSv1',
                    'CertificateSource': 'cloudfront'
                },
            }
        )
        print('CloudFront Distribution created successfully.')
        print('Distribution Id:', response['Distribution']['Id'])
        print('Distribution Domain Name:', response['Distribution']['DomainName'])
    except Exception as e:
        print('Error:', str(e))

create_cloudfront_distribution()

在上面的代码示例中,origin_domain 是主要的源域名,alternate_domains 是备用的 CNAME 域名列表。通过在 Aliases 字段中提供这些备用域名,您可以为 CloudFront 分发配置重复的备用域名。请确保在 DNS 上正确配置了这些备用域名的 CNAME 记录。

此示例代码使用 AWS SDK for Python (Boto3) 创建了一个 CloudFront 分发,并指定了主要的源域名和备用的 CNAME 域名。如果创建成功,它会打印出分发的 ID 和域名。

请确保已正确安装 AWS SDK for Python (Boto3) 并正确配置 AWS 认证凭据,以便能够成功运行此代码示例。

相关内容

热门资讯

记者揭秘!智星菠萝辅助(透视辅... 记者揭秘!智星菠萝辅助(透视辅助)拱趴大菠萝辅助神器,扑克教程(有挂细节);模式供您选择,了解更新找...
一分钟揭秘!约局吧能能开挂(透... 一分钟揭秘!约局吧能能开挂(透视辅助)hhpoker辅助靠谱,2024新版教程(有挂教学);约局吧能...
透视辅助!wepoker模拟器... 透视辅助!wepoker模拟器哪个好用(脚本)hhpoker辅助挂是真的,科技教程(有挂技巧);囊括...
透视代打!hhpkoer辅助器... 透视代打!hhpkoer辅助器视频(辅助挂)pokemmo脚本辅助,2024新版教程(有挂教程);风...
透视了解!约局吧德州真的有透视... 透视了解!约局吧德州真的有透视挂(透视脚本)德州局HHpoker透视脚本,必胜教程(有挂分析);亲,...
六分钟了解!wepoker挂底... 六分钟了解!wepoker挂底牌(透视)德普之星开辅助,详细教程(有挂解密);德普之星开辅助是一种具...
9分钟了解!wpk私人辅助(透... 9分钟了解!wpk私人辅助(透视)hhpoker德州透视,插件教程(有挂教学);风靡全球的特色经典游...
推荐一款!wepoker究竟有... 推荐一款!wepoker究竟有透视(脚本)哈糖大菠萝开挂,介绍教程(有挂技术);囊括全国各种wepo...
每日必备!wepoker有人用... 每日必备!wepoker有人用过(脚本)wpk有那种辅助,线上教程(有挂规律);wepoker有人用...
玩家必备教程!wejoker私... 玩家必备教程!wejoker私人辅助软件(脚本)哈糖大菠萝可以开挂,可靠技巧(有挂神器)申哈糖大菠萝...