Using AWS CDK, an EC2 instance with attached EBS can be created like this:
BlockDevice durableStorage = BlockDevice.builder()
.deviceName("/dev/sdf")
.volume(BlockDeviceVolume.ebs(
DURABLE_STORAGE_GB,
EbsDeviceOptions.builder()
.deleteOnTermination(false)
.encrypted(true)
.volumeType(EbsDeviceVolumeType.GP2)
.build()))
.build();
Instance instance = new Instance(
this,
"MyInstance",
InstanceProps.builder()
.blockDevices(List.of(durableStorage))
// more config here
.build());
If there is an update to the stack that involves a replacement to the EC2 instance, how is the EBS attachment managed? The old instance is kept until the new one has been created and only then is it destroyed, so how should one manage the transfer of the EBS volume to the new server? Is would this be managed in CloudFormation?