AWSTemplateFormatVersion: 2010-09-09 Metadata: 'AWS::CloudFormation::Designer': 802ed097-ef96-425d-abea-10111969d895: size: width: 60 height: 60 position: x: 150 'y': 210 z: 0 Parameters: KeyName: Description: Name of an existing EC2 KeyPair to enable SSH access to the instances Type: 'AWS::EC2::KeyPair::KeyName' ConstraintDescription: must be the name of an existing EC2 KeyPair. LatestAmiId: Type: 'AWS::SSM::Parameter::Value' Default: '/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2' Resources: VPC: Type: 'AWS::EC2::VPC' Properties: EnableDnsSupport: 'true' EnableDnsHostnames: 'true' CidrBlock: 10.0.0.0/16 Tags: - Key: Application Value: !Ref 'AWS::StackName' - Key: Network Value: Public - Key: Name Value: EDMVPC PublicSubnet0: Type: 'AWS::EC2::Subnet' Properties: VpcId: !Ref VPC AvailabilityZone: !Sub - '${AWS::Region}${AZ}' - AZ: a CidrBlock: 10.0.0.0/20 MapPublicIpOnLaunch: 'true' Tags: - Key: Application Value: !Ref 'AWS::StackName' - Key: Network Value: Public - Key: Name Value: !Join - '' - - EDMVPC - '-public-' - a WebServerSecurityGroup: Type: 'AWS::EC2::SecurityGroup' Properties: GroupDescription: open ports 22 and 80 to enbale ssh and http requests. VpcId: !Ref VPC SecurityGroupIngress: - IpProtocol: tcp FromPort: 22 ToPort: 22 CidrIp: 0.0.0.0/0 - IpProtocol: tcp FromPort: 80 ToPort: 80 CidrIp: 0.0.0.0/0 InternetGateway: Type: "AWS::EC2::InternetGateway" Properties: Tags: - Key: "Application" Value: Ref: "AWS::StackName" - Key: "Network" Value: "Public" - Key: "Name" Value: !Join - '' - - "EDMVPC" - '-IGW' GatewayToInternet: Type: "AWS::EC2::VPCGatewayAttachment" Properties: VpcId: Ref: "VPC" InternetGatewayId: Ref: "InternetGateway" PublicRouteTable: Type: "AWS::EC2::RouteTable" Properties: VpcId: Ref: "VPC" Tags: - Key: "Application" Value: Ref: "AWS::StackName" - Key: "Network" Value: "Public" - Key: "Name" Value: !Join - '' - - "EDMVPC" - '-public-route-table' PublicRoute: Type: "AWS::EC2::Route" DependsOn: "GatewayToInternet" Properties: RouteTableId: Ref: "PublicRouteTable" DestinationCidrBlock: "0.0.0.0/0" GatewayId: Ref: "InternetGateway" PublicSubnetRouteTableAssociation0: Type: "AWS::EC2::SubnetRouteTableAssociation" Properties: SubnetId: Ref: "PublicSubnet0" RouteTableId: Ref: "PublicRouteTable" PublicNetworkAcl: Type: "AWS::EC2::NetworkAcl" Properties: VpcId: Ref: "VPC" Tags: - Key: "Application" Value: Ref: "AWS::StackName" - Key: "Network" Value: "Public" - Key: "Name" Value: !Join - '' - - "EDMVPC" - '-public-nacl' InboundHTTPPublicNetworkAclEntry: Type: "AWS::EC2::NetworkAclEntry" Properties: NetworkAclId: Ref: "PublicNetworkAcl" RuleNumber: "100" Protocol: "-1" RuleAction: "allow" Egress: "false" CidrBlock: "0.0.0.0/0" PortRange: From: "0" To: "65535" OutboundPublicNetworkAclEntry: Type: "AWS::EC2::NetworkAclEntry" Properties: NetworkAclId: Ref: "PublicNetworkAcl" RuleNumber: "100" Protocol: "-1" RuleAction: "allow" Egress: "true" CidrBlock: "0.0.0.0/0" PortRange: From: "0" To: "65535" PublicSubnetNetworkAclAssociation0: Type: "AWS::EC2::SubnetNetworkAclAssociation" Properties: SubnetId: Ref: "PublicSubnet0" NetworkAclId: Ref: "PublicNetworkAcl" EC2Instance: Type: 'AWS::EC2::Instance' Properties: ImageId: !Ref LatestAmiId SubnetId: !Ref PublicSubnet0 InstanceType: t2.micro KeyName: !Ref KeyName SecurityGroupIds: - !Ref WebServerSecurityGroup BlockDeviceMappings: - DeviceName: /dev/sdm Ebs: VolumeType: gp3 Iops: 100 DeleteOnTermination: false VolumeSize: 8 UserData: !Base64 'Fn::Sub': > #!/bin/bash -xe sudo yum -y install httpd sudo systemctl enable --now httpd.service sudo curl --output-dir /var/www/html/ -O https://raw.githubusercontent.com/axios/axios/v1.1.3/dist/axios.js sudo curl --output-dir /var/www/html/ -O https://raw.githubusercontent.com/axios/axios/v1.1.3/sandbox/client.html sudo cp /var/www/html/client.html /var/www/html/index.html Metadata: 'AWS::CloudFormation`::Designer': id: 802ed097-ef96-425d-abea-10111969d895 DeletionPolicy: Delete Outputs: ServiceIPAddress: Description: URL of visual UI by IP Value: !Join - '' - - 'http://' - !GetAtt EC2Instance.PublicIp - /