@@ -612,7 +612,7 @@ def _construct_api_domain( # noqa: PLR0912, PLR0915
612
612
613
613
return ApiDomainResponse (domain , basepath_resource_list , record_set_group )
614
614
615
- def _construct_api_domain_v2 (
615
+ def _construct_api_domain_v2 ( # noqa: PLR0912, PLR0915
616
616
self , rest_api : ApiGatewayRestApi , route53_record_set_groups : Any
617
617
) -> ApiDomainResponseV2 :
618
618
"""
@@ -671,12 +671,7 @@ def _construct_api_domain_v2(
671
671
672
672
basepath_resource_list : List [ApiGatewayBasePathMappingV2 ] = []
673
673
if basepaths is None :
674
- basepath_mapping = ApiGatewayBasePathMappingV2 (
675
- self .logical_id + "BasePathMapping" , attributes = self .passthrough_resource_attributes
676
- )
677
- basepath_mapping .DomainNameArn = ref (domain_name_arn )
678
- basepath_mapping .RestApiId = ref (rest_api .logical_id )
679
- basepath_mapping .Stage = ref (rest_api .logical_id + ".Stage" )
674
+ basepath_mapping = self ._create_basepath_mapping (domain_name_arn , rest_api )
680
675
basepath_resource_list .extend ([basepath_mapping ])
681
676
else :
682
677
sam_expect (basepaths , self .logical_id , "Domain.BasePath" ).to_be_a_list_of (ExpectedType .STRING )
@@ -723,18 +718,22 @@ def _construct_api_domain_v2(
723
718
)
724
719
725
720
if not record_set_group :
726
- record_set_group = Route53RecordSetGroup (logical_id , attributes = self .passthrough_resource_attributes )
727
- if "HostedZoneId" in route53 :
728
- record_set_group .HostedZoneId = route53 .get ("HostedZoneId" )
729
- if "HostedZoneName" in route53 :
730
- record_set_group .HostedZoneName = route53 .get ("HostedZoneName" )
731
- record_set_group .RecordSets = []
721
+ record_set_group = self ._get_record_set_group (logical_id , route53 )
732
722
route53_record_set_groups [logical_id ] = record_set_group
733
723
734
724
record_set_group .RecordSets += self ._construct_record_sets_for_domain (self .domain , domain_name , route53 )
735
725
736
726
return ApiDomainResponseV2 (domain , basepath_resource_list , record_set_group )
737
727
728
+ def _get_record_set_group (self , logical_id : str , route53 : Dict [str , Any ]) -> Route53RecordSetGroup :
729
+ record_set_group = Route53RecordSetGroup (logical_id , attributes = self .passthrough_resource_attributes )
730
+ if "HostedZoneId" in route53 :
731
+ record_set_group .HostedZoneId = route53 .get ("HostedZoneId" )
732
+ if "HostedZoneName" in route53 :
733
+ record_set_group .HostedZoneName = route53 .get ("HostedZoneName" )
734
+ record_set_group .RecordSets = []
735
+ return record_set_group
736
+
738
737
def _construct_single_record_set_group (
739
738
self , domain : Dict [str , Any ], api_domain_name : str , route53 : Any
740
739
) -> Route53RecordSetGroup :
@@ -799,6 +798,17 @@ def _construct_alias_target(self, domain: Dict[str, Any], api_domain_name: str,
799
798
alias_target ["DNSName" ] = route53 .get ("DistributionDomainName" )
800
799
return alias_target
801
800
801
+ def _create_basepath_mapping (
802
+ self , domain_name_arn : PassThrough , rest_api : ApiGatewayRestApi
803
+ ) -> ApiGatewayBasePathMappingV2 :
804
+ basepath_mapping = ApiGatewayBasePathMappingV2 (
805
+ self .logical_id + "BasePathMapping" , attributes = self .passthrough_resource_attributes
806
+ )
807
+ basepath_mapping .DomainNameArn = ref (domain_name_arn )
808
+ basepath_mapping .RestApiId = ref (rest_api .logical_id )
809
+ basepath_mapping .Stage = ref (rest_api .logical_id + ".Stage" )
810
+ return basepath_mapping
811
+
802
812
@cw_timer (prefix = "Generator" , name = "Api" )
803
813
def to_cloudformation (
804
814
self , redeploy_restapi_parameters : Optional [Any ], route53_record_set_groups : Dict [str , Route53RecordSetGroup ]
@@ -808,8 +818,11 @@ def to_cloudformation(
808
818
:returns: a tuple containing the RestApi, Deployment, and Stage for an empty Api.
809
819
:rtype: tuple
810
820
"""
821
+ api_domain_response : ApiDomainResponseV2 | ApiDomainResponse
822
+ domain : Resource | None
823
+ basepath_mapping : List [ApiGatewayBasePathMapping ] | List [ApiGatewayBasePathMappingV2 ] | None
811
824
rest_api = self ._construct_rest_api ()
812
- if self .endpoint_configuration == "PRIVATE" :
825
+ if self .endpoint_configuration and self . endpoint_configuration . get ( "Type" ) == "PRIVATE" :
813
826
api_domain_response = self ._construct_api_domain_v2 (rest_api , route53_record_set_groups )
814
827
domain = api_domain_response .domain
815
828
basepath_mapping = api_domain_response .apigw_basepath_mapping_list
@@ -840,7 +853,9 @@ def to_cloudformation(
840
853
List [Resource ],
841
854
Tuple [Resource ],
842
855
List [LambdaPermission ],
856
+ List [Resource ],
843
857
List [ApiGatewayBasePathMapping ],
858
+ List [ApiGatewayBasePathMappingV2 ],
844
859
],
845
860
] = []
846
861
0 commit comments