diff --git a/moto/ec2/responses/fleets.py b/moto/ec2/responses/fleets.py index e63a74322812..ff44fa84b6ff 100644 --- a/moto/ec2/responses/fleets.py +++ b/moto/ec2/responses/fleets.py @@ -33,6 +33,22 @@ def create_fleet(self) -> str: launch_template_configs = self._get_multi_param( param_prefix="LaunchTemplateConfigs" ) + # Our multi_param function doesn't understand when to return a list, a string, or a dictionary + # So we'll have to help it a little, by explicitly asking for a dict if we're getting anything else back + for idx, config in enumerate(launch_template_configs, start=1): + if (overrides := config.get("Overrides")) and not isinstance( + overrides, dict + ): + config["Overrides"] = self._get_multi_param( + f"LaunchTemplateConfigs.{idx}.Overrides", + skip_result_conversion=True, + ) + if (spec := config.get("LaunchTemplateSpecification")) and not isinstance( + spec, dict + ): + config["LaunchTemplateSpecification"] = self._get_multi_param_dict( + f"LaunchTemplateConfigs.{idx}.LaunchTemplateSpecification" + ) excess_capacity_termination_policy = self._get_param( "ExcessCapacityTerminationPolicy" diff --git a/tests/test_ec2/test_fleets.py b/tests/test_ec2/test_fleets.py index e2db4ceba2c0..a8080ce80eb3 100644 --- a/tests/test_ec2/test_fleets.py +++ b/tests/test_ec2/test_fleets.py @@ -328,6 +328,35 @@ def test_create_fleet_request_with_tags(): assert tag in instance["Tags"] +@mock_aws +@pytest.mark.parametrize( + "overrides", [{"InstanceType": "t2.nano"}, {"AvailabilityZone": "us-west-1"}] +) +def test_create_fleet_using_launch_template_config__overrides_single(overrides): + conn = boto3.client("ec2", region_name="us-east-2") + + template_id, _ = get_launch_template(conn, instance_type="t2.medium") + + fleet_id = conn.create_fleet( + LaunchTemplateConfigs=[ + { + "LaunchTemplateSpecification": {"LaunchTemplateId": template_id}, + # Verify we parse the incoming parameters correctly, + # even when only supplying a dictionary with a single key + "Overrides": [overrides], + }, + ], + TargetCapacitySpecification={ + "DefaultTargetCapacityType": "spot", + "TotalTargetCapacity": 1, + }, + )["FleetId"] + + fleet = conn.describe_fleets(FleetIds=[fleet_id])["Fleets"][0] + lt_config = fleet["LaunchTemplateConfigs"][0] + assert lt_config["Overrides"] == [overrides] + + @mock_aws def test_create_fleet_using_launch_template_config__overrides(): conn = boto3.client("ec2", region_name="us-east-2")