Answer – B
The AWS Documentation mentions the following.
Option B is correct because When an instance is terminated, Amazon Elastic Compute Cloud (Amazon EC2) uses the value of the DeleteOnTermination attribute for each root EBS volume to determine whether to preserve or delete the volume when the instance is terminated. By default, the DeleteOnTermination attribute for an instance`s root volume is set to true, but it is set to false for all other volume types.
To preserve the root volume when an instance is terminated, change the DeleteOnTermination attribute for the root volume to false.
Option A is invalid since the flag needs to be set on the EBS volume.
Option C is invalid because (-f) no such parameter exists as per AWS Documentation, and this command is used to delete the volume. See the below correct syntax to delete a volume using CLI.
aws ec2 delete-volume --volume-id vol-049df61146cXXXX
Option D is invalid because command syntax is not correct, (=) should be used, but (-) is used, see the actual syntax below.
aws ec2 modify-instance-attribute\ --instance-id i-1234567890abcdef0 \ --block-device-mappings `DeviceName=/dev/sda1,Ebs={DeleteOnTermination=false}`
In AWS Documentation, the format is given in JSON, so if you follow that, you have to specify the JSON in a file mapping.json
[{\"DeviceName\": \"/dev/sda1\",\"Ebs\":{\"DeleteOnTermination\":false}}]
And run the command as below.
aws ec2 modify-instance-attribute --block-device-mappings
file://mapping.json
If you don`t want to follow this, another syntax provided above is also correct.
For more information on the Delete on termination flag, please refer to the below URLs-
https://aws.amazon.com/premiumsupport/knowledge-center/deleteontermination-ebs/
https://docs.aws.amazon.com/cli/latest/reference/ec2/modify-instance-attribute.html