Reputation: 167
I am trying to attach available ebs volume when ec2 instance is starting up. I am saving the available volume list in a variable and running for loop to attach but it's not working. Kindly advice Value stored in $vid variable vol-0f1afab1e58853cf4 vol-0cda4ca53406a13fa
foreach ($volumeid in $vid) {
$instanceId = Invoke-RestMethod -Uri http://169.254.169.254/latest/meta-data/instance-id
ec2-attach-volume --instance-id $instanceId --volume-id $volumeid }
</powershell>
Upvotes: 0
Views: 109
Reputation: 81356
1) You are missing the --device to attach the volume to.
2) Look in the instance logfile which is available in the AWS console and add the error messages that are displayed to your post if #1 does not solve your issue.
3) Have you assigned a role to the EC2 instance with permissions to access and mount EBS volumes? Verify this using the AWS CLI after the instance runs or using PowerShell with your scripts.
4) Under Windows, attached volumes often have to be placed "online" before they can be accessed. After attaching a volume, run diskmgmt.msc to verify if this is necessary. Generally this only happens the first time Windows sees a new disk (volume). Diskpart.exe and diskmgmt.msc have commands for bringing a volume online.
Upvotes: 1