不同 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 认证凭据,以便能够成功运行此代码示例。

相关内容

热门资讯

科技通报!佛手在线大菠萝辅助(... 科技通报!佛手在线大菠萝辅助(辅助挂)真是存在有挂(确实有挂辅助器)1、上手简单,内置详细流程视频教...
玩家攻略!cloudpoker... 玩家攻略!cloudpoker作弊(辅助挂)真是是真的有挂(有挂技术辅助软件)1、进入到是否有挂之后...
科技通报!wpk可以作弊吗(辅... 科技通报!wpk可以作弊吗(辅助挂)真是有挂(有挂解密辅助软件)1、起透看视 辅助软件价格2、随意选...
发现玩家!htx矩阵wepok... 发现玩家!htx矩阵wepoker辅助(辅助挂)其实存在有挂(有挂规律辅助方法)1)免费钻石:进一步...
分享一款!hhpoker脚本(... 分享一款!hhpoker脚本(辅助挂)好像是有挂(有挂秘籍辅助脚本)1、起透看视 辅助软件价格2、随...
科技新动态!wepoker辅助... 科技新动态!wepoker辅助插件功能(辅助挂)其实真的是有挂(揭秘有挂辅助工具)1、实时透视辅助更...
一分钟了解!约局吧德州真的有透... 一分钟了解!约局吧德州真的有透视挂吗(辅助挂)真是真的是有挂(真的有挂辅助插件)1、一分钟了解!约局...
实测教程!wpk安卓下载辅助(... 实测教程!wpk安卓下载辅助(辅助挂)真是有挂(有挂功能辅助器)1、起透看视 辅助软件价格2、随意选...
玩家必备教程!aapoker能... 玩家必备教程!aapoker能控制牌吗(辅助挂)一直真的有挂(有挂细节辅助技巧)1、首先打开辅助器下...
玩家科普!wepoker辅助器... 玩家科普!wepoker辅助器(辅助挂)好像真的是有挂(有挂透视辅助方法)1、用户打开应用后不用登录...