Elastigroups support Stateful configurations for data and assets maintenance. Specifically for Data volumes, we support two options – “reattaching” the volume or using a snapshot and creating a new volume upon instance launch – for more info see here.

while using the stateful feature with the reattach option, we launch an instance and then attach the volumes.

If you want to execute a user data script on the instance after the volumes are attached to the instance, you should enter the following script at the beginning of the user data script:


EC2_INSTANCE_ID=$(curl -s
EC2_AVAIL_ZONE=`curl -s`
EC2_REGION="`echo \"$EC2_AVAIL_ZONE\" | sed -e 's:\([0-9][0-9]*\)[a-z]*\$:\\1:'`"

until [ "$DATA_STATE" == "attached" ]; do

        DATA_STATE=$(aws ec2 describe-volumes \
                --region $EC2_REGION \
                --filters \
                Name=attachment.instance-id,Values=$EC2_INSTANCE_ID \
                Name=attachment.device,Values=$DEVICE_NAME \
                --query Volumes[].Attachments[].State \
                --output text)

        echo $DATA_STATE      
        sleep 5


echo "volume is ready"