Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ';现场证书';对象没有属性';证书';使用AWS CDK_Python_Amazon Web Services_Aws Cdk_Infrastructure As Code - Fatal编程技术网

Python ';现场证书';对象没有属性';证书';使用AWS CDK

Python ';现场证书';对象没有属性';证书';使用AWS CDK,python,amazon-web-services,aws-cdk,infrastructure-as-code,Python,Amazon Web Services,Aws Cdk,Infrastructure As Code,我正在尝试将CloudFormation项目转移到AWS CDK。我从前端开始,它是一个静态站点,在一个S3存储桶前面使用CloudFront分发版和一个证书管理器证书 以下是我用于构建此堆栈的各种组件: 根 来自aws\U cdk导入核心的 从证书导入站点证书 从托管区导入HostedZone 从静态站点导入静态站点 AwscdkStack类(core.Stack): def uuu init uuuu(self,作用域:core.Construct,id:str,**kwargs)->无:

我正在尝试将CloudFormation项目转移到AWS CDK。我从前端开始,它是一个静态站点,在一个S3存储桶前面使用CloudFront分发版和一个证书管理器证书

以下是我用于构建此堆栈的各种组件:

根 来自aws\U cdk导入核心的

从证书导入站点证书
从托管区导入HostedZone
从静态站点导入静态站点
AwscdkStack类(core.Stack):
def uuu init uuuu(self,作用域:core.Construct,id:str,**kwargs)->无:
super()
self.hosted_zone=HostedZone(self,“HostedZone”)
self.certificate=站点证书(self,“站点证书”)
self.static\u site=StaticSite(
自“静态站点”,
托管分区=自托管分区,
证书=self.certificate
)
托管区
导入操作系统
从aws_cdk导入(
果心
aws_线路53作为线路53
)
类HostedZone(core.Construct):
定义初始化(self,作用域:core.Construct,id:str,**kwargs):
super()
self.hosted_zone=route53.HostedZone.from_hosted_zone_属性(
自我,“托管区”,
hosted_zone_id=os.environ.get(“hosted_zone_id”,“ABC123”),
zone_name=os.environ.get(“域名”、“mysite.com”)
)
证明书
导入操作系统
从aws_cdk导入(
果心
aws_认证管理员作为acm,
)
类站点证书(core.Construct):
def uuu init uuuu(self,作用域:core.Construct,id:str,**kwargs)->无:
super()
证书=acm.证书(
self,“站点证书”,
domain_name=f“*.{os.environ.get('domain_name','mysite.com')}”
)
静态站点 其中包含S3 bucket、policy和CloudFront分发(我可能想将它们分解成不同的文件)

导入操作系统
从aws_cdk导入(
aws_认证管理员作为acm,
aws_s3作为s3,
aws_cloudfront作为cloudfront,
aws_线路53作为线路53,
我作为我的律师,
果心
)
类静态站点(core.Construct):
定义初始化__(
自己
经营范围:核心。建设,
编号:str,,
托管分区:路由53.IHostedZone,
证书:acm.ICE证书,
**夸尔斯
)->无:
super()
self.static\u site\u bucket=s3.bucket(
赛尔夫,“静态SiteBucket”,
访问控制=s3.BucketAccessControl.PUBLIC\u读取,
bucket\u name=os.environ.get(“域名”、“mysite.com”),
删除策略=core.RemovalPolicy.DESTROY,
)
self.policy_语句=iam.policy语句(
actions=[“s3:GetObject”],
资源=[f“{self.static\u site\u bucket.bucket\u arn}/*”]
)
self.policy\u statement.add\u any\u principal()
self.static\u site\u policy\u document=iam.PolicyDocument(
语句=[self.policy_语句]
)
self.static\u site\u bucket.add\u to\u resource\u策略(
自我政策声明
)
self.distribution=cloudfront.CloudFrontWebDistribution(
self,“CloudFrontDistribution”,
原点配置=[
cloudfront.SourceConfiguration(
s3\u origin\u source=cloudfront.S3OriginConfig(
s3_bucket_source=self.static_site_bucket
),
行为=[cloudfront.Behavior(是否为默认值\u Behavior=True)]
)
],
alias_配置=cloudfront.AliasConfiguration(
acm\u cert\u ref=证书,
名字=[
os.environ.get(“域名”,“mysite.com”),
f“*.{os.environ.get('DOMAIN_NAME','mysite.com')}”]
),
错误配置=[
{
“错误代码”:403,
“errorCachingMinTtl”:0,
“响应代码”:200,
“responsePagePath”:“/index.html”
},
{
“错误代码”:404,
“errorCachingMinTtl”:0,
“响应代码”:200,
“responsePagePath”:“/index.html”
}
]
)
我还没有部署任何东西,我只是用
cdk-synth
在本地测试它。我一直在运行
cdk synth
,每次在我的cdk文件中添加内容,CloudFormation输出都与我当前用于部署项目的CloudFormation模板中的内容类似。运行
cdk sythn
时,出现以下错误:

AttributeError: 'SiteCertificate' object has no attribute 'certificate_arn'

我在这里使用了正确的构造吗?在我可以访问它的ARN之前,证书是否需要存在?我曾尝试使用
DnsValidatedCertificate
,但我得到了相同的错误。我还注意到此方法是实验性的,因此我不确定这是否与我看到此错误的原因有关。

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

self.certificate=SiteCertificate(self,“SiteCert”)
self.static\u site=StaticSite(
自“静态站点”,
托管分区=自托管分区,
证书=self.certificate
)
在StaticSite中,您引用了
证书。证书\u arn
,但SiteCertificate没有定义该属性

类站点证书(core.Construct):
def uuu init uuuu(self,作用域:core.Construct,id:str,**kwargs)->无:
super()
证书=acm.证书(
self,“站点证书”,
domain_name=f“*.{os.environ.get('domain_name','mysite.com')}”
)
//加上这个
self.certificate\u arn=cert.certificate\u arn