Automation Flowchart
This diagram shows the full execution flow of the upgrade automation, including the DryRun path, the happy path, the 8-cycle verification chain, the stop when Setup is still running, cumulative-update patching, rollback, and failure cleanup paths.
Reading the Diagram
| Path | Description |
|---|---|
| DryRun=true | Runs pre-flight checks only, never modifies the instance |
| Happy path (solid lines down) | Full upgrade: backup → drivers → EC2Launch v2 → upgrade → verify → patch → cleanup |
| Verification chain | InitialUpgradeWait then up to 8 VerifyUpgradeN cycles with a VerifyIntervalMinutes aws:sleep between each (default 40 minutes, about 4 hours 50 minutes in total). If Setup is still running at the last check, the run stops at StopSetupStillRunning without rolling back |
| Setup still running | If the last check finds Setup still working, the run ends at StopSetupStillRunning without rollback or cleanup, whatever AutoRollback is set to. The media volume, backup AMI and any temporary instance profile stay in place so Setup can finish. Delete the media volume after the instance reports Windows Server 2022 |
| Rollback path (AutoRollback=true) | On upgrade failure: restore root volume from the backup AMI snapshot via Replace Root Volume |
| Failure path (AutoRollback=false) | On upgrade failure: clean up volumes and profiles, then fail loud for investigation |
| Dotted lines | Failure cleanup shortcuts — any step that fails routes to the appropriate cleanup path |
Why the verification chain is unrolled into 8 cycles
A single long-polling aws:executeScript step cannot wait for the upgrade to finish: the aws:executeScript handler is hard-capped at 600 seconds, regardless of the step's timeoutSeconds. A single step set to wait several hours is killed at the 10-minute mark while the OS is still mid-upgrade.
The chain works around this:
InitialUpgradeWait—aws:sleep PT10M(theaws:sleepaction has no 600s cap).VerifyUpgrade1..VerifyUpgrade8— each anaws:executeScriptwithtimeoutSecondsunder 480s, safely inside the 600s cap.Sleep1..Sleep7—aws:sleepofVerifyIntervalMinutes(default 40) between verify cycles.- Each
VerifyUpgradeNclassifies the instance: UPGRADE_COMPLETE branches toCleanupUpgradeVolume; FATAL (IMAGE_STATE_UNDEPLOYABLE) raises immediately and routes to rollback; in-progress falls through to the next sleep. After cycle 8,BranchOnVerify8stops the run atStopSetupStillRunningif Setup is still working, and goes toCollectSetupLogsand the rollback branch only if Setup is confirmed not running.
Total window: 10 minutes plus 7 sleeps of VerifyIntervalMinutes, plus verify time. With the default of 40 minutes that is about 4 hours 50 minutes.
Key Design Principles
- No orphaned resources: Every success, failure and rollback path cleans up the upgrade EBS volume and removes any temporary instance profile the automation attached. The one exception is
StopSetupStillRunning, which keeps both on purpose because Setup is still using them. - Patching is best-effort: The
InstallPinnedUpdates→VerifyPatchLevelsegment usesonFailure: Continue. A patch failure never aborts the run — the OS upgrade already succeeded. - Temp profile always removed: The
RemoveTempProfilestep usesonFailure: Abort— if profile removal itself fails (rare: throttling, transient API error), the automation halts loudly so you know to clean up manually. - Existing instance profiles are never modified: If the instance already has an instance profile (with or without SSM permissions), the automation either uses it or fails with guidance — it never attaches/detaches the instance's own profile.
- EC2Launch v2 runs pre-upgrade: v2 supports Server 2016, so migrating before the upgrade carries the agent cleanly into 2022.