From 29ffa63cab299c5e8993c9d63b03065802d078c9 Mon Sep 17 00:00:00 2001 From: "remote-swe-app[bot]" <123456+remote-swe-app[bot]@users.noreply.github.com> Date: Wed, 18 Jun 2025 06:08:55 +0000 Subject: [PATCH 1/2] Fix AMI cleanup workflow to deregister AMI before deleting snapshots --- cdk/lib/constructs/ec2-gc/sfn/asl.json | 167 ++++++++++++------------- 1 file changed, 78 insertions(+), 89 deletions(-) diff --git a/cdk/lib/constructs/ec2-gc/sfn/asl.json b/cdk/lib/constructs/ec2-gc/sfn/asl.json index 204b7512..3de29ff0 100644 --- a/cdk/lib/constructs/ec2-gc/sfn/asl.json +++ b/cdk/lib/constructs/ec2-gc/sfn/asl.json @@ -82,103 +82,92 @@ "ProcessorConfig": { "Mode": "INLINE" }, - "StartAt": "Parallel", + "StartAt": "Cleanup", "States": { - "Parallel": { - "Type": "Parallel", - "Branches": [ - { - "StartAt": "DeleteImageBuilderImage", - "States": { - "DeleteImageBuilderImage": { - "Type": "Task", - "Resource": "arn:aws:states:::aws-sdk:imagebuilder:deleteImage", - "Arguments": { - "ImageBuildVersionArn": "{% $states.input.Tags[Key = 'Ec2ImageBuilderArn'].Value %}" - }, - "Next": "Pass", - "Catch": [ - { - "ErrorEquals": [ - "States.ALL" - ], - "Next": "Pass" - } - ] - }, - "Pass": { - "Type": "Pass", - "End": true - } - } + "Cleanup": { + "Type": "Map", + "Items": "{% [$states.input] %}", + "ItemProcessor": { + "ProcessorConfig": { + "Mode": "INLINE" }, - { - "StartAt": "DeregisterImage", - "States": { - "DeregisterImage": { - "Type": "Task", - "Resource": "arn:aws:states:::aws-sdk:ec2:deregisterImage", - "Arguments": { - "ImageId": "{% $states.input.ImageId %}" - }, - "Next": "Pass (1)", - "Catch": [ - { - "ErrorEquals": [ - "States.ALL" - ], - "Next": "Pass (1)" - } - ] + "StartAt": "DeleteImageBuilderImage", + "States": { + "DeleteImageBuilderImage": { + "Type": "Task", + "Resource": "arn:aws:states:::aws-sdk:imagebuilder:deleteImage", + "Arguments": { + "ImageBuildVersionArn": "{% $states.input.Tags[Key = 'Ec2ImageBuilderArn'].Value %}" }, - "Pass (1)": { - "Type": "Pass", - "End": true - } - } - }, - { - "StartAt": "ProcessSnapshots", - "States": { - "ProcessSnapshots": { - "Type": "Map", - "Items": "{% [$states.input.BlockDeviceMappings[$exists(Ebs)]] %}", - "ItemProcessor": { - "ProcessorConfig": { - "Mode": "INLINE" - }, - "StartAt": "DeleteSnapshotInMap", - "States": { - "DeleteSnapshotInMap": { - "Type": "Task", - "Resource": "arn:aws:states:::aws-sdk:ec2:deleteSnapshot", - "Arguments": { - "SnapshotId": "{% $states.input.Ebs.SnapshotId %}" - }, - "Next": "Pass (2)", - "Catch": [ - { - "ErrorEquals": [ - "States.ALL" - ], - "Next": "Pass (2)" - } - ] + "Next": "DeregisterImage", + "Catch": [ + { + "ErrorEquals": [ + "States.ALL" + ], + "Next": "DeregisterImage" + } + ] + }, + "DeregisterImage": { + "Type": "Task", + "Resource": "arn:aws:states:::aws-sdk:ec2:deregisterImage", + "Arguments": { + "ImageId": "{% $states.input.ImageId %}" + }, + "Next": "ProcessSnapshots", + "Catch": [ + { + "ErrorEquals": [ + "States.ALL" + ], + "Next": "Pass" + } + ] + }, + "ProcessSnapshots": { + "Type": "Map", + "Items": "{% [$states.input.BlockDeviceMappings[$exists(Ebs)]] %}", + "ItemProcessor": { + "ProcessorConfig": { + "Mode": "INLINE" + }, + "StartAt": "DeleteSnapshotInMap", + "States": { + "DeleteSnapshotInMap": { + "Type": "Task", + "Resource": "arn:aws:states:::aws-sdk:ec2:deleteSnapshot", + "Arguments": { + "SnapshotId": "{% $states.input.Ebs.SnapshotId %}" }, - "Pass (2)": { - "Type": "Pass", - "End": true - } + "Next": "Pass (2)", + "Catch": [ + { + "ErrorEquals": [ + "States.ALL" + ], + "Next": "Pass (2)" + } + ] + }, + "Pass (2)": { + "Type": "Pass", + "End": true } - }, - "MaxConcurrency": 5, - "End": true - } + } + }, + "MaxConcurrency": 5, + "Next": "Pass" + }, + "Pass": { + "Type": "Pass", + "End": true } } - ], + }, + "MaxConcurrency": 3, "End": true - } + }} } }, "MaxConcurrency": 3, From 8b95b279bdfea441651620fda9215bb145678b28 Mon Sep 17 00:00:00 2001 From: "remote-swe-app[bot]" <123456+remote-swe-app[bot]@users.noreply.github.com> Date: Wed, 18 Jun 2025 06:12:08 +0000 Subject: [PATCH 2/2] Update snapshot test for AMI cleanup workflow changes --- cdk/test/__snapshots__/cdk.test.ts.snap | 167 +++++++++++------------- 1 file changed, 78 insertions(+), 89 deletions(-) diff --git a/cdk/test/__snapshots__/cdk.test.ts.snap b/cdk/test/__snapshots__/cdk.test.ts.snap index 566f5d92..ff7e0f29 100644 --- a/cdk/test/__snapshots__/cdk.test.ts.snap +++ b/cdk/test/__snapshots__/cdk.test.ts.snap @@ -1457,103 +1457,92 @@ Remote SWE Agents Team", "ProcessorConfig": { "Mode": "INLINE" }, - "StartAt": "Parallel", + "StartAt": "Cleanup", "States": { - "Parallel": { - "Type": "Parallel", - "Branches": [ - { - "StartAt": "DeleteImageBuilderImage", - "States": { - "DeleteImageBuilderImage": { - "Type": "Task", - "Resource": "arn:aws:states:::aws-sdk:imagebuilder:deleteImage", - "Arguments": { - "ImageBuildVersionArn": "{% $states.input.Tags[Key = 'Ec2ImageBuilderArn'].Value %}" - }, - "Next": "Pass", - "Catch": [ - { - "ErrorEquals": [ - "States.ALL" - ], - "Next": "Pass" - } - ] - }, - "Pass": { - "Type": "Pass", - "End": true - } - } + "Cleanup": { + "Type": "Map", + "Items": "{% [$states.input] %}", + "ItemProcessor": { + "ProcessorConfig": { + "Mode": "INLINE" }, - { - "StartAt": "DeregisterImage", - "States": { - "DeregisterImage": { - "Type": "Task", - "Resource": "arn:aws:states:::aws-sdk:ec2:deregisterImage", - "Arguments": { - "ImageId": "{% $states.input.ImageId %}" - }, - "Next": "Pass (1)", - "Catch": [ - { - "ErrorEquals": [ - "States.ALL" - ], - "Next": "Pass (1)" - } - ] + "StartAt": "DeleteImageBuilderImage", + "States": { + "DeleteImageBuilderImage": { + "Type": "Task", + "Resource": "arn:aws:states:::aws-sdk:imagebuilder:deleteImage", + "Arguments": { + "ImageBuildVersionArn": "{% $states.input.Tags[Key = 'Ec2ImageBuilderArn'].Value %}" }, - "Pass (1)": { - "Type": "Pass", - "End": true - } - } - }, - { - "StartAt": "ProcessSnapshots", - "States": { - "ProcessSnapshots": { - "Type": "Map", - "Items": "{% [$states.input.BlockDeviceMappings[$exists(Ebs)]] %}", - "ItemProcessor": { - "ProcessorConfig": { - "Mode": "INLINE" - }, - "StartAt": "DeleteSnapshotInMap", - "States": { - "DeleteSnapshotInMap": { - "Type": "Task", - "Resource": "arn:aws:states:::aws-sdk:ec2:deleteSnapshot", - "Arguments": { - "SnapshotId": "{% $states.input.Ebs.SnapshotId %}" - }, - "Next": "Pass (2)", - "Catch": [ - { - "ErrorEquals": [ - "States.ALL" - ], - "Next": "Pass (2)" - } - ] + "Next": "DeregisterImage", + "Catch": [ + { + "ErrorEquals": [ + "States.ALL" + ], + "Next": "DeregisterImage" + } + ] + }, + "DeregisterImage": { + "Type": "Task", + "Resource": "arn:aws:states:::aws-sdk:ec2:deregisterImage", + "Arguments": { + "ImageId": "{% $states.input.ImageId %}" + }, + "Next": "ProcessSnapshots", + "Catch": [ + { + "ErrorEquals": [ + "States.ALL" + ], + "Next": "Pass" + } + ] + }, + "ProcessSnapshots": { + "Type": "Map", + "Items": "{% [$states.input.BlockDeviceMappings[$exists(Ebs)]] %}", + "ItemProcessor": { + "ProcessorConfig": { + "Mode": "INLINE" + }, + "StartAt": "DeleteSnapshotInMap", + "States": { + "DeleteSnapshotInMap": { + "Type": "Task", + "Resource": "arn:aws:states:::aws-sdk:ec2:deleteSnapshot", + "Arguments": { + "SnapshotId": "{% $states.input.Ebs.SnapshotId %}" }, - "Pass (2)": { - "Type": "Pass", - "End": true - } + "Next": "Pass (2)", + "Catch": [ + { + "ErrorEquals": [ + "States.ALL" + ], + "Next": "Pass (2)" + } + ] + }, + "Pass (2)": { + "Type": "Pass", + "End": true } - }, - "MaxConcurrency": 5, - "End": true - } + } + }, + "MaxConcurrency": 5, + "Next": "Pass" + }, + "Pass": { + "Type": "Pass", + "End": true } } - ], + }, + "MaxConcurrency": 3, "End": true - } + }} } }, "MaxConcurrency": 3,