3535class IoTScenario :
3636 """Runs an interactive scenario that shows how to use AWS IoT."""
3737
38- def __init__ (self , iot_wrapper , iot_data_client , cfn_client ):
38+ def __init__ (self , iot_wrapper , iot_data_client , cfn_client , stack_name = "IoTBasicsStack" , template_path = None ):
3939 """
4040 :param iot_wrapper: An instance of the IoTWrapper class.
4141 :param iot_data_client: A Boto3 IoT Data Plane client.
4242 :param cfn_client: A Boto3 CloudFormation client.
43+ :param stack_name: Name for the CloudFormation stack.
44+ :param template_path: Path to the CloudFormation template file.
4345 """
4446 self .iot_wrapper = iot_wrapper
4547 self .iot_data_client = iot_data_client
@@ -48,11 +50,12 @@ def __init__(self, iot_wrapper, iot_data_client, cfn_client):
4850 self .certificate_arn = None
4951 self .certificate_id = None
5052 self .rule_name = None
51- self .stack_name = "IoTBasicsStack"
53+ self .stack_name = stack_name
54+ self .template_path = template_path or "../../../scenarios/basics/iot/iot_usecase/resources/cfn_template.yaml"
5255
5356 def _deploy_stack (self ):
5457 """Deploy CloudFormation stack and return outputs."""
55- with open ("../../../scenarios/basics/iot/iot_usecase/resources/cfn_template.yaml" , "r" ) as f :
58+ with open (self . template_path , "r" ) as f :
5659 template_body = f .read ()
5760
5861 try :
@@ -283,7 +286,11 @@ def _cleanup(self):
283286 iot_data_client = boto3 .client ("iot-data" )
284287 cfn_client = boto3 .client ("cloudformation" )
285288 wrapper = IoTWrapper (iot_client , iot_data_client )
286- scenario = IoTScenario (wrapper , iot_data_client , cfn_client )
289+
290+ stack_name = input ("Enter a name for the CloudFormation stack (default: IoTBasicsStack): " ).strip () or "IoTBasicsStack"
291+ template_path = input ("Enter path to CloudFormation template (default: ../../../scenarios/basics/iot/iot_usecase/resources/cfn_template.yaml): " ).strip () or "../../../scenarios/basics/iot/iot_usecase/resources/cfn_template.yaml"
292+
293+ scenario = IoTScenario (wrapper , iot_data_client , cfn_client , stack_name , template_path )
287294
288295 thing_name = q .ask ("Enter a name for the IoT thing: " , q .non_empty )
289296 rule_name = q .ask ("Enter a name for the topic rule: " , q .non_empty )
@@ -292,3 +299,5 @@ def _cleanup(self):
292299 except Exception as e :
293300 logger .exception ("An error occurred during the scenario." )
294301 print (f"An error occurred: { e } " )
302+
303+
0 commit comments