(core): stateful annotations
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Describe the feature
I as a construct author, want to be able to change or remove annotations after they have been constructed.
### Use Case
For example, the `aws-lambda-nodejs.Function` construct can use a runtime `NODEJS_LATEST`, which changes as new runtime versions are available. We currently warn users when they are using this runtime, and have dependencies listed in `externalModules`, since this indicates that they are relying on these packages being present somewhere other than their bundled handler. However, these dependencies may be present in a lambda layer.
Currently lambda layers are [computed lazily](https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/aws-lambda/lib/function.ts#L809) which means we can't just check if the runtime is variable, external modules are passed, and there are no layers present within `aws-lambda-nodejs.Function` then add an annotation, as a user may call `addLayers` post construction and then the annotation would be inaccurate.
If we could remove an annotation, we could check for these conditions within a constructor, add the annotation, then override `addLayers` from the inheriting class to remove the annotation if present.
See https://github.com/aws/aws-cdk/pull/26763 for additional context
### Proposed Solution
This was explored previously by @corymhall [in this pr](https://github.com/aws/aws-cdk/pull/26144) but it was dropped for the moment as solutions weren't ideal.
### Other Information
_No response_
### Acknowledgements
- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change
### CDK version used
2.92.0
### Environment details (OS name and version, etc.)
MacOs
Contributor guide
Research direction
Read packages/aws-cdk-lib/aws-lambda/lib/function.ts, especially the lazy layer computation, then review PRs 26763 and 26144 for the prior design context. Define an annotation API that supports removal or replacement and verify that the runtime and external-module warning is absent once layers are added after construction.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- infrastructure
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100