Parameters:
KeyName:
Description: existing EC2 KeyPair, SSH access to the instances.
Type: AWS::EC2::KeyPair::KeyName
ConstraintDescription: name of an existing EC2 KeyPair.
Resources:
SeoulAWSVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.1.0.0/16
EnableDnsHostnames: true
EnableDnsSupport: true
# InstanceTenancy: "String"
# Ipv4IpamPoolId: "String"
# Ipv4NetmaskLength: "Number"
Tags:
- Key: Name
Value: Seoul-AWS-VPC
PublicSN1:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: ap-northeast-2a
CidrBlock: 10.1.1.0/24
Tags:
- Key: Name
Value: Public-SN-1
VpcId: !Ref SeoulAWSVPC
PublicSN2:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: ap-northeast-2c
CidrBlock: 10.1.2.0/24
Tags:
- Key: Name
Value: Public-SN-2
VpcId: !Ref SeoulAWSVPC
PrivateSN1:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: ap-northeast-2a
CidrBlock: 10.1.3.0/24
Tags:
- Key: Name
Value: Private-SN-1
VpcId: !Ref SeoulAWSVPC
PrivateSN2:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: ap-northeast-2c
CidrBlock: 10.1.4.0/24
Tags:
- Key: Name
Value: Private-SN-2
VpcId: !Ref SeoulAWSVPC
SeoulAWSIGW:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: Seoul-AWS-IGW
SeoulIGWAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
InternetGatewayId: !Ref SeoulAWSIGW
VpcId: !Ref SeoulAWSVPC
SeoulAWSRT:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref SeoulAWSVPC
Tags:
- Key: Name
Value: CloudNeta-Public-RT
SeoulDefaultRoute:
Type: AWS::EC2::Route
DependsOn: SeoulIGWAttachment
Properties:
RouteTableId: !Ref SeoulAWSRT
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref SeoulAWSIGW
SeoulPublicSNRouteTableAssociation1:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref SeoulAWSRT
SubnetId: !Ref PublicSN1
SeoulPublicSNRouteTableAssociation2:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref SeoulAWSRT
SubnetId: !Ref PublicSN2
SeoulPrivateSNRouteTableAssociation1:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref SeoulAWSRT
SubnetId: !Ref PrivateSN1
SeoulPrivateSNRouteTableAssociation2:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref SeoulAWSRT
SubnetId: !Ref PrivateSN2
SeoulSG:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Enable HTTP access via port 80 and SSH access via port 22
VpcId: !Ref SeoulAWSVPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0
- IpProtocol: icmp
FromPort: -1
ToPort: -1
CidrIp: 0.0.0.0/0
- IpProtocol: tcp
FromPort: 443
ToPort: 443
CidrIp: 0.0.0.0/0
NetPublicEC21:
Type: AWS::EC2::Instance
Properties:
InstanceType: t2.micro
ImageId: ami-048c8b90bfe9b49b8
KeyName: !Ref KeyName
Tags:
- Key: Name
Value: Net-Public-EC21
NetworkInterfaces:
- DeviceIndex: 0
SubnetId: !Ref PublicSN1
GroupSet:
- !Ref SeoulSG
AssociatePublicIpAddress: true
UserData:
Fn::Base64:
!Sub |
#! /bin/bash
amazon-linux-extras install epel -y
yum install httpd -y
systemctl enable --now httpd
echo "<h1> ho </h1>" > /var/www/html/
NetPublicEC22:
Type: AWS::EC2::Instance
Properties:
InstanceType: t2.micro
ImageId: ami-048c8b90bfe9b49b8
KeyName: !Ref KeyName
Tags:
- Key: Name
Value: Net-Public-EC22
NetworkInterfaces:
- DeviceIndex: 0
SubnetId: !Ref PublicSN1
GroupSet:
- !Ref SeoulSG
AssociatePublicIpAddress: true
UserData:
Fn::Base64:
!Sub |
#! /bin/bash
amazon-linux-extras install epel -y
yum install httpd -y
systemctl enable --now httpd
echo "<h1> ho </h1>" > /var/www/html/
NetPrivateEC21:
Type: AWS::EC2::Instance
Properties:
InstanceType: t2.micro
ImageId: ami-048c8b90bfe9b49b8
KeyName: !Ref KeyName
Tags:
- Key: Name
Value: Net-Private-EC21
NetworkInterfaces:
- DeviceIndex: 0
SubnetId: !Ref PrivateSN1
GroupSet:
- !Ref SeoulSG
UserData:
Fn::Base64:
!Sub |
#! /bin/bash
amazon-linux-extras install epel -y
yum install httpd -y
systemctl enable --now httpd
echo "<h1> ho </h1>" > /var/www/html/
NetPrivateEC22:
Type: AWS::EC2::Instance
Properties:
InstanceType: t2.micro
ImageId: ami-048c8b90bfe9b49b8
KeyName: !Ref KeyName
Tags:
- Key: Name
Value: Net-Private-EC22
NetworkInterfaces:
- DeviceIndex: 0
SubnetId: !Ref PrivateSN1
GroupSet:
- !Ref SeoulSG
UserData:
Fn::Base64:
!Sub |
#! /bin/bash
amazon-linux-extras install epel -y
yum install httpd -y
systemctl enable --now httpd
echo "<h1> ho </h1>" > /var/www/html/
ALBTG:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Properties:
Name: ALB-TG
Port: 80
Protocol: TCP
HealthCheckPort: 80
VpcId: !Ref SeoulAWSVPC
Targets:
- Id: !Ref NetPrivateEC21
Port: 80
- Id: !Ref NetPrivateEC22
Port: 80
ALB:
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
DependsOn: SeoulIGWAttachment
Properties:
Type: network
Name: ALB
Scheme: internal
Subnets:
- !Ref PrivateSN1
- !Ref PrivateSN2
SecurityGroups:
- !Ref SeoulSG
Tags:
- Key: Name
Value: ALB
ALBListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
DefaultActions:
- Type: forward
TargetGroupArn: !Ref ALBTG
LoadBalancerArn: !Ref ALB
Port: 80
Protocol: TCP
SeoulPrivateDNS:
Type: AWS::Route53::HostedZone
DependsOn: SeoulAWSVPC
Properties:
Name: seoul.internal
VPCs:
- VPCId: !Ref SeoulAWSVPC
VPCRegion: ap-northeast-2
HostedZoneTags:
- Key: Name
Value: SeoulDomain
DNSRecordinstance1:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneId: !Ref SeoulPrivateDNS
Name: NetPublicEC21.seoul.internal
Type: A
TTL: 60
ResourceRecords:
- !GetAtt NetPublicEC21.PrivateIp
DNSRecordinstance2:
Type: AWS::Route53::RecordSet
Properties:
HostedZoneId: !Ref SeoulPrivateDNS
Name: NetPublicEC22.seoul.internal
Type: A
TTL: 60
ResourceRecords:
- !GetAtt NetPublicEC22.PrivateIp