From a1e415ec03f2b432e3e324da0b03f0f6af1a82fe Mon Sep 17 00:00:00 2001 From: Brian Pandola Date: Fri, 27 Aug 2021 23:04:15 -0700 Subject: [PATCH] Support alternate EC2:ModifyInstanceAttribute request syntax (#4234) --- moto/ec2/responses/instances.py | 16 ++++++++++++++++ tests/test_ec2/test_instances.py | 3 ++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/moto/ec2/responses/instances.py b/moto/ec2/responses/instances.py index ca17e8bfd..b92b2ea1b 100644 --- a/moto/ec2/responses/instances.py +++ b/moto/ec2/responses/instances.py @@ -177,6 +177,7 @@ class InstanceResponse(BaseResponse): def modify_instance_attribute(self): handlers = [ + self._attribute_value_handler, self._dot_value_instance_attribute_handler, self._block_device_mapping_handler, self._security_grp_instance_attribute_handler, @@ -258,6 +259,21 @@ class InstanceResponse(BaseResponse): ) return EC2_MODIFY_INSTANCE_ATTRIBUTE + def _attribute_value_handler(self): + attribute_key = self._get_param("Attribute") + + if attribute_key is None: + return + + if self.is_not_dryrun("ModifyInstanceAttribute"): + value = self._get_param("Value") + normalized_attribute = camelcase_to_underscores(attribute_key) + instance_id = self._get_param("InstanceId") + self.ec2_backend.modify_instance_attribute( + instance_id, normalized_attribute, value + ) + return EC2_MODIFY_INSTANCE_ATTRIBUTE + def _security_grp_instance_attribute_handler(self): new_security_grp_list = [] for key, value in self.querystring.items(): diff --git a/tests/test_ec2/test_instances.py b/tests/test_ec2/test_instances.py index bec2b9717..99f8fa70f 100644 --- a/tests/test_ec2/test_instances.py +++ b/tests/test_ec2/test_instances.py @@ -1775,8 +1775,9 @@ def test_instance_termination_protection(): r"The instance '{}' may not be terminated.*$".format(instance_id) ) + # Use alternate request syntax for setting attribute. client.modify_instance_attribute( - InstanceId=instance_id, DisableApiTermination={"Value": False} + InstanceId=instance_id, Attribute="disableApiTermination", Value="false" ) client.terminate_instances(InstanceIds=[instance_id])