fix: rewrite artifact URIs for AWS::Serverless::Function in Fn::ForEach (#9117)#9123
Open
bnusunny wants to merge 10 commits into
Open
fix: rewrite artifact URIs for AWS::Serverless::Function in Fn::ForEach (#9117)#9123bnusunny wants to merge 10 commits into
bnusunny wants to merge 10 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue(s) does this change fix?
Close #9117
Why is this change necessary?
When an
AWS::Serverless::Function(or any packageable resource) is generated inside anAWS::LanguageExtensionsFn::ForEachloop,sam package/sam deployfails to rewrite its artifact URI (ImageUri,CodeUri, etc.) to the uploaded artifact. For image functions the deploy then fails withImage not found for ImageUri parameter, andsam deploy --resolve-image-reposcrashes outright with'list' object has no attribute 'get'.There are two distinct root causes:
Artifact merge-back gap. After SAM CLI expands
Fn::ForEachlocally, exports (uploads) artifacts on the expanded copy, and merges the rewritten URIs back onto the originalFn::ForEach-preserving template, the static merge path (_update_foreach_with_s3_uris) (a) skipped!Ref-based collections entirely —collection_valueswas only built from literal lists, so!Ref FuncTypeyielded[]and the rewrite was skipped — and (b) for multi-value collections copied the first iteration's URI onto the shared body, which is wrong whenever iterations resolve to distinct URIs (always true for images, whose local tag encodes the per-iteration logical id).--resolve-image-reposcrash.sync_ecr_stackcalledSamLocalStackProvider.get_stacks(..., language_extensions_enabled=False)with the flag hardcoded, so theFn::ForEachblock was never expanded and the SAM translator crashed calling.get("Type")on the ForEach list value before it could resolve ECR repos.How does it address the issue?
!Refcollections via the existingresolve_collection(threadingparameter_values/template through the merge path), then make a value-driven decision per artifact property — if all iterations' exported URIs are identical, copy the raw shared value (preserving object shapes like{S3Bucket, S3Key}); if they differ, defer to the existing Mapping +Fn::FindInMapmachinery via adeferred_dynamicaccumulator that the package callers combine with the pre-existing dynamic properties. This is artifact-agnostic (works forImageUri,CodeUri,DefinitionUri,Content, dotted paths, etc.).--resolve-image-repos: add alanguage_extensions_enabledparameter tosync_ecr_stackand thread the already-resolved flag through its three callers (deploy, guided deploy, package) so ForEach is expanded before the SAM translator runs.What side effects does this change have?
Fn::ForEachwith a static image value falls back to legacy copy, since a static value carries no loop variable to build compound Mapping keys. Nested loops with dynamic values are unaffected.Mandatory Checklist
PRs will only be reviewed after checklist is complete
make prpassesmake update-reproducible-reqsif dependencies were changedBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.