From 0b4889ad377ac773659735a26fd9779d631d7db6 Mon Sep 17 00:00:00 2001 From: Pepe Fagoaga Date: Wed, 16 Aug 2023 23:55:24 +0200 Subject: [PATCH] feat(ec2): Add Instance Monitoring attribute (#6678) --- moto/ec2/models/instances.py | 1 + moto/ec2/responses/instances.py | 7 +++++-- tests/test_ec2/test_instances.py | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/moto/ec2/models/instances.py b/moto/ec2/models/instances.py index 19a2dac0b..8463ed9c3 100644 --- a/moto/ec2/models/instances.py +++ b/moto/ec2/models/instances.py @@ -120,6 +120,7 @@ class Instance(TaggedEC2Resource, BotoInstance, CloudFormationModel): in_ec2_classic = not bool(self.subnet_id) self.key_name = kwargs.get("key_name") self.ebs_optimized = kwargs.get("ebs_optimized", False) + self.monitoring_state = kwargs.get("monitoring_state", "disabled") self.source_dest_check = "true" self.launch_time = utc_date_and_time() self.ami_launch_index = kwargs.get("ami_launch_index", 0) diff --git a/moto/ec2/responses/instances.py b/moto/ec2/responses/instances.py index e1d2e0bcf..c1ec8fc92 100644 --- a/moto/ec2/responses/instances.py +++ b/moto/ec2/responses/instances.py @@ -84,6 +84,9 @@ class InstanceResponse(EC2BaseResponse): or None, "iam_instance_profile_arn": self._get_param("IamInstanceProfile.Arn") or None, + "monitoring_state": "enabled" + if self._get_param("Monitoring.Enabled") == "true" + else "disabled", } if len(kwargs["nics"]) and kwargs["subnet_id"]: raise InvalidParameterCombination( @@ -472,7 +475,7 @@ EC2_RUN_INSTANCES = """