mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(cloudformation): treat delete of an already-removed DynamoDB table or Lambda function as idempotent (#1803)
* fix(cloudformation): treat delete of an already-removed DynamoDB table or Lambda function as idempotent When a stack is torn down after a rollback has already deleted some of its resources, CloudFormation re-issues the delete against resources that no longer exist. DynamoDB DeleteTable and Lambda DeleteFunction both raise ResourceNotFoundException in that case, which flipped the stack to DELETE_FAILED and wedged the stack name against a later create. Route the AWS::DynamoDB::Table and AWS::Lambda::Function delete cases through deleteDynamoTableSafe / deleteLambdaFunctionSafe, which swallow ResourceNotFoundException (treating an absent resource as already deleted, as AWS does) while still re-throwing any other AwsException so genuine conflicts continue to surface as DELETE_FAILED. * test(cloudformation): cover idempotent delete boundaries * chore(ci): retrigger flaky checks
This commit is contained in:
1 parent
48b2139b4f
commit
5cb26ff117
3 files changed
+235
-2
No files matched your search
+24
-2
@@ -455,8 +455,8 @@ public class CloudFormationResourceProvisioner {
|
||||
case "AWS::S3::Bucket" -> s3Service.deleteBucket(physicalId);
|
||||
case "AWS::SNS::Topic" -> snsService.deleteTopic(physicalId, region);
|
||||
case "AWS::SNS::Subscription" -> snsService.unsubscribe(physicalId, region);
|
||||
case "AWS::DynamoDB::Table" -> dynamoDbService.deleteTable(physicalId, region);
|
||||
case "AWS::Lambda::Function" -> lambdaService.deleteFunction(region, physicalId);
|
||||
case "AWS::DynamoDB::Table" -> deleteDynamoTableSafe(physicalId, region);
|
||||
case "AWS::Lambda::Function" -> deleteLambdaFunctionSafe(physicalId, region);
|
||||
case "AWS::IAM::Role" -> deleteRoleSafe(physicalId);
|
||||
// AWS::IAM::Policy is inline: it is removed together with its owning principal (see
|
||||
// deleteRoleSafe), or precisely via the StackResource-aware delete path. Nothing to do
|
||||
@@ -4261,6 +4261,28 @@ public class CloudFormationResourceProvisioner {
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteDynamoTableSafe(String tableName, String region) {
|
||||
try {
|
||||
dynamoDbService.deleteTable(tableName, region);
|
||||
} catch (AwsException e) {
|
||||
if (!"ResourceNotFoundException".equals(e.getErrorCode())) {
|
||||
throw e;
|
||||
}
|
||||
LOG.debugv("DynamoDB table already gone, treating as deleted: {0}", tableName);
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteLambdaFunctionSafe(String functionName, String region) {
|
||||
try {
|
||||
lambdaService.deleteFunction(region, functionName);
|
||||
} catch (AwsException e) {
|
||||
if (!"ResourceNotFoundException".equals(e.getErrorCode())) {
|
||||
throw e;
|
||||
}
|
||||
LOG.debugv("Lambda function already gone, treating as deleted: {0}", functionName);
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteManagedPolicy(StackResource resource) {
|
||||
String policyArn = resource.getPhysicalId();
|
||||
for (String roleName : managedPolicyRoleTargets(resource)) {
|
||||
|
||||
Reference in new issue
Block a user