Mark S
Mark S

Reputation: 47

Enabling mounted EBS volumes at startup in Amazon EC2 on Windows

I'm trying to bring a drive online automatically on startup in Windows on EC2, the device is present in the Disk Management app, just offline.

I'm using a custom AMI built using Packer and would like to have it do this when the AMI is launched into an instance.

My current thinking is to create a scheduled job in Powershell triggered on startup, however this job never runs and I can't work out why.

$script = {Get-Disk | Where-Object IsOffline –Eq $True | Set-Disk –IsOffline $False}
$trigger = New-JobTrigger -AtStartup
Register-ScheduledJob -Name 'Mount EBS Drives' -ScriptBlock $script -Trigger $trigger

What am I doing wrong with this script and/or is there another way to achieve my goal?

Upvotes: 0

Views: 1493

Answers (1)

user1956801
user1956801

Reputation: 135

If these instances are being launched by an Auto-Scaling Group, you can define a block of UserData in the Launch Configuration that can contain PowerShell script that runs on first boot. It can be made to run on each boot with a bit of tweaking.

Look under "Executing Scripts with User Data" in this AWS document: http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-instance-metadata.html

Regrettably, I am still learning this, and found your question in the course of my research. It looks like this question is actually about Scheduled Tasks and this is not reflected in the tags.

Upvotes: 1

Related Questions