def patch_nested()

in source/cdk_solution_helper_py/helpers_cdk/aws_solutions/cdk/synthesizers.py [0:0]


    def patch_nested(self):
        """Patch nested stacks for S3 deployment compatibility"""
        template_output_bucket = os.getenv(
            "TEMPLATE_OUTPUT_BUCKET",
            {
                "Fn::FindInMap": [  # NOSONAR (python:S1192) - string for clarity
                    "SourceCode",
                    "General",
                    "S3Bucket",
                ]
            },
        )
        for (resource_name, resource) in self.contents.get("Resources", {}).items():
            resource_type = resource.get("Type")
            if resource_type == "AWS::CloudFormation::Stack":
                try:
                    nested_stack_filename = resource["Metadata"][
                        "aws:solutions:templatename"
                    ]
                except KeyError:
                    raise KeyError("nested stack missing required TemplateOptions")

                # update CloudFormation resource properties for S3Bucket and S3Key
                # fmt: off
                resource["Properties"]["TemplateURL"] = {
                    "Fn::Join": [  # NOSONAR (python:S1192) - string for clarity
                        "",
                        [
                            "https://",
                            template_output_bucket,
                            ".s3.",
                            {"Ref": "AWS::URLSuffix"},
                            "/",
                            {
                                "Fn::FindInMap": ["SourceCode", "General", "KeyPrefix"]  # NOSONAR (python:S1192) - string for clarity
                            },
                            "/",
                            nested_stack_filename,
                        ],
                    ]
                }