We have a cloud formation template which deploys the jenkins.war to the AWS ElasticBeanstalk with configuration in "ebs.config" and included it via .ebextensions. The EBS volume got attached, and environment launched successfully.
When we do stack update for any changes in war file, when it is trying to deploy the new war file, we are getting error in ElasticBeanstalk, for “01_attach-volume” command in "ebs.config":
Stack error:
The following resource(s) failed to update: [JenkinsEBSVol].
Volume properties other than AutoEnableIO cannot be updated. Change the properties back to previous values and update the stack again.
ElasticBeanstalk error:
[Instance: i-07ba0e47cc4ae929e] Command failed on instance. Return code: 255 Output: A client error (VolumeInUse) occurred when calling the AttachVolume operation: vol-050a4afd80895bb79 is already attached to an instance. command 01_attach-volume in .ebextensions/ebs.config failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
It is throwing error when executing command in ebs.config when updating the stack because it is trying to attach the volume that is already attached. So how can we address this ? How to ignore the attach-volume command when it is already attached? Any help………….
Stack error:
The following resource(s) failed to update: [JenkinsEBSVol].
Volume properties other than AutoEnableIO cannot be updated. Change the properties back to previous values and update the stack again.
ElasticBeanstalk error:
[Instance: i-07ba0e47cc4ae929e] Command failed on instance. Return code: 255 Output: A client error (VolumeInUse) occurred when calling the AttachVolume operation: vol-050a4afd80895bb79 is already attached to an instance. command 01_attach-volume in .ebextensions/ebs.config failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
ebs.config:
{
"commands": {
"01_clear-if-unmounted": {
"command": "if ! mount | grep /usr/share/tomcat7/.jenkins > /dev/nul; then rm -rf /usr/share/tomcat7/.jenkins; fi"
},
"02_attach-volume": {
"command": "aws ec2 attach-volume --region us-east-1 --volume-id $EBSVolumeId --instance-id $(curl -s http://169.254.169.254/latest/meta-data/instance-id) --device /dev/sdh",
"env": {
"EBSVolumeId": {
"Fn::GetOptionSetting": {
"OptionName": "EBSVolumeId"
}
}
}
},
"03_wait": {
"command": "sleep 10"
},
"04_mkdir": {
"command" : "mkdir /usr/share/tomcat7/.jenkins"
},
"05_trymount": {
"command" : "mount /dev/sdh /usr/share/tomcat7/.jenkins",
"ignoreErrors": "true"
},
"06_format-if-not-already": {
"command": "if find /usr/share/tomcat7/.jenkins -maxdepth 0 -empty | read v; then mkfs -t ext3 /dev/sdh; fi"
}
}
}