25-6-19-云计算复习12

好的!以下是一道**对标真题难度**的 CloudFormation 设计题,涵盖 VPC、子网、安全组、路由表、NAT 网关、实例角色等多个知识点,**贴近 COMP5349/4349 期末考试中 Question 7 的风格**,可用于模拟练习。

------

## ✅ CloudFormation 设计题(模拟真题风格)

------

### 📘 场景设定:

你正在阅读一个 CloudFormation 模板片段,该模板为一个 Web 应用创建了基础网络架构和两台 EC2 实例。以下是该模板的 YAML 片段(已简化):

```yaml
Parameters:
KeyName:
Type: AWS::EC2::KeyPair::KeyName
Default: labkey

Resources:
MyVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.10.0.0/16

IGW:
Type: AWS::EC2::InternetGateway

VPCGatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId: !Ref MyVPC
InternetGatewayId: !Ref IGW

PublicSubnet:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref MyVPC
CidrBlock: 10.10.1.0/24
MapPublicIpOnLaunch: true

PrivateSubnet:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref MyVPC
CidrBlock: 10.10.2.0/24

PublicRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref MyVPC

PublicRoute:
Type: AWS::EC2::Route
DependsOn: VPCGatewayAttachment
Properties:
RouteTableId: !Ref PublicRouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref IGW

PublicSubnetRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref PublicSubnet
RouteTableId: !Ref PublicRouteTable

NATGatewayEIP:
Type: AWS::EC2::EIP

NATGateway:
Type: AWS::EC2::NatGateway
Properties:
AllocationId: !GetAtt NATGatewayEIP.AllocationId
SubnetId: !Ref PublicSubnet

PrivateRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref MyVPC

PrivateRoute:
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref PrivateRouteTable
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !Ref NATGateway

PrivateSubnetRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref PrivateSubnet
RouteTableId: !Ref PrivateRouteTable

WebSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Allow HTTP
VpcId: !Ref MyVPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 80
ToPort: 80
CidrIp: 0.0.0.0/0

AppSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Allow HTTP from Web
VpcId: !Ref MyVPC
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 8080
ToPort: 8080
SourceSecurityGroupId: !Ref WebSecurityGroup

WebServer:
Type: AWS::EC2::Instance
Properties:
InstanceType: t2.micro
KeyName: !Ref KeyName
ImageId: ami-0c101f26f147fa7fd
SubnetId: !Ref PublicSubnet
SecurityGroupIds:
- !Ref WebSecurityGroup

AppServer:
Type: AWS::EC2::Instance
Properties:
InstanceType: t2.micro
KeyName: !Ref KeyName
ImageId: ami-0c101f26f147fa7fd
SubnetId: !Ref PrivateSubnet
SecurityGroupIds:
- !Ref AppSecurityGroup
```

------

## 💬 问题(模拟题,满分 15 分)

------

### **1. [2 分]**

模板中创建了几台 EC2 实例?它们是否可以访问互联网?请分别说明理由。

两个,分别是WebServer和AppServer

WebServer:可以,因为它的subnet是PublicSubnet,这个子网设置了MapPublicIpOnLaunch: true,因此有ip地址,并且其安全组WebSecurityGroup设置了tcp80入站,因此可以互相访问互联网。

AppServer:不可以,因为它的subnet是PrivateSubnet,这个子网没有分配ip地址。

------

### **2. [3 分]**

请解释 NAT 网关的作用,以及为什么它必须位于 PublicSubnet 中。

NAT网关是将内部资源序列化分配ip地址以便将其连接至互联网的网关。

必须位于 PublicSubnet 中是因为PublicSubnet是设计连接外部网络的子网,并且分配了ip地址。如果它在PrivateSubnet中,那么它就会因为没有公共ip地址导致无法连接外部网络

------

### **3. [2 分]**

AppServer 能否访问外网(例如下载 apt 包)?为什么?如果不能,该如何修改?

不能,因为它的subnet是PrivateSubnet,这个子网没有分配ip地址。修改办法只需要将AppServer添加额外绑定PublicSubnet子网,使其同时绑定PublicSubnet和PrivateSubnet就可以了

------

### **4. [2 分]**

假设 WebServer 的作用是接收用户发起的 HTTP 请求并转发到 AppServer 的 8080 端口,请说明是否能实现?为什么?

不可以实现,因为目前它们都不在一个子网下。

------

### **5. [3 分]**

WebServer 和 AppServer 分别部署在不同子网中,请说明它们之间是否能通过私网通信?为什么?

不可以直接通信,因为子网之间的隔离是保护网络之间的安全问题而必须的。

------

### **6. [3 分]**

请指出该模板中是否存在安全风险?如果有,请列出一项并说明如何改进。

有风险,因为 WebSecurityGroup的入站规则是0.0.0.0/0,允许所有流量入站,如果遭到黑客攻击,会产生大量消耗,因此有风险。

------

📝 请尝试独立完成上述问题。如需批改,请回复“请帮我批改 CloudFormation 设计题”。
如需查看参考答案,请回复“请给出参考答案”。加油!💪

~  ~  The   End  ~  ~


 赏 
感谢您的支持,我会继续努力哒!
支付宝收款码
tips
文章二维码 分类标签:归档TypechoAutoUpload
文章标题:25-6-19-云计算复习12
文章链接:https://www.fangshaonian.cn/archives/100/
最后编辑:2025 年 11 月 10 日 18:31 By 方少年
许可协议: 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
(*) 3 + 5 =
快来做第一个评论的人吧~