“SiteCertificate”对象在 AWS CDK 中没有属性

我正在尝试将 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')}"

        )


慕雪6442864
浏览 102回答 1
1回答

婷婷同学_

这看起来您缺少属性定义SiteCertificate        self.certificate = SiteCertificate(self, "SiteCert")        self.static_site = StaticSite(            self, 'StaticSite',            hosted_zone=self.hosted_zone,            certificate=self.certificate        )在 StaticSite 中引用,但 SiteCertificate 没有定义该属性。certificate.certificate_arnclass 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')}"        )        // Add this        self.certificate_arn = cert.certificate_arn或者从 acm 继承。CeritificateSiteCertificateclass SiteCertificate(acm.Certificate):    def __init__(self, scope: core.Construct) -> None:        super().__init__(scope, "SiteCertificate",            domain_name=f"*.{os.environ.get('DOMAIN_NAME', 'mysite.com')}")我不是Python专家,所以我可能错过了一些东西。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python