1

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.

Shailesh Sutar
  • 1,427
  • 4
  • 22
  • 40

2 Answers2

0

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 :)

MLu
  • 23,798
  • 5
  • 54
  • 81
0

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

Shahad
  • 326
  • 1
  • 6