0

I have two stacks: myData and myWorker. The worker uses the data. I get errors when deleting the worker. The errors complain that his attachment to the data is still active.

myData is long lived and contains myVolume, an AWS::EC2::Volume.

myWorker exists only occasionally and contains myServer and myMountPoint, an AWS::EC2::Instance and an AWS::EC2::VolumeAttachment.

This doesn't work out. delete-stack on myWorker reports:

DELETE_FAILED Volume detachment between volume-id vol-XXXX and instance-id i-YYYY at device /dev/sdX is in busy state

That seems reasonable. The sequence is probably:

create myWorker
  create myServer
  create myMountPoint
... later ...
delete-stack myWorker
   delete myMountPoint
   delete myServer

In which case the server is still running and probably using the mount point.

But that seems unlikely.

create myWorker
  create myServer
  create myMountPoint
  start up myServer
     mount that mount point
     start services including disk mounting
... later ...
delete-stack myWorker
   stop up myServer
     stop services & unmount disk
   delete myMountPoint
   delete myServer

So, help? Where is this sequence actually documented, and how can I fix this?

wjordan
  • 19,770
  • 3
  • 85
  • 98
Ben Hyde
  • 1,503
  • 12
  • 14

1 Answers1

1

Where is this sequence actually documented [...]

The AWS::EC2::VolumeAttachment behavior you described is noted at the start of the resource's CloudFormation documentation:

Important

Before this resource can be deleted (and therefore the volume detached), you must first unmount the volume in the instance. Failure to do so results in the volume being stuck in the busy state while it is trying to detach, which could possibly damage the file system or the data it contains.

If an Amazon EBS volume is the root device of an instance, it cannot be detached while the instance is in the "running" state. To detach the root volume, stop the instance first.


[...] and how can I fix this?

For typical use-cases like yours where the EC2 instance uses an attached EBS volume throughout the instance's lifecycle, you can declare your EBS volume attachment using the Volumes property on the AWS::EC2::Instance resource instead of a separate AWS::EC2::VolumeAttachment resource. The Volumes property lets the instance properly shut down first (unmounting any mounted volumes is part of the shutdown process) before the volume is detached from the EC2 instance.

wjordan
  • 19,770
  • 3
  • 85
  • 98