lambda: add removalPolicy option to LayerVersionPermission #30686
Labels
@aws-cdk/aws-lambda
Related to AWS Lambda
effort/small
Small work item – less than a day of effort
feature-request
A feature should be added or improved.
p2
Describe the feature
Change LayerVersionPermission to take a optional RemovalPolicy
Use Case
My use case involves publishing a lambda layer consumed by a library. Users may be on different library versions, meaning they may be on different layer versions. These users need to be able to access the layer from different accounts across my organization.
At first I added resource permissions to the layer by calling ILayerVersion.addPermission(). However I noticed that when new layers were published, old layers lost their resource permissions. I confirmed this with the cli: aws lambda get-layer-version-policy --layer-name ... --version-number ....
Looking at the I was able to fix the behavior by manually constructing the CfnLayerVersionPermission instead of using the top level addPermission() function:
This added "UpdateReplacePolicy": "Retain", "DeletionPolicy": "Retain" to the cloud formation template (according to this documentation, both are required). That fixed my issue but it's an ugly solution that was difficult to come up with. I'd like to be able to use addPermission().
Proposed Solution
I have a PR for it the change here, thanks! #30578
Other Information
No response
Acknowledgements
CDK version used
2.140.0
Environment details (OS name and version, etc.)
Mac OS 14.5 Sonoma
The text was updated successfully, but these errors were encountered: