0

When the instance is launched from the custom AMI I could not retrieve password for the launched instance. This issue and resolution is discussed here and it worked.
These are the manual steps I performed:

  1. Open the Amazon EC2 console, and then connect to the original Windows EC2 instance using Remote Desktop Protocol (RDP).
  2. From the Windows Start menu, do the following:
    For Windows Server 2008 through Windows Server 2012 R2, open EC2ConfigService Settings, and then choose the Image tab.
    For Windows Server 2016 or later, open EC2 Launch Settings.
  3. For Administrator Password, choose Random.
  4. Select Shutdown without Sysprep *.
  5. Select Yes.
  6. Open the Amazon EC2 console, and then select Instances.
  7. Wait until the instance state changes to Stopped, and then choose your instance.
  8. Select Actions, Image, Create image. For Image name, enter a name. (Optional) For Image description, enter a description.
  9. Choose Create image.

I wanted to know if steps from 1 to 5 can be automated? The source instance has the following scripts, and wondering if any of these script will do the trick, if yes, then what parameter I need to pass

"C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\SendWindowsIsReady.ps1 -Schedule",  
"C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\InitializeInstance.ps1 -Schedule",  
"C:\ProgramData\Amazon\EC2-Windows\Launch\Scripts\SysprepInstance.ps1 -NoShutdown"  
LP13
  • 30,567
  • 53
  • 217
  • 400
  • Those scripts should be all you need; those are being run as provisioners at the end of a packer build right? – Paolo Dec 08 '22 at 17:33
  • Right now I am planning to run those script as a instance's `user_data`. I am planning to use packer once I figure out how to connect using WinRM :) – LP13 Dec 08 '22 at 18:01
  • Those scripts aren't meant to be run in the userdata..if you take a look at the scripts, you will see that they create Windows scheduled tasks which only run on following reboots. so for now, if you must run these in the userdata, then you will need to reboot the instance afterwards – Paolo Dec 08 '22 at 18:03

0 Answers0