(cloudformation-include): Support for referencing Serverless::Function .Version and .Alias attributes #22747
Labels
@aws-cdk/cloudformation-include
Issues related to the "CFN include v.20" package
@aws-cdk/core
Related to core CDK functionality
effort/small
Small work item – less than a day of effort
feature-request
A feature should be added or improved.
p2
Describe the feature
I'm proposing to add support to CfnInclude for templates which include references to Serverless referenceable properties (namely,
<function‑LogicalId>.Version
and<function‑LogicalId>.Alias
) that are placeholders until the Transform is executed at deploy-time.Use Case
CfnInclude seems to work today with many templates that use the Serverless transform, but some edge cases exist that require workarounds. In this case, templates that need to reference a specific lambda version or alias effectively can't leverage
AutoPublishAlias
and require manual definition of versions, aliases, deployment groups, etc.This issue (and subsequent fix) is a recent example of adding support for templates that leverage the Serverless transform (in that case, by supporting cyclic dependencies in templates).
Proposed Solution
Going out on a limb a bit here, so I'm definitely soliciting input from folks more familiar with this module.
To maintain some consistency in the interface, we might consider adding an
allowDanglingReferences
props flag, following theallowCyclicalReferences
flag convention (or a similar flag with a better name). Another option might be an allowlist of references that are expected to have no resolved target. I imagine there are other potential use-cases for this type of leniency outside of these two specific Serverless reference patterns, so I'd think it makes sense to be a bit more generic than is necessary for this issue alone.In the parser itself, there are a few different situations that support somewhat similar behavior. One example being leaving Resolvable objects alone. A potentially more-relevant example in the case of Ref parsing is the existing support for special refs, which supports Refs of things like AWS::Region and AWS::AccountId. Depending on the intended interface for
CfnInclude
, a flag (or allowlist) could be passed inCfnParserOptions
to optionally allow for similar handling in cases where no ref target is found.Other Information
When
AutoPublishAlias
is set, the Serverless transform creates both a lambda Version and Alias resource at deployment time. These are referenceable via<function‑LogicalId>.Version
and<function‑LogicalId>.Alias
respectively. These references are replaced by the Serverless transform during deployment.CfnInclude generally requires the targets of Ref expressions to exist within the template (e.g. here, though the specific ICfnFinder implementation depends on the section of the template being parsed). Today, when trying to parse a template that includes one of these references, the result is
This specific issue has been raised before, and was resolved with a different workaround using CfnApplication. This still seems like a reasonable bit of functionality to add, given both that this workaround doesn't result in the same effect as properly supported dangling references, as well as the existing support for some leniency in template parsing.
A small example template and code can be found in the previous issue on this topic.
Acknowledgements
CDK version used
2.43.1
Environment details (OS name and version, etc.)
macOS Monterey v12.6
The text was updated successfully, but these errors were encountered: