I need to setup an EC2 instance and attach an existing EBS Volume via CloudFormation.
Currently there is an AutoScalingGroup for the EC2 instance with minsize=1
and maxsize=1
in place. I am not able to attach the EBS Volume to the LaunchConfiguration for the AutoScalingGroup. The reason is I can't find an option similar to AWS::EC2::VolumeAttachment.
Questions:
It appears you wish to attach an existing Amazon EBS volume to the Amazon EC2 instance that is launched by Auto Scaling.
It is a common practice to use Auto Scaling with min/max of 1. This ensures that an instance is running even if it fails or if an Availability Zone fails.
However, I don't think you will find an Auto Scaling or CloudFormation option to attach an existing Amazon EBS volume. An Auto Scaling group is used to launch lots of identical instances for horizontal scaling. They will have their own EBS volumes, but they would not "share" an EBS volume.
Rather than attempting to attach it via an Auto Scaling / CloudFormation configuration, you could use a User Data script that runs when the instance is launched. It could use the AWS CLI to attach a volume to itself. The script would need to retrieve the instance's InstanceId via metadata, then pass that to the attachment call.