• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

localstack / localstack / 20565403496

29 Dec 2025 05:11AM UTC coverage: 84.103% (-2.8%) from 86.921%
20565403496

Pull #13567

github

web-flow
Merge 4816837a5 into 2417384aa
Pull Request #13567: Update ASF APIs

67166 of 79862 relevant lines covered (84.1%)

0.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.0
/localstack-core/localstack/services/cloudformation/engine/template_preparer.py
1
import json
1✔
2
import logging
1✔
3

4
from localstack.services.cloudformation.engine import yaml_parser
1✔
5
from localstack.services.cloudformation.engine.transformers import (
1✔
6
    apply_global_transformations,
7
    apply_intrinsic_transformations,
8
)
9
from localstack.services.cloudformation.engine.validations import ValidationError
1✔
10
from localstack.utils.json import clone_safe
1✔
11

12
LOG = logging.getLogger(__name__)
1✔
13

14

15
def parse_template(template: str) -> dict:
1✔
16
    try:
1✔
17
        return json.loads(template)
1✔
18
    except Exception:
1✔
19
        try:
1✔
20
            return clone_safe(yaml_parser.parse_yaml(template))
1✔
21
        except ValidationError:
1✔
22
            # The error is handled in the yaml parsing helper
23
            raise
1✔
24
        except Exception:
1✔
25
            # TODO: present the user with a better error message including error location
26
            raise ValidationError("Template format error: YAML not well-formed.")
1✔
27

28

29
def template_to_json(template: str) -> str:
1✔
30
    template = parse_template(template)
1✔
31
    return json.dumps(template)
1✔
32

33

34
# TODO: consider moving to transformers.py as well
35
def transform_template(
1✔
36
    account_id: str,
37
    region_name: str,
38
    template: dict,
39
    stack_name: str,
40
    resources: dict,
41
    mappings: dict,
42
    conditions: dict[str, bool],
43
    resolved_parameters: dict,
44
) -> dict:
45
    proccesed_template = dict(template)
×
46

47
    # apply 'Fn::Transform' intrinsic functions (note: needs to be applied before global
48
    #  transforms below, as some utils - incl samtransformer - expect them to be resolved already)
49
    proccesed_template = apply_intrinsic_transformations(
×
50
        account_id,
51
        region_name,
52
        proccesed_template,
53
        stack_name,
54
        resources,
55
        mappings,
56
        conditions,
57
        resolved_parameters,
58
    )
59

60
    # apply global transforms
61
    proccesed_template = apply_global_transformations(
×
62
        account_id,
63
        region_name,
64
        proccesed_template,
65
        stack_name,
66
        resources,
67
        mappings,
68
        conditions,
69
        resolved_parameters,
70
    )
71

72
    return proccesed_template
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc