1 Answer
- Newest
- Most votes
- Most comments
0
This is a common issue with Windows Server Core updates, particularly with Microsoft Defender updates. Here are the recommended approaches to resolve this:
- First Approach - Update Configuration:
# Create a component that runs before update-windows $script = @' # Stop Windows Update and Defender services Stop-Service -Name wuauserv -Force Stop-Service -Name WinDefend -Force # Wait for services to stop completely Start-Sleep -Seconds 10 # Start services again Start-Service wuauserv Start-Service WinDefend # Wait for services to start Start-Sleep -Seconds 30 # Clear Windows Update cache Remove-Item "$env:SystemRoot\SoftwareDistribution\*" -Recurse -Force '@
- Second Approach - Exclude Defender Updates: Create a custom component that configures Windows Update to exclude Defender updates:
# Configure Windows Update to exclude Defender updates $script = @' $updateSession = New-Object -ComObject Microsoft.Update.Session $updateSearcher = $updateSession.CreateUpdateSearcher() $searchResult = $updateSearcher.Search("IsInstalled=0") foreach ($update in $searchResult.Updates) { if ($update.Title -like "*Defender*") { $update.AutoSelectOnWebSites = $false } } '@
- Third Approach - Use AWS-UpdateWindowsAmi Component: Instead of using update-windows, you could use the AWS-UpdateWindowsAmi component, which has better handling for Defender updates:
- name: UpdateWindows action: ExecutePowerShell inputs: commands: - | Install-WindowsFeature -Name UpdateServices-Services Start-Sleep -Seconds 30 Install-WindowsUpdate -AcceptAll -IgnoreReboot
Key Implementation Notes:
-
Component Ordering:
- Ensure your custom component runs BEFORE the update-windows component
- Set the appropriate dependencies in your recipe
-
Error Handling: Add error handling to your custom component:
try { # Your update script here exit 0 } catch { Write-Error $_.Exception.Message exit 1 }
- Infrastructure Configuration:
infrastructureConfiguration: instanceType: t3.medium # Recommend minimum t3.medium terminateInstanceOnFailure: true subnetId: subnet----# Optional: specify custom subnet
- Timeouts:
- Consider increasing the timeout settings in your Image Builder configuration
- Default timeout might not be sufficient for all updates
Best Practices:
-
Monitor Build Logs:
- Enable enhanced logging in EC2 Image Builder
- Monitor CloudWatch Logs for detailed troubleshooting
-
Testing:
- Test the build process in a development environment first
- Validate updates are applying correctly using:
Get-HotFix | Sort-Object InstalledOn -Descending
- Version Control:
- Maintain version control for your components and recipes
- Document any specific update exclusions or configurations
If these solutions don't resolve the issue, you might want to:
- Review Windows Update logs at C:\Windows\Logs\WindowsUpdate
- Check if there are any network connectivity issues
- Verify there's sufficient disk space (at least 20GB free recommended)
- Consider using a larger instance type during the build process
Relevant content
- asked a year ago
