Recently, AWS announced a major new capability: the ability to dynamically modify EBS volumes. AWS calls the new capabilities “Elastic Volumes” and many properties of EBS volumes are now changeable — though reduction of a volume’s size is not.
I was blown away by the announcement but didn’t have time until now to explore Elastic Volumes. This week, a client asked me to show him how to expand Windows Server EBS volumes — and I got my chance.
As always, AWS Console operations are really just calls to the AWS API and so I was very pleased to see that AWS updated its PowerShell cmdlets the same day that Elastic Volumes was announced. New cmdlets to manage Elastic Volumes include Edit-EC2Volume
and Get-EC2VolumeModification
. That’s the good news. The bad news is that the AWS documentation for Windows describes using the AWS CLI to monitor modifications instead of the PowerShell cmdlets. (I’ve left a feedback and the doc writers are amazingly responsive, so by the time you find this on Google it may have been updated.)
That piqued my curiosity and resulted in the script you see below. This is a simple (or, given the way the output is formatted, maybe not so simple) PowerShell script that uses Get-EC2VolumeModification
to display the results of modifications. (I am in awe of the things you can do with PowerShell when combined with the AWS API.)
Here are some usage notes:
- The calculated duration field (using PowerShell calculated expressions with, essentially, an embedded script within a script) is inaccurate until the modification is complete
- I eliminated fields in the output that I don’t especially care about like “OriginalIops” and “TargetSize”. If you want those, just add them back to the
Select-Object
statement - Obviously, Ctrl-C breaks stops the endless loop 🙂
- Bonus! It appears that
Get-EC2VolumeModification
will report all Elastic Volume modifications that have ever occurred in the account. In the screenshot nearby, you can see I had one volume being modified and two that were previously modified. I don’t know how long the history is maintained. But if it is permanent, what a wonderful record of changes this could become. You can even see how to use this in billing reports.
As always, I hope this is of some use to you.
Import-Module AWSPowerShell <# .SYNOPSIS Watches EBS volume modifications via Get-Ec2VolumeModification .DESCRIPTION Loops endlessly issuing Get-Ec2VolumeModification every 30 seconds to report progress, status, start time, stop time and duration of each volume modification .PARAMETER none .INPUTS none .OUTPUTS Formatted console output .EXAMPLE PS C:\> ./Watch-EBS-volume-resizing.ps1 Outputs to the console modified output from Get-Ec2VolumeModification .NOTES For more information on EBS volume modification, see http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ebs-expand-volume.html (c) 2017 Air11 Technology LLC -- licensed under the Apache OpenSource 2.0 license, https://opensource.org/licenses/Apache-2.0 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author's blog: https://yobyot.com #> While (1) { Get-EC2VolumeModification | Select-Object -Property VolumeId, Progress, @{ Name = 'Duration'; Expression = { $d = (New-TimeSpan -Start $_.StartTime -End $_.EndTime); "{0:hh}:{0:mm}" -f $d } }, @{ Name = 'Status'; Expression = { $_.ModificationState } }, StartTime, EndTime | Format-Table -AutoSize -Wrap Start-Sleep -Seconds 30 }
Leave a Reply