lony
lony

Reputation: 7750

EC2 and EBS how and what are the differences?

I have an AWS EC2 machine I want to attach storage to which after its shutdown isn't deleted. The management should be done using Cloudformation.

I so far, do this using the following snippet:

"BlockDeviceMappings": [
    {
        "DeviceName": "/dev/sda",
        "Ebs": {
            "DeleteOnTermination": "false",
            "VolumeSize": "10",
            "VolumeType": "gp2"
        }
    }
],

Reading also about AWS:EC2:Volume and AWS:EC2:VolumeAttachment can somebody explain the differences? What are the benefits and disadvantage using one way over the other? How do I use the other methods together with an EC2 instance?

Upvotes: 1

Views: 510

Answers (1)

Rocherlee
Rocherlee

Reputation: 2771

AWS:EC2:Volume just creates a new EBS volume. It's not Available for Use

AWS:EC2:VolumeAttachment allows you to attach the new volume to a running EC2 instance where it will be exposed as a block (storage) device.

So, you need to do AWS:EC2:Volume first to know the VolumeId, and then supply it to AWS:EC2:VolumeAttachment

{
"Type":"AWS::EC2::VolumeAttachment",
"Properties" : {
   "Device" : String,
   "InstanceId" : String,
   "VolumeId" : String
}
}

You use BlockDeviceMappings when you create an AMI or when you launch a new EC2 instance.

You use AWS::EC2::VolumeAttachment when you attach an EBS volume to a running EC2 instance. You can attach multiple additional EBS volumes.

You can also attach and detach root device as mentioned here

If an EBS volume is the root device of an instance, you must stop the instance before you can detach the volume. http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-detaching-volume.html

Upvotes: 2

Related Questions