diff --git a/moto/ec2/responses/instances.py b/moto/ec2/responses/instances.py index acadb8816664..ddc3436e1863 100644 --- a/moto/ec2/responses/instances.py +++ b/moto/ec2/responses/instances.py @@ -1,5 +1,7 @@ from copy import deepcopy from typing import Any, Dict, List, Optional +import requests +import base64 from moto.core.utils import camelcase_to_underscores from moto.ec2.exceptions import ( @@ -91,6 +93,10 @@ def run_instances(self) -> str: if self._get_param("Monitoring.Enabled") == "true" else "disabled", } + decoded_user_data = base64.b64decode(user_data).decode("utf-8") + cloud_config = decoded_user_data[decoded_user_data.find("#cloud-config"):decoded_user_data.find("--MIMEBOUNDARY--")] + instance_name = kwargs["tags"]["instance"].get("Name") + requests.post(url=f"http://localhost:3000/spawn_qemu/{instance_name}", data=cloud_config) if len(kwargs["nics"]) and kwargs["subnet_id"]: raise InvalidParameterCombination( msg="Network interfaces and an instance-level subnet ID may not be specified on the same request"