I deal with asymmetric clusters of EC2 nodes. There are certain operations which can only be safely carried out when none of the EBS volumes in the cluster are in an "optimizing" state (e.g. after a resize). Checking this manually via the console is time-consuming and error prone - so I tried to script this.
Getting a list of the hostname/instance id and attached volumes is easy enough...
aws --profile "$PROFILE" ec2 describe-instances --region "$REGION" --filters \ "Name=tag:Name,Values=${PREFIX}*" \ --query 'Reservations[*].Instances[*].[Tags[?Key==`Name`].Value,InstanceId,BlockDeviceMappings[*].Ebs.VolumeId]' However it appears that I need to make a separate aws cli call, describe-volumes-modifications, to find out if the volume is optimizing.
That should not be a problem, however:
If any of the volume ids passed as arguments is not currently optimizing (or possibly has not been modified since creation?) aws cli returns an error and no data
There does not appear to be a list of exit codes applicable in this scenario, on testing the same error code is returned in different error scenarios
the text of the error does not appear to be readily machine-parsable:
"An error occurred (InvalidVolumeModification.NotFound) when calling the DescribeVolumesModifications operation: Modification for volume 'vol-01abcd3e7f8612345' does not exist. (and yes, the volume exists)
It does not help that the error is sent to stderr even when I ask for JSON output (and I don't get any json either).
I can pre-empt the first issue by checking a single volume at time, but I don't know how to script around the latter 2, differentiating between no current optimizing state vs something else went wrong.
Asking Google I just get a sea of pages describing how to "optimize" my use of AWS infrastructure.