Commit a486922
authored
* feat(cfn-lang-ext): add jmespath-aware property get/set helpers
* refactor(cfn-lang-ext): use jmespath for artifact property copy
* refactor(cfn-lang-ext): use jmespath for build_context artifact copy
* fix(cfn-lang-ext): derive PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES from canonical dicts (aws#9005)
Replace the literal PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES dict with
a derivation from RESOURCES_WITH_LOCAL_PATHS and RESOURCES_WITH_IMAGE_COMPONENT
in samcli.lib.utils.resources, establishing a single source of truth.
This fixes issue aws#9005 where eight resource types were missing from the
language-extensions packaging path:
- AWS::Serverless::Application
- AWS::CloudFormation::StackSet
- AWS::ElasticBeanstalk::ApplicationVersion
- AWS::AppSync::GraphQLSchema
- AWS::AppSync::Resolver
- AWS::AppSync::FunctionConfiguration
- AWS::CloudFormation::ModuleVersion
- AWS::CloudFormation::ResourceVersion
The derivation also adds AWS::Glue::Job with dotted-path property
Command.ScriptLocation, and adds Code.ImageUri to AWS::Lambda::Function.
All 14 new tests pass, confirming the derived dict includes the expected
entries and excludes design exclusions (ECR::Repository, ServerlessRepo::Application).
Cross-task integration anchors for Glue::Job dotted-path handling now pass.
* test(cfn-lang-ext): regression tests for aws#9005 and sibling resource types
* style: apply black formatting to new tests
* chore: fix lint findings (ruff import order, mypy unreachable guard)
* fix(cfn-lang-ext): route Fn::ForEach dynamic-property consumers through jmespath
PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES now contains dotted paths like
Command.ScriptLocation (Glue) and Code.ImageUri (Lambda image), but four
call sites in build_context, sam_integration, and language_extensions_packaging
were still doing flat-key dict access:
- _update_foreach_artifact_paths
- _count_dynamic_properties
- _get_artifact_value
- detect_foreach_dynamic_properties
For dotted entries those reads return None, the early skip kicks in, no
SAM* mapping is generated, and the dotted artifact value never propagates
back to the Fn::ForEach body. CloudFormation Mapping names and FindInMap
third-arg keys also can't contain dots.
Switch the four sites to _get_prop_value / _set_prop_value, derive the
Mapping name and FindInMap third-arg from the leaf segment via a new
_leaf_prop_name helper, and add _resolve_property_paths to skip parent
paths when a more specific dotted child is present (so Lambda::Function
"Code" doesn't shadow "Code.ImageUri" for image functions).
Adds 6 regression tests covering Fn::ForEach over Glue::Job with
templated Command.ScriptLocation and Lambda::Function with templated
Code.ImageUri at both detection and Mapping-generation layers.
Addresses review feedback on PR aws#9009.
* docs(cfn-lang-ext): expand CloudFormation Language Extensions reference
Adds documentation for behaviors that are now supported / verified by this
PR's coverage:
- Full table of recognized dynamic artifact properties (derived from the
canonical packageable-resource list rather than a hand-maintained one),
including AWS::Serverless::Application, AWS::CloudFormation::StackSet,
AppSync, ElasticBeanstalk, Glue::Job, Lambda::Function image package
- Note about how dotted property paths (Command.ScriptLocation,
Code.ImageUri) are addressed on the resource vs. used as Mapping
identifiers
- Multiple resources per ForEach body, Mapping name collision resolution
- ForEach in Outputs; Conditions and DependsOn on emitted resources
- Validation errors (ForEach element count, nesting limit, missing
parameter, empty collection)
* docs(cfn-lang-ext): correct validation errors table to match code
The previous table paraphrased messages and listed an error that doesn't
exist:
- Layout error: actual message is "Fn::ForEach::<key> layout is
incorrect" and covers more cases than just element count (non-list
value, non-string identifier, etc.).
- Nesting depth: actual message is the multi-line "Fn::ForEach nesting
depth of <N> exceeds the maximum allowed depth of 5. CloudFormation
supports up to 5 nested Fn::ForEach loops."
- Missing parameter referenced by Fn::ForEach: there is no such error.
In partial mode (typical sam build/package), the unresolved Ref is
preserved and CFN rejects it at deploy time.
- Empty collection: no message; silently skipped (kept as-is).
* fix(cfn-lang-ext): derive Mapping-prefix list and artifact-property set from canonical dict
Two consumers of PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES were left out of
sync when this PR began emitting Mappings for newly-supported resource
types (Application, Glue, EB, AppSync, CFN Module/ResourceVersion) and for
dotted-leaf entries (Code.ImageUri):
- samcli/lib/cfn_language_extensions/utils.py — _SAM_GENERATED_MAPPING_PREFIXES
was a hand-maintained tuple covering only the pre-PR set, so
is_sam_generated_mapping returned False for SAMLocation*, SAMScriptLocation*,
SAMSourceBundle*, SAMModulePackage*, SAMSchemaHandlerPackage*. That made
_update_sam_mappings_relative_paths skip these mappings on template move
(paths weren't adjusted) and prevented _create_deploy_error from wrapping
CFN "key not found" errors as MissingMappingKeyError.
- samcli/commands/_utils/template.py — _ARTIFACT_PATH_PROPERTIES was built
from the dotted form ("Command.ScriptLocation") but the SAM-generated
Mapping value-dicts use the leaf ("ScriptLocation") as the key. So the
inner property check rejected leaf names and Glue script paths never got
their relative paths adjusted on template move.
Both lists now derive from PACKAGEABLE_RESOURCE_ARTIFACT_PROPERTIES at
module import (mirroring the single-source-of-truth approach used for the
dict itself in models.py). Adds two sync tests so future drift fails loudly.
Addresses second review comment on PR aws#9009.
* fix(cfn-lang-ext): key Mapping-name collision detection on the leaf, not the dotted path
The Mapping name now uses only the leaf segment (SAM<leaf><Loop>), but the
collision counter was still keyed on the dotted property_name. So two
resources whose dotted paths share a leaf — e.g. AWS::Serverless::Function
"ImageUri" and AWS::Lambda::Function "Code.ImageUri" — would land in
different collision-group buckets (each count=1), neither gets the
resource-key suffix, and both produce the identical Mapping name. The
second resource's Mapping entries silently overwrite the first's at deploy
time — the exact silent-corruption shape aws#9005 was meant to eliminate.
Fix: re-key the collision counter and the lookup by the leaf in both
language_extensions_packaging._generate_artifact_mappings /
_compute_mapping_name and build_context._count_dynamic_properties /
_update_foreach_artifact_paths.
Adds two regression tests that put a Serverless::Function (ImageUri) and a
Lambda::Function (Code.ImageUri) in the same Fn::ForEach body and assert
that two distinct SAMImageUri<Loop>* Mappings are produced and neither
resource's entries are lost.
Addresses third review comment on PR aws#9009.
1 parent 9006343 commit a486922
13 files changed
Lines changed: 1044 additions & 71 deletions
File tree
- docs
- samcli
- commands
- _utils
- build
- lib
- cfn_language_extensions
- package
- tests/unit
- commands
- _utils
- buildcmd
- package
- lib/cfn_language_extensions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
45 | 75 | | |
46 | 76 | | |
47 | 77 | | |
| |||
67 | 97 | | |
68 | 98 | | |
69 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
70 | 139 | | |
71 | 140 | | |
72 | 141 | | |
| |||
120 | 189 | | |
121 | 190 | | |
122 | 191 | | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
123 | 232 | | |
124 | 233 | | |
125 | 234 | | |
| |||
154 | 263 | | |
155 | 264 | | |
156 | 265 | | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
157 | 277 | | |
158 | 278 | | |
159 | 279 | | |
160 | 280 | | |
161 | 281 | | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
162 | 286 | | |
163 | 287 | | |
164 | 288 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
36 | 42 | | |
37 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
38 | 47 | | |
39 | 48 | | |
40 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
553 | 553 | | |
554 | 554 | | |
555 | 555 | | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
556 | 562 | | |
557 | 563 | | |
558 | 564 | | |
| |||
599 | 605 | | |
600 | 606 | | |
601 | 607 | | |
602 | | - | |
603 | | - | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
604 | 611 | | |
605 | 612 | | |
606 | 613 | | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
607 | 619 | | |
608 | 620 | | |
609 | 621 | | |
| |||
622 | 634 | | |
623 | 635 | | |
624 | 636 | | |
625 | | - | |
626 | | - | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
627 | 643 | | |
628 | 644 | | |
629 | 645 | | |
| |||
637 | 653 | | |
638 | 654 | | |
639 | 655 | | |
640 | | - | |
| 656 | + | |
641 | 657 | | |
642 | 658 | | |
643 | 659 | | |
| |||
648 | 664 | | |
649 | 665 | | |
650 | 666 | | |
651 | | - | |
| 667 | + | |
652 | 668 | | |
653 | 669 | | |
654 | 670 | | |
| |||
707 | 723 | | |
708 | 724 | | |
709 | 725 | | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
710 | 731 | | |
711 | 732 | | |
712 | 733 | | |
| |||
718 | 739 | | |
719 | 740 | | |
720 | 741 | | |
721 | | - | |
722 | | - | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
723 | 745 | | |
724 | | - | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
725 | 749 | | |
726 | 750 | | |
727 | 751 | | |
| |||
759 | 783 | | |
760 | 784 | | |
761 | 785 | | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
762 | 790 | | |
| 791 | + | |
| 792 | + | |
763 | 793 | | |
| 794 | + | |
764 | 795 | | |
765 | 796 | | |
766 | 797 | | |
| |||
778 | 809 | | |
779 | 810 | | |
780 | 811 | | |
781 | | - | |
| 812 | + | |
782 | 813 | | |
783 | 814 | | |
784 | 815 | | |
| |||
793 | 824 | | |
794 | 825 | | |
795 | 826 | | |
796 | | - | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
797 | 831 | | |
798 | 832 | | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
799 | 836 | | |
800 | 837 | | |
801 | 838 | | |
| |||
821 | 858 | | |
822 | 859 | | |
823 | 860 | | |
824 | | - | |
| 861 | + | |
825 | 862 | | |
826 | 863 | | |
827 | 864 | | |
| |||
895 | 932 | | |
896 | 933 | | |
897 | 934 | | |
898 | | - | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
899 | 941 | | |
900 | 942 | | |
901 | 943 | | |
902 | 944 | | |
903 | 945 | | |
904 | 946 | | |
905 | | - | |
| 947 | + | |
906 | 948 | | |
907 | 949 | | |
908 | 950 | | |
| |||
919 | 961 | | |
920 | 962 | | |
921 | 963 | | |
| 964 | + | |
922 | 965 | | |
923 | 966 | | |
924 | 967 | | |
| |||
929 | 972 | | |
930 | 973 | | |
931 | 974 | | |
932 | | - | |
933 | | - | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
934 | 978 | | |
935 | 979 | | |
936 | 980 | | |
| |||
0 commit comments