@@ -46,10 +46,10 @@ Options
4646
4747 -t, --type Type of volume. (Default: config.volume.type)
4848
49- -i, --iops N
49+ -i, --iops N
5050 IOPS for volume. Only valid if type=io1, io2, gp3. (Default: config.volume.iops)
5151
52- --throughput N
52+ --throughput N
5353 The throughput for a volume, with a maximum of 1,000 MiB/s. (Default: config.volume.throughput)
5454
5555 --not-encrypted Flag to make the volume un-encyrpted. Default is to create
@@ -58,11 +58,11 @@ Options
5858 --max-total-created-size SIZE_GB
5959 Maximum total size in GB of all volumes created by the instance.
6060 (Default: config.limits.max_logical_volume_size)
61-
61+
6262 --max-attached-volumes N
6363 Maximum number of attached volumes.
6464 (Default: config.limits.max_ebs_volume_count)
65-
65+
6666 --max-created-volumes N
6767 Maximum number of volumes that can be created by the instance.
6868 (Default: MAX_ATTACHED_VOLUMES)
@@ -166,6 +166,8 @@ function get_next_logical_device() {
166166}
167167
168168function create_and_attach_volume() {
169+ TAG=amazon-ebs-autoscale-creation-time
170+
169171 local instance_id=$( get_metadata instance-id)
170172 local availability_zone=$( get_metadata placement/availability-zone)
171173 local region=${availability_zone% ?}
@@ -184,7 +186,7 @@ function create_and_attach_volume() {
184186 attached_volumes=$(
185187 aws ec2 describe-volumes \
186188 --region $region \
187- --filters " Name=attachment.instance-id,Values=$instance_id "
189+ --filters Name=attachment.instance-id,Values=$instance_id Name=tag-key,Values= $TAG
188190 )
189191
190192 if [ $? -eq 0 ]; then
@@ -201,7 +203,7 @@ function create_and_attach_volume() {
201203 created_volumes=$(
202204 aws ec2 describe-volumes \
203205 --region $region \
204- --filters " Name=tag:source- instance,Values=$instance_id "
206+ --filters Name=attachment. instance-id ,Values=$instance_id Name=tag-key,Values= $TAG
205207 )
206208
207209 if [ $? -eq 0 ]; then
@@ -218,7 +220,7 @@ function create_and_attach_volume() {
218220 total_created_size=$(
219221 aws ec2 describe-volumes \
220222 --region $region \
221- --filters " Name=tag:source- instance,Values=$instance_id " \
223+ --filters Name=attachment. instance-id ,Values=$instance_id Name=tag-key,Values= $TAG \
222224 --query ' sum(Volumes[].Size)' \
223225 --output text
224226 )
@@ -246,7 +248,7 @@ function create_and_attach_volume() {
246248 if [ " ` echo $attached_volumes | jq ' .Volumes | length' ` " -ge " $MAX_ATTACHED_VOLUMES " ]; then
247249 error " maximum number of attached volumes reached ($MAX_ATTACHED_VOLUMES )"
248250 fi
249-
251+
250252 # check if there are available device names
251253 local device=$( get_next_logical_device)
252254 if [ -z " $device " ]; then
@@ -266,7 +268,7 @@ function create_and_attach_volume() {
266268 local volume=" "
267269 for i in $( eval echo " {0..$max_attempts }" ) ; do
268270
269- local ebs_autoscale_tags=' [{"Key":"source-instance","Value":"' $instance_id ' "},{"Key":"amazon-ebs-autoscale-creation-time ","Value":"' $timestamp ' "}]'
271+ local ebs_autoscale_tags=' [{"Key":"source-instance","Value":"' $instance_id ' "},{"Key":' $TAG ' ","Value":"' $timestamp ' "}]'
270272 local tag_specifications=' [{"ResourceType":"volume","Tags":' $( jq -sc ' add' <( echo " $ebs_autoscale_tags " ) <( echo " $instance_tags " ) ) ' }]'
271273
272274 # Note: Shellcheck says the $vars in this command should be double quoted to prevent globbing and word-splitting,
@@ -324,15 +326,15 @@ function create_and_attach_volume() {
324326 --instance-id $instance_id \
325327 --volume-id $volume_id \
326328 > /dev/null
327-
329+
328330 status=" $? "
329331 if [ ! " $status " -eq 0 ]; then
330332 logthis " deleting volume $volume_id "
331333 aws ec2 delete-volume \
332334 --region $region \
333335 --volume-id $volume_id \
334336 > /dev/null
335-
337+
336338 error " could not attach volume to instance"
337339 fi
338340 set -e
0 commit comments