我正在尝试将 CloudFormation 项目迁移到 AWS CDK。我从前端开始,这是一个静态站点,在具有证书管理器证书的 S3 存储桶前面使用 CloudFront 分配。
以下是我用来构建此堆栈的各种组件:
根
from aws_cdk import core
from cert import SiteCertificate
from hosted_zone import HostedZone
from static_site import StaticSite
class AwscdkStack(core.Stack):
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
self.hosted_zone = HostedZone(self, "HostedZone")
self.certificate = SiteCertificate(self, "SiteCert")
self.static_site = StaticSite(
self, 'StaticSite',
hosted_zone=self.hosted_zone,
certificate=self.certificate
)
托管区域
import os
from aws_cdk import (
core,
aws_route53 as route53
)
class HostedZone(core.Construct):
def __init__(self, scope: core.Construct, id: str, **kwargs):
super().__init__(scope, id, **kwargs)
self.hosted_zone = route53.HostedZone.from_hosted_zone_attributes(
self, "hosted_zone",
hosted_zone_id=os.environ.get("HOSTED_ZONE_ID", "ABC123"),
zone_name=os.environ.get("DOMAIN_NAME", "mysite.com")
)
证书
import os
from aws_cdk import (
core,
aws_certificatemanager as acm,
)
class SiteCertificate(core.Construct):
def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
cert = acm.Certificate(
self, "SiteCertificate",
domain_name=f"*.{os.environ.get('DOMAIN_NAME', 'mysite.com')}"
)
婷婷同学_
相关分类