为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕雪6442864 2022-08-16 18:16:58
我正在尝试将 CloudFormation 项目迁移到 AWS CDK。我从前端开始,这是一个静态站点,在具有证书管理器证书的 S3 存储桶前面使用 CloudFront 分配。以下是我用来构建此堆栈的各种组件:根from aws_cdk import corefrom cert import SiteCertificatefrom hosted_zone import HostedZonefrom static_site import StaticSiteclass 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 osfrom 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 osfrom 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')}"        )
查看完整描述

1 回答

?
婷婷同学_

TA贡献1844条经验 获得超8个赞

这看起来您缺少属性定义SiteCertificate


        self.certificate = SiteCertificate(self, "SiteCert")


        self.static_site = StaticSite(

            self, 'StaticSite',

            hosted_zone=self.hosted_zone,

            certificate=self.certificate

        )

在 StaticSite 中引用,但 SiteCertificate 没有定义该属性。certificate.certificate_arn


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')}"

        )

        // Add this

        self.certificate_arn = cert.certificate_arn

或者从 acm 继承。CeritificateSiteCertificate


class 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专家,所以我可能错过了一些东西。


查看完整回答
反对 回复 2022-08-16
  • 1 回答
  • 0 关注
  • 101 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号