Skip to content

Windows 2025 + EC2 Launch Agent V2 breaking userdata behavior

0

Hello, I'm posting this with the hope that it can save other people the time it took me to figure out.

Solution:

Microsoft has deprecated wmic with Windows Server 2025, which breaks the EC2 launch agent. The issue can be fixed by reinstalling wmic using this command in PowerShell (Admin):

DISM /Online /Add-Capability /CapabilityName:WMIC~~~~


Story time:

Instance type used: g4dn.4xlarge

I've recently started migrating one of our services to Win 2025 ( ami-09cb80360d5069de4 - base Amazon image of Windows 2025 used).

Old setup:

Previously, with version 1 of the "EC2 Launch Agent" we would call "InitializeInstance.ps1" in our scripts to prepare our server for imaging. After an Image was made, we would replace the old ami in the Auto Scaling Group's launch template and terminate the old warm pool instances. This would then trigger a recreation of the warm pool using the new AMI. Our launch templates have a powershell User Data script that runs once during warm-up. Later on, when we needed to scale, the instances were ready to go and would scale relatively fast.

What changed:

With version 2 of the "EC2 Launch Agent" and Windows Server 2025 the "InitializeInstance.ps1" script no longer exists. We replaced the call with EC2Launch.exe sysprep, everything else stayed the same, but here is where the fun began for me.

It turns out that Microsoft removed WMI command-line utility or C:\Windows\System32\wbem\wmic.exe. This causes the launch agent to fail during an initial warm-up of an instance on the step preReady-installEgpuManager-0, marking the stage preReady as failed and skipping the execution of user data. The instance then counts as warmed up and ready to go. However, on scale up, when we expect them to start right up, they have to first go through the user data script.

There is an error being logged in the agent.log file, thanks to which I was able to find the issue: Error: Error running task: failed to run task 'preReady-installEgpuManager-0': fork/exec C:\Windows\System32\wbem\wmic.exe: The system cannot find the file specified.

Please log when the User Data step is skipped. Currently it only logs this:

2025-05-16 12:28:08 Info: Stage: preReady completed.
2025-05-16 12:28:08 Info: User data was not provided. Skip running user data.
2025-05-16 12:28:09 Info: Initialize user-data state.
2025-05-16 12:28:09 Info: User-data state initialized successfully.
2025-05-16 12:28:09 Info: Stage: postReadyUserData completed.

Hopefully, the EC2 team can fix the issue as it is next to silent.

asked a year ago1.1K views

1 Answer
0
Accepted Answer

Thank you for sharing your experience and solution regarding the issue with Windows Server 2025 and EC2 Launch Agent v2. Your findings are valuable for the AWS community.

Indeed, the deprecation of the Windows Management Instrumentation Command-line (WMIC) utility in Windows Server 2025 has caused an unexpected issue with the EC2 Launch Agent v2. This change affects the agent's ability to execute certain tasks during instance initialization, specifically the 'preReady-installEgpuManager-0' step.

The solution you've provided, reinstalling WMIC using the DISM command, is a good workaround for this issue:

DISM /Online /Add-Capability /CapabilityName:WMIC~~~~

This command adds the WMIC capability back to the system, allowing the EC2 Launch Agent to function as expected.

Regarding the user data execution, it's important to note that by default, user data scripts run only once at the initial launch of an instance. The behavior you've described, where user data is skipped during the warm-up but executed during scale-up, is not the typical behavior and may be related to the issue you encountered.

Your suggestion to improve logging when the User Data step is skipped is a good one. More detailed logs could indeed help in troubleshooting such issues more quickly in the future.

It's worth mentioning that for Windows instances, EC2Launch v2 supports various customization options, including the ability to run user data before or after certain stages in the agent configuration file. If you need user data to run consistently, you might want to explore these configuration options.

Thank you again for sharing this information. It will undoubtedly be helpful for others encountering similar issues with Windows Server 2025 and EC2 Launch Agent v2.
Sources
Configure EC2Launch v2 settings for Windows instances - Amazon Elastic Compute Cloud
Use the EC2Launch v2 agent to perform tasks during EC2 Windows instance launch - Amazon Elastic Compute Cloud
Run commands when you launch an EC2 instance with user data input - Amazon Elastic Compute Cloud

answered a year ago

EXPERT

reviewed a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.