WIP: sam build Resolve layer ARN passed from to parent stacks (not covering all intrinsic functions)#2732
WIP: sam build Resolve layer ARN passed from to parent stacks (not covering all intrinsic functions)#2732aahung wants to merge 4 commits intoaws:developfrom
sam build Resolve layer ARN passed from to parent stacks (not covering all intrinsic functions)#2732Conversation
sam build Resolve layer ARN passed from to parent stacks (not covering all intrinsic functions)
mndeveci
left a comment
There was a problem hiding this comment.
Can we add some tests to cover use cases with intrinsic functions? I didn't see any addition most of them was fixing the existing ones I believe.
| # It is a parameter passed down from the parent | ||
| # here we use a special function "CrossStackRef" to refer a logicalID from other stacks | ||
| # ".." means the parent stack |
There was a problem hiding this comment.
nit: can we move the comment under if statement?
| return os.path.normpath(os.path.join(os.path.dirname(stack_file_path), path)) | ||
|
|
||
| @staticmethod | ||
| def resolve_stack(stacks: List[Stack], base_stack: Stack, relative_stack_path: str) -> Stack: |
There was a problem hiding this comment.
Please add some documentation to the method
| # for example, {"Ref": "layerLogicalID"} refers to the "layerLogicalID" in the current stack. | ||
| # {"Ref": {"CrossStackRef": ["..", "layerLogicalID"]} | ||
| # refers to the "layerLogicalID" in the parent stack. | ||
| # {"Ref": {"CrossStackRef": ["..", {"CrossStackRef": ["..", "layerLogicalID"]})} |
There was a problem hiding this comment.
We should carefully clear this CrossStackRef from the template.
And what happens if there are more than one level between the layer definition vs the function. Like RootStack (LayerDefinition) -> ChildStack -> GrandChildStack (Function which uses LayerDefinition from RootStack)?
There was a problem hiding this comment.
We should carefully clear this CrossStackRef from the template.
Yes, but this does not affect the output template because it is only affected by builder.update_template()(only update codeuri and other path properties) and template.move_template() (only move the file).
And what happens if there are more than one level between the layer definition vs the function.
this is the last example. I tested this with
# template.yaml
Resources:
MyLayerVersion:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: MyLayer
Description: Layer description
ContentUri: MyLayerVersion
CompatibleRuntimes:
- python3.8
App:
Type: AWS::Serverless::Application
Properties:
Location: ./child.yaml
Parameters:
Layer: !Ref MyLayerVersion
# child.yaml
Parameters:
Layer:
Type: String
Resources:
Function:
Type: AWS::Serverless::Function
Properties:
CodeUri: function
Handler: app.lambda_handler
Runtime: python3.8
Layers:
- !Ref Layer
App:
Type: AWS::Serverless::Application
Properties:
Location: ./child2.yaml
Parameters:
Layer: !Ref Layer
# child2.yaml
Parameters:
Layer:
Type: String
Resources:
Function2:
Type: AWS::Serverless::Function
Properties:
CodeUri: function
Handler: app.lambda_handler
Runtime: python3.8
Layers:
- !Ref Layer
@mndeveci Before I polish this PR too much, do you think this is the approach the one we want to implement? For each intrinsic function use case, we need to manually support it. |
| # Here layer refers to another resources. | ||
| # in a multi stack system, the layer might locate in the current stack or passed down from parents. | ||
| # for example, {"Ref": "layerLogicalID"} refers to the "layerLogicalID" in the current stack. | ||
| # {"Ref": {"CrossStackRef": ["..", "layerLogicalID"]} |
There was a problem hiding this comment.
Wouldn't adding a new SAM CLI specific intrinsic function break existing translation? The template will not be compatible with uploading to CFN directly.
There was a problem hiding this comment.
The built template won't contain this special function.
The output template because it is only affected by builder.update_template()(only update codeuri and other path properties) and template.move_template() (only move the file).
|
close in favor of #2760 |
Which issue(s) does this change fix?
Attempt to fix #2724
Why is this change necessary?
When
samtries to resolve intrinsic functions inParameterspassed from parent, it simply does this replacement:single
!Refused in parentCompound intrinsic function like
!JoinIn either case,
samwon't be able to link the resolved value to original resources passed from the parentHow does it address the issue?
get_translation().SamFunctionProviderto locate resource reference across different stacks.Support these methods:
Directly passed down using
!RefUsing
!Join [",", [..., ..., ...]]What side effects does this change have?
Checklist
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.