From 6bd7e5941f7c13c01959539067e9e565770da7f4 Mon Sep 17 00:00:00 2001 From: acsbendi Date: Tue, 15 Jan 2019 17:34:22 +0100 Subject: [PATCH 1/4] Added test case for running multiple instances in the same command. --- tests/test_ec2/test_instances.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/test_ec2/test_instances.py b/tests/test_ec2/test_instances.py index 84b4fbd7..c0f0eea4 100644 --- a/tests/test_ec2/test_instances.py +++ b/tests/test_ec2/test_instances.py @@ -1254,3 +1254,18 @@ def test_create_instance_ebs_optimized(): ) instance.load() instance.ebs_optimized.should.be(False) + +@mock_ec2 +def test_run_multiple_instances_in_same_command(): + instance_count = 4 + client = boto3.client('ec2', region_name='us-east-1') + client.run_instances(ImageId='ami-1234abcd', + MinCount=instance_count, + MaxCount=instance_count) + reservations = client.describe_instances()['Reservations'] + + reservations[0]['Instances'].should.have.length_of(instance_count) + + instances = reservations[0]['Instances'] + for i in range(0, instance_count): + instances[i]['AmiLaunchIndex'].should.be(i) From 22288ef83b32e32d221c129fe1206e0aae38fe43 Mon Sep 17 00:00:00 2001 From: acsbendi Date: Tue, 15 Jan 2019 17:36:10 +0100 Subject: [PATCH 2/4] Implemented initializing ami_launch_index property. --- moto/ec2/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/moto/ec2/models.py b/moto/ec2/models.py index a450943b..cc333e79 100755 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -388,6 +388,7 @@ class Instance(TaggedEC2Resource, BotoInstance): self.ebs_optimized = kwargs.get("ebs_optimized", False) self.source_dest_check = "true" self.launch_time = utc_date_and_time() + self.ami_launch_index = kwargs.get("ami_launch_index", 0) self.disable_api_termination = kwargs.get("disable_api_termination", False) self._spot_fleet_id = kwargs.get("spot_fleet_id", None) associate_public_ip = kwargs.get("associate_public_ip", False) From ca5a8033e54ac049448c4c36394d80c588640668 Mon Sep 17 00:00:00 2001 From: acsbendi Date: Tue, 15 Jan 2019 17:37:22 +0100 Subject: [PATCH 3/4] Implemented providing ami_launch_index to the new Instance's constructor. --- moto/ec2/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/moto/ec2/models.py b/moto/ec2/models.py index cc333e79..11ad8b10 100755 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -720,6 +720,7 @@ class InstanceBackend(object): instance_tags = tags.get('instance', {}) for index in range(count): + kwargs["ami_launch_index"] = index new_instance = Instance( self, image_id, From e4768662818c42fe920379ce7cd7b093380da12c Mon Sep 17 00:00:00 2001 From: acsbendi Date: Tue, 15 Jan 2019 17:38:44 +0100 Subject: [PATCH 4/4] Implemented showing ami_launch_index property in responses. --- moto/ec2/responses/instances.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/moto/ec2/responses/instances.py b/moto/ec2/responses/instances.py index 3e4705f9..49f1face 100644 --- a/moto/ec2/responses/instances.py +++ b/moto/ec2/responses/instances.py @@ -244,7 +244,7 @@ EC2_RUN_INSTANCES = """