From e743daf9f7cee4d21721981d5cc880194b053e8a Mon Sep 17 00:00:00 2001 From: Stefano Date: Thu, 29 May 2025 17:16:08 -0500 Subject: [PATCH] Moved creation of the instance after database creation --- infrastructure/stack.py | 52 ++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/infrastructure/stack.py b/infrastructure/stack.py index dd91299..466cac4 100644 --- a/infrastructure/stack.py +++ b/infrastructure/stack.py @@ -111,32 +111,6 @@ class IptvManagerStack(Stack): iam.ManagedPolicy.from_aws_managed_policy_name("AmazonCognitoReadOnly") ) - # EC2 Instance - instance = ec2.Instance( - self, - "IptvManagerInstance", - vpc=vpc, - vpc_subnets=ec2.SubnetSelection(subnet_type=ec2.SubnetType.PUBLIC), - instance_type=ec2.InstanceType.of( - ec2.InstanceClass.T2, ec2.InstanceSize.MICRO - ), - machine_image=ec2.AmazonLinuxImage( - generation=ec2.AmazonLinuxGeneration.AMAZON_LINUX_2023 - ), - security_group=security_group, - key_pair=key_pair, - role=role, - # Option: 1: Enable auto-assign public IP (free tier compatible) - associate_public_ip_address=True, - ) - - # Option: 2: Create Elastic IP (not free tier compatible) - # eip = ec2.CfnEIP( - # self, "IptvManagerEIP", - # domain="vpc", - # instance_id=instance.instance_id - # ) - # Add Cognito User Pool user_pool = cognito.UserPool( self, @@ -282,6 +256,32 @@ class IptvManagerStack(Stack): iam.ManagedPolicy.from_aws_managed_policy_name("AmazonSSMReadOnlyAccess") ) + # EC2 Instance (created after all dependencies are ready) + instance = ec2.Instance( + self, + "IptvManagerInstance", + vpc=vpc, + vpc_subnets=ec2.SubnetSelection(subnet_type=ec2.SubnetType.PUBLIC), + instance_type=ec2.InstanceType.of( + ec2.InstanceClass.T2, ec2.InstanceSize.MICRO + ), + machine_image=ec2.AmazonLinuxImage( + generation=ec2.AmazonLinuxGeneration.AMAZON_LINUX_2023 + ), + security_group=security_group, + key_pair=key_pair, + role=role, + # Option: 1: Enable auto-assign public IP (free tier compatible) + associate_public_ip_address=True, + ) + + # Option: 2: Create Elastic IP (not free tier compatible) + # eip = ec2.CfnEIP( + # self, "IptvManagerEIP", + # domain="vpc", + # instance_id=instance.instance_id + # ) + # Update instance with userdata instance.add_user_data(userdata.render())