We have windows servers that do application initialization which takes almost 3-4 hours for servers to be online. So to avoid downtime we use autoscaling group lifecycle hooks. Now we want to shut down all the servers at night and start them in the morning for cost optimization. Is it possible to run the PowerShell user-data script on the restart of the server? I followed link here however, cloud-init does not support Windows PowerShell user-data format as per this link.
Any suggestions would be a great help. Thank you.
I believe there is a way to run a PowerShell script from user data, however user-data script is only run on the first instance boot, not on every restart. At least that’s how it is in Linux, I guess on Windows it would be similar. Which means user-data / cloud-init script won’t do what you want anyway.
You should better create a job that runs every time the instance starts like it’s documented here: Use PowerShell to Create Job that Runs at Startup
Hope that helps :)
You can add the < persist> tag to have it run on every boot https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-windows-user-data.html#user-data-batch-scripts