AWSTemplateFormatVersion: '2010-09-09' Description: Deploy EC2 instance using a specific AMI, configure a security group with ingress rules for SSH and port 3001, and create VPC and subnet. Parameters: AMI: Type: String Default: ami-021141a79f4c8fc02 # Default to your AMI ID if needed InstanceType: Type: String Default: t3.large # Default to t3.large VpcCidrBlock: Type: String Default: 10.0.0.0/16 # Default to a private network range SubnetCidrBlock: Type: String Default: 10.0.1.0/24 # Default to a smaller subnet range SecurityGroupName: Type: String Default: ShuffleSG Resources: # Create the VPC VPC: Type: AWS::EC2::VPC Properties: CidrBlock: !Ref VpcCidrBlock EnableDnsSupport: "true" EnableDnsHostnames: "true" Tags: - Key: Name Value: ShuffleVPC # Create the Subnet within the VPC Subnet: Type: AWS::EC2::Subnet Properties: CidrBlock: !Ref SubnetCidrBlock VpcId: !Ref VPC AvailabilityZone: !Select [ 0, !GetAZs '' ] MapPublicIpOnLaunch: "true" Tags: - Key: Name Value: ShuffleSubnet # Create the Security Group for the EC2 instance SecurityGroup: Type: AWS::EC2::SecurityGroup Properties: GroupName: !Ref SecurityGroupName VpcId: !Ref VPC SecurityGroupIngress: - IpProtocol: tcp FromPort: 22 ToPort: 22 CidrIp: 0.0.0.0/0 # Allow SSH from anywhere - IpProtocol: tcp FromPort: 3001 ToPort: 3001 CidrIp: 0.0.0.0/0 # Allow traffic on port 3001 from anywhere # Create an EC2 instance EC2Instance: Type: AWS::EC2::Instance Properties: ImageId: !Ref AMI InstanceType: !Ref InstanceType NetworkInterfaces: - AssociatePublicIpAddress: true DeviceIndex: 0 GroupSet: - !Ref SecurityGroup SubnetId: !Ref Subnet Tags: - Key: Name Value: Shuffle AMI Test Instance CpuOptions: CoreCount: 1 ThreadsPerCore: 1 PrivateDnsNameOptions: HostnameType: "ip-name" EnableResourceNameDnsARecord: true EnableResourceNameDnsAAAARecord: false Outputs: InstanceId: Description: "Instance ID of the created EC2 instance" Value: !Ref EC2Instance PublicIP: Description: "Public IP address of the EC2 instance" Value: !GetAtt EC2Instance.PublicIp VPCId: Description: "VPC ID" Value: !Ref VPC SubnetId: Description: "Subnet ID" Value: !Ref Subnet SecurityGroupId: Description: "Security Group ID" Value: !Ref SecurityGroup