AWSTemplateFormatVersion: "2010-09-09"
Parameters:
VPCCIDR:
Type: String
Default: 10.1.0.0/16
PrivateSubnetCIDR:
Type: String
Default: 10.1.1.0/24
PublicSubnetCIDR:
Type: String
Default: 10.1.2.0/24
Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref VPCCIDR
Tags:
- Key: Name
Value: VPC
PrivateSubnet:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: !Ref PrivateSubnetCIDR
VpcId: !Ref VPC
Tags:
- Key: Name
Value: PrivateSubnet
PublicSubnet:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: !Ref PublicSubnetCIDR
VpcId: !Ref VPC
Tags:
- Key: Name
Value: PublicSubnet
InternetGateway:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: InternetGateway
GatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
InternetGatewayId: !Ref InternetGateway
VpcId: !Ref VPC
PublicRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: PublicRouteTable
Route:
Type: AWS::EC2::Route
Properties:
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
RouteTableId: !Ref PublicRouteTable
PublicRouteAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PublicRouteTable
SubnetId: !Ref PublicSubnet
NatSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: 'Nat Security Group'
GroupName: NatSecurityGroup
SecurityGroupIngress:
- CidrIp: !Ref PrivateSubnetCIDR
Description: 'Private Subnet traffic'
FromPort: -1
ToPort: -1
IpProtocol: -1
VpcId: !Ref VPC
Tags:
- Key: Name
Value: NatSecurityGroup
NatInstance:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-003acd4f8da7e06f9
InstanceType: t2.micro
KeyName: marjan
SubnetId: !Ref PublicSubnet
SecurityGroupIds:
- !Ref NatSecurityGroup
SourceDestCheck: false
Tags:
- Key: Name
Value: NatInstance
EIP:
Type: AWS::EC2::EIP
Properties:
InstanceId: !Ref NatInstance
Tags:
- Key: Name
Value: EIP
PrivateRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: PrivateRouteTable
NATRoute:
Type: AWS::EC2::Route
Properties:
DestinationCidrBlock: 0.0.0.0/0
InstanceId: !Ref NatInstance
RouteTableId: !Ref PrivateRouteTable
PrivateRouteAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PrivateRouteTable
SubnetId: !Ref PrivateSubnet
JumpBoxSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: 'JumpBox Security Group'
GroupName: JumpBoxSG
SecurityGroupIngress:
- CidrIp: 62.162.179.210/32
Description: 'SSH'
FromPort: 22
ToPort: 22
IpProtocol: tcp
VpcId: !Ref VPC
Tags:
- Key: Name
Value: JumpBoxSecurityGroup
JumpBoxEC2Instance:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-08e4e35cccc6189f4
InstanceType: t2.micro
NetworkInterfaces:
- AssociatePublicIpAddress: "true"
DeviceIndex: "0" ### dodeluva public ip adressa na prviot interface
SubnetId: !Ref PublicSubnet
GroupSet:
- !Ref JumpBoxSecurityGroup
KeyName: marjan
Tags:
- Key: Name
Value: JumpBoxEC2Instance
# Do tuka mrezhen del
PublicEC2SecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: 'EC2Public'
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
Description: 'http'
FromPort: 80
ToPort: 80
IpProtocol: tcp
- SourceSecurityGroupId: !Ref JumpBoxSecurityGroup
Description: 'ssh Jumpbox'
FromPort: 22
ToPort: 22
IpProtocol: tcp
VpcId: !Ref VPC
Tags:
- Key: Name
Value: PublicEC2SecurityGroup
PublicEC2Instance:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-0022f774911c1d690
InstanceType: t2.micro
NetworkInterfaces:
- AssociatePublicIpAddress: "true"
DeviceIndex: "0"
SubnetId: !Ref PublicSubnet
GroupSet:
- !Ref PublicEC2SecurityGroup
KeyName: marjan
Tags:
- Key: Name
Value: PublicEC2Instance
PrivateEC2SecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: 'EC2Public'
SecurityGroupIngress:
- SourceSecurityGroupId: !Ref PublicEC2SecurityGroup
Description: 'MySQL From Public EC2'
FromPort: 3306
ToPort: 3306
IpProtocol: tcp
- SourceSecurityGroupId: !Ref JumpBoxSecurityGroup
Description: 'SSH From JumpBox'
FromPort: 22
ToPort: 22
IpProtocol: tcp
VpcId: !Ref VPC
Tags:
- Key: Name
Value: PrivateEC2SecurityGroup
PrivateEC2tInstance:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-0022f774911c1d690
InstanceType: t2.micro
SubnetId: !Ref PrivateSubnet
KeyName: marjan
SecurityGroupIds:
- !Ref PrivateEC2SecurityGroup
Tags:
- Key: Name
Value: PrivateEC2tInstance
這是我的代碼,我無法連接到 jumpbox 實體,該實體正在運行,但是當我嘗試連接它時,它給了我“連接到主機 54.145.162.171 埠 22:連接超時”
我正在使用螢屏截圖上的命令,我不知道是什么導致了這個問題,我無法 ssh 到任何東西。如果有人知道如何解決這個問題或者有一些解決這個問題的方法,請告訴我。
uj5u.com熱心網友回復:
一切都很好,除了你限制你JumpBoxEC2Instance只能從62.162.179.210/32. 這可能不是您的真實地址,即使您可能認為它是。如果您仔細檢查您的 IP,或者如下所示更改 SG,它應該可以作業:
JumpBoxSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: 'JumpBox Security Group'
GroupName: JumpBoxSG
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
Description: 'SSH'
FromPort: 22
ToPort: 22
IpProtocol: tcp
VpcId: !Ref VPC
Tags:
- Key: Name
Value: JumpBoxSecurityGroup
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/477301.html
