AWS CDK Python如何正确引用使用自定义资源创建的托管区域

2024-09-28 22:25:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下代码

   HZ_on_create = custom_resource.AwsSdkCall(
            service='Route53',
            action='createHostedZone',
            physical_resource_id=custom_resource.PhysicalResourceId.from_response(
                "HostedZone.Id"),
            parameters={
                "CallerReference": environment + "hosted zone" + str(time.time()),
                "Name": environment+".bbot.menu",
                "DelegationSetId": "N06079012Q8954F8DG91Y",
                "HostedZoneConfig": {
                    "Comment": "n/a",
                    "PrivateZone": False
                }
            })

        HZ_on_update = custom_resource.AwsSdkCall(
            service='Route53',
            action='createHostedZone',
            physical_resource_id=custom_resource.PhysicalResourceId.from_response(
                "HostedZone.Id"),
            parameters={
                "CallerReference": environment + "hosted zone" + str(time.time()),
                "Name": environment+".bbot.menu",
                "DelegationSetId": "N06079012Q8954F8DG91Y",
                "HostedZoneConfig": {
                    "Comment": "n/a",
                    "PrivateZone": False
                }
            })

        HZ_with_delegation = custom_resource.AwsCustomResource(
            self,
            "hz_with_delegation",
            policy=custom_resource.AwsCustomResourcePolicy.from_sdk_calls(
                resources=custom_resource.AwsCustomResourcePolicy.ANY_RESOURCE),
            on_create=HZ_on_create,  # this needs to be updated
            # on_delete=1,  # this needs to be updated
            # # this needs to be updated (potentially, on create is also called on update if this is not set)
            on_update=HZ_on_update)

        my_hosted_zone = route53.HostedZone.from_hosted_zone_id(self,
                                                                id="hostedzone", hosted_zone_id=HZ_with_delegation.get_response_field("HostedZone.Id").split('/')[-1])

        certificate = acm.Certificate(self, "Certificate",
                                      domain_name=environment+".bbot.menu",
                                      subject_alternative_names=[
                                          ("*."+environment+".bbot.menu")],
                                      validation=acm.CertificateValidation.from_dns(
                                          my_hosted_zone)
                                      )

我能够使用get_response_字段获取正确的id,并在最后拆分值以仅获取id,但ACM创建证书验证步骤似乎失败,我认为这表明我未能正确引用托管区域

有什么建议吗


Tags: fromidzoneenvironmenttimeonresponsecreate