AWSTemplateFormatVersion: '2010-09-09' Description: 'Create an EC2 instance with port 3001 open and auto-generate network resources' Resources: VPC: Type: AWS::EC2::VPC Properties: CidrBlock: 10.0.0.0/16 EnableDnsHostnames: true EnableDnsSupport: true PublicSubnet: Type: AWS::EC2::Subnet Properties: VpcId: !Ref VPC AvailabilityZone: !Select - 0 - !GetAZs Ref: 'AWS::Region' CidrBlock: 10.0.1.0/24 MapPublicIpOnLaunch: true InternetGateway: Type: AWS::EC2::InternetGateway AttachGateway: Type: AWS::EC2::VPCGatewayAttachment Properties: VpcId: !Ref VPC InternetGatewayId: !Ref InternetGateway PublicRouteTable: Type: AWS::EC2::RouteTable Properties: VpcId: !Ref VPC PublicRoute: Type: AWS::EC2::Route DependsOn: AttachGateway Properties: RouteTableId: !Ref PublicRouteTable DestinationCidrBlock: 0.0.0.0/0 GatewayId: !Ref InternetGateway SubnetRouteTableAssociation: Type: AWS::EC2::SubnetRouteTableAssociation Properties: SubnetId: !Ref PublicSubnet RouteTableId: !Ref PublicRouteTable SecurityGroup: Type: AWS::EC2::SecurityGroup Properties: GroupDescription: Allow port 3001 access VpcId: !Ref VPC SecurityGroupIngress: - IpProtocol: tcp FromPort: 3001 ToPort: 3001 CidrIp: 0.0.0.0/0 - IpProtocol: tcp FromPort: 22 ToPort: 22 CidrIp: 0.0.0.0/0 EC2Instance: Type: AWS::EC2::Instance Properties: InstanceType: t3.large SecurityGroupIds: - !Ref SecurityGroup SubnetId: !Ref PublicSubnet ImageId: ami-04996ef73316c465c Outputs: InstanceId: Description: InstanceId of the newly created EC2 instance Value: !Ref EC2Instance PublicDNS: Description: Public DNSName of the newly created EC2 instance Value: !GetAtt EC2Instance.PublicDnsName