Skip to content

Commit 6a5b7b3

Browse files
tejasgntejasgn1
authored andcommitted
providing option for custom stack and stack_template
1 parent c2147d9 commit 6a5b7b3

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

python/example_code/iot/scenario_iot_basics.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@
3535
class 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

Comments
 (0)