Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/testinfra-ami-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,17 @@ jobs:

if [ -n "$STAGE2_AMI_IDS" ]; then
for ami_id in $STAGE2_AMI_IDS; do
SNAPSHOT_IDS=$(aws ec2 describe-images \
--region ap-southeast-1 \
--image-ids "$ami_id" \
--query 'Images[*].BlockDeviceMappings[*].Ebs.SnapshotId' \
--output text)
Comment on lines +149 to +153
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description/title mention cleaning up EBS volumes, but this change deletes EBS snapshots associated with the AMI. If the intent is snapshot cleanup (likely the actual cost driver), please update the PR description/title for accuracy; if volumes are also being left behind, add a corresponding describe-volumes/delete-volume cleanup based on the same execution-id tags.

Copilot uses AI. Check for mistakes.
echo "Deregistering stage 2 AMI: $ami_id"
aws ec2 deregister-image --region ap-southeast-1 --image-id "$ami_id" || true
for snap_id in $SNAPSHOT_IDS; do
echo "Deleting snapshot: $snap_id"
aws ec2 delete-snapshot --region ap-southeast-1 --snapshot-id "$snap_id" || true
Comment on lines +149 to +158
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--query 'Images[*].BlockDeviceMappings[*].Ebs.SnapshotId' --output text can yield None/empty values for non-EBS mappings; the for snap_id in $SNAPSHOT_IDS loop will then attempt to delete an invalid snapshot id. Filter out nulls in the query (or guard in bash) so only real snapshot IDs are passed to delete-snapshot.

Copilot uses AI. Check for mistakes.
done
Comment on lines 155 to +159
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aws ec2 delete-snapshot ... || true will silently leave snapshots behind when deletion fails (e.g., eventual-consistency right after deregistration, snapshots still referenced, or IAM permission issues), which undermines the goal of this cleanup. Consider adding a short retry/backoff (and/or collecting failures and failing the step at the end) so leaks are surfaced and cleanup is more reliable.

Copilot uses AI. Check for mistakes.
done
else
echo "No stage 2 AMI to clean up"
Expand Down
Loading