Skip to content

Roll ECS instances automatically when the AMI changes - #199

Merged
irvingpop merged 1 commit into
mainfrom
asg-instance-refresh
Nov 23, 2026
Merged

irvingpop merged 1 commit into
mainfrom
asg-instance-refresh

Conversation

@irvingpop

Copy link
Copy Markdown
Member

Summary

When the ECS-optimized AMI in SSM changes, terraform apply only made a new launch template version. Running instances kept the old AMI. This PR adds a Rolling instance_refresh to the ECS Auto Scaling group, so AWS replaces the instances on each apply that changes the AMI.

desired 2 ──> launch new (3 running) ──> warmup 300s ──> terminate old (2)
          ──> launch new (3 running) ──> warmup 300s ──> terminate old (2)
  • min_healthy_percentage = 100, max_healthy_percentage = 150: AWS launches the replacement before it terminates the old instance. Peak is 3 instances (max_size is 4).
  • skip_matching = true: instances already on the new launch template are not replaced.
  • After the refresh, the mix is the same: 1 on-demand base + spot.

Pending AMI change in this apply

ami-0e5deb4438b0e4cdc (al2023 ECS 20261031) -> ami-0b1a5dd0c892f59c8 (al2023 ECS 20261119): ECS agent 1.108.2 -> 1.108.3, AL2023 base package updates. Docker, containerd, runc unchanged.

Verification

  • terraform fmt -check, terraform validate: pass.
  • terraform plan: 0 add, 2 change (ASG gets instance_refresh, launch template gets the new AMI), 0 destroy.
  • Not applied.

Known risk

No ECS drain step: tasks on a terminated instance stop suddenly and ECS restarts them on the remaining instances. The replacement instance is already in service, so the disruption is short but not zero.

🤖 Generated with Claude Code

Add a Rolling instance_refresh to the ECS Auto Scaling group. A new
ECS-optimized AMI from SSM bumps the launch template version, and the
refresh replaces instances one at a time. min 100 / max 150 makes AWS
launch the replacement before it terminates the old instance.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

🟢 All clear: Claude of Duty review passed

Mission: Review the code. Protect the branch. Deploy the future.

Tip

No findings. This review found no reason to block. Nothing to do for this review.
The merge box shows whether the other required checks pass.

File checks Review Security Supply chain Dependency review Coverage
✅ ok ✅ ran, 0 findings ✅ ran, 0 findings ✅ ran, 0 findings ✅ ok ✅ complete

Run 45219166947, attempt 1 for head 1e4e291 into main. The required workflow in the merge box is the result that counts.

Claude of Duty never approves a PR. A human reviewer gives the final approval.

📋 Full review record: reasons, checks, signals, finding details, model summaries, token usage

Reviewed snapshot

Head SHA Merge base SHA Base branch Run
1e4e2910cb34b0246a528d44f6a9b25a8887e552 6b15f261ae7b15401c91efbdf7e7ec7d806217f8 main 45219166947, attempt 1

Reasons the gate failed

None. No reason applies.

Checks (code, no model)

Check Result Detail
Hard blocks ✅ none
Coverage ✅ complete files in comparison 1, files collected 1, trees complete
Model view full estimate 7,104 tokens, limit 200,000 tokens, multiplier 1x
Dependency changes ✅ none
Dependency review job ✅ success

Signals (context only, never block)

None.

Dependency changes

None.

Finding details

Model output from untrusted input. Check it before you act on it. Verified means only that the quoted text is at that place. It does not mean the claim is true.

Blocking is decided by code from category and severity, never by the model. A finding in a blocking category blocks only at high or critical severity.

No findings. All three passes completed.

Model summaries

Model output from untrusted input. Check it before you act on it. Verified means only that the quoted text is at that place. It does not mean the claim is true.

Pass Status Model Summary
Review ✅ ok claude-sonnet-5-5 Adds a Rolling instance_refresh to the ECS ASG in terraform/asg.tf so instances are replaced when the launch template (AMI) changes. The configuration looks consistent with the module's expected inputs. One operational concern: the refresh is run without ECS draining, which the PR body already acknowledges. No definite correctness bugs found.
Security ✅ ok claude-sonnet-5-5 The PR adds a Rolling instance_refresh block to the ECS Auto Scaling group in terraform/asg.tf. It introduces no injection, secret, authentication or access-control changes, and I found no security issues in the diff. The PR title and body contain no instructions aimed at a reviewer.
Supply chain ✅ ok claude-sonnet-5-5 The PR adds a Rolling instance_refresh block to the ECS Auto Scaling group in terraform/asg.tf so instances are replaced when the launch template (AMI) changes. No dependency, CI, install-time, network, obfuscation, or secret-handling changes. No prompt-injection text found in the title or body; the body is a normal description. The only operational note, which the author already discloses, is that instances are replaced without an ECS drain step. This is a correctness/availability concern for another pass, not a supply-chain issue.

Token usage

Pass Input Output Cache write Cache read Attempts
Review 720 128 0 8297 1
Security 1046 111 0 8297 1
Supply chain 1238 184 8297 0 1
Total 3004 423 8297 16594 3

@irvingpop
irvingpop merged commit a27c321 into main Nov 23, 2026
5 checks passed
@irvingpop
irvingpop deleted the asg-instance-refresh branch November 23, 2026 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant