mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(cloudformation): delete published Lambda versions with their stacks (#8371)
An AWS::Lambda::Version resource reported its deletion but left the version published. CloudFormation now deletes the version through Lambda's qualified DeleteFunction when the stack is deleted, the resource leaves the template, or its creation rolls back, unless its DeletionPolicy retains it. $LATEST and other versions stay, an already-missing version counts as deleted, and an alias still pointing at the version fails the delete until it is removed. A placeholder, unqualified or alias identity is never turned into a whole-function delete. The SDK regressions use the shared CfnStackWaits, now with an SDK deleteStack that follows the stack id, and AwsSdkErrors for their error checks. Signed-off-by: Andre Kurait <AndreKurait@gmail.com> Signed-off-by: Jackson Price <jxnprice@amazon.com> Co-authored-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
1 parent
d5e831bd54
commit
da23f42d11
8 files changed
+773
-17
No files matched your search
+16
-2
@@ -56,9 +56,11 @@ public class LambdaVersionAliasCfnProvisioner implements CfnResourceProvisioner
|
||||
|
||||
@Override
|
||||
public void delete(String resourceType, String physicalId, String region) {
|
||||
if ("AWS::Lambda::Version".equals(resourceType)) {
|
||||
deleteVersion(physicalId, region);
|
||||
return;
|
||||
}
|
||||
if (!"AWS::Lambda::Alias".equals(resourceType)) {
|
||||
// AWS::Lambda::Version has no backing delete: Lambda exposes no DeleteVersion, and
|
||||
// deleting the function drops its versions with it.
|
||||
return;
|
||||
}
|
||||
// The physical id is the alias ARN (arn:…:function:<name>:<alias>), so the function name
|
||||
@@ -77,6 +79,18 @@ public class LambdaVersionAliasCfnProvisioner implements CfnResourceProvisioner
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteVersion(String physicalId, String region) {
|
||||
LambdaArnUtils.ResolvedFunctionRef ref = LambdaArnUtils.resolveWithRegion(region, physicalId, null);
|
||||
String version = ref.qualifier();
|
||||
if (version == null || !version.chars().allMatch(value -> value >= '0' && value <= '9')) {
|
||||
// Older stacks can carry a generic placeholder. Never turn that into a whole-function delete.
|
||||
LOG.debugv("Not a published version ARN, nothing to delete: {0}", physicalId);
|
||||
return;
|
||||
}
|
||||
CfnDeletes.safeDelete("Lambda version", physicalId,
|
||||
() -> lambdaService.deleteFunction(region, physicalId, version), "ResourceNotFoundException");
|
||||
}
|
||||
|
||||
private void provisionVersion(StackResource r, JsonNode props, ProvisionContext ctx) {
|
||||
String functionName = ctx.resolveOptional(props, "FunctionName");
|
||||
if (functionName == null || functionName.isBlank()) {
|
||||
|
||||
Reference in new issue
Block a user