gpt4 book ai didi

amazon-web-services - RouteTable 使用 cloudformation 创建两次 - ECS

转载 作者:行者123 更新时间:2023-12-03 07:30:03 26 4
gpt4 key购买 nike

我正在尝试使用cloudformation创建vpc,并使用单个公共(public)子网、路由表和互联网网关。问题是即使我只包含 1 个路由表,也会创建与 vpc 关联的两个路由表。

enter image description here

下面是我的代码

Description: "Create a VPC with a public subnet, Internet Gateway, and a public route table"

Parameters:
VpcCIDR:
Type: String
Description: "CIDR block for the VPC (e.g., 10.0.0.0/16)"

PublicSubnetCIDR:
Type: String
Description: "CIDR block for the public subnet (e.g., 10.0.1.0/24)"

Resources:
MyVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref VpcCIDR
Tags:
- Key: Name
Value: MyVPC

MyInternetGateway:
Type: AWS::EC2::InternetGateway

MyVPCGatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
VpcId: !Ref MyVPC
InternetGatewayId: !Ref MyInternetGateway

PublicRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref MyVPC
Tags:
- Key: Name
Value: PublicRouteTable

PublicRoute:
Type: AWS::EC2::Route
DependsOn: MyVPCGatewayAttachment
Properties:
RouteTableId: !Ref PublicRouteTable
DestinationCidrBlock: "0.0.0.0/0"
GatewayId: !Ref MyInternetGateway

PublicSubnet:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref MyVPC
CidrBlock: !Ref PublicSubnetCIDR
AvailabilityZone:
Fn::Select:
- 0
- Fn::GetAZs: {Ref: 'AWS::Region'}
Tags:
- Key: Name
Value: PublicSubnet

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

Outputs:
VpcId:
Value: !Ref MyVPC
Description: "VPC ID"
PublicRouteTableId:
Value: !Ref PublicRouteTable
Description: "Public Route Table ID"
PublicSubnetId:
Value: !Ref PublicSubnet
Description: "Public Subnet ID"

最佳答案

VPC 将始终有 default route table :

When you create a VPC, it automatically has a main route table. When a subnet does not have an explicit routing table associated with it, the main routing table is used by default.

关于amazon-web-services - RouteTable 使用 cloudformation 创建两次 - ECS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76754406/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com