Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(cloudformation-include): Support for referencing Serverless::Function .Version and .Alias attributes #22747

Open
1 of 2 tasks
alexander-ray opened this issue Nov 2, 2022 · 2 comments
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

Comments

@alexander-ray
Copy link

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 the allowCyclicalReferences 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 in CfnParserOptions 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

Error: Element used in Ref expression with logical ID: '<function‑LogicalId>.Version' not found

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

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.43.1

Environment details (OS name and version, etc.)

macOS Monterey v12.6

@alexander-ray alexander-ray added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Nov 2, 2022
@github-actions github-actions bot added the @aws-cdk/cloudformation-include Issues related to the "CFN include v.20" package label Nov 2, 2022
@comcalvi comcalvi added p2 and removed needs-triage This issue or PR still needs to be triaged. labels Nov 14, 2022
@comcalvi
Copy link
Contributor

I think allowDanglingReferences is the way to go here, at least until serverless support is added.

@comcalvi comcalvi added the effort/small Small work item – less than a day of effort label Nov 14, 2022
@san-amal
Copy link

san-amal commented Aug 3, 2023

Hi,
Is there an update for this feature ?

@khushail khushail added the @aws-cdk/core Related to core CDK functionality label Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

4 participants