Support alternate EC2:ModifyInstanceAttribute request syntax (#4234)

This commit is contained in:
Brian Pandola 2021-08-27 23:04:15 -07:00 committed by GitHub
parent 6f4b6080f8
commit a1e415ec03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -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():

View File

@ -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])