gpt4 book ai didi

amazon-web-services - AWS 云形成 : how do I refer to the default/main route table (that is created when a VPC is created) in a cloudformation template?

转载 作者:行者123 更新时间:2023-12-04 23:12:37 25 4
gpt4 key购买 nike

我有一个用于创建自定义 VPC 的 CloudFormation 模板。该模板创建以下资源 - VPC、Internet 网关、将 IGW 连接到 VPC,并创建公共(public)子网。我想将路由(目标 0.0.0.0/0、目标 IGW)添加到作为 VPC 一部分创建的路由表。

我已经阅读了cloudformation文档中的路由、路由表来弄清楚如何做到这一点,但无济于事。

我可以使用 Fn::Ref 函数来引用作为模板的一部分显式创建的资源或参数,但如何引用使用 VPC 固有创建的资源?

非常感谢有关如何重用现有路由表、NACL 和安全组的任何见解。

谢谢

最佳答案

到目前为止,干得不错 - 您拥有互联网网关、路由表和公共(public)子网。现在,您需要创建路由并将路由表附加到子网(如果您尚未这样做)。如果您使用 YAML,它可能看起来像这样:

 InternetGateway:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: !Ref EnvironmentName

InternetGatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
InternetGatewayId: !Ref InternetGateway
VpcId: !Ref VPC

PublicSubnet1:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select [ 0, !GetAZs '' ]
CidrBlock: !Ref PublicSubnet1CIDR
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: !Sub ${EnvironmentName} Public Subnet (AZ1)

PublicRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Sub ${EnvironmentName} Public Routes

DefaultPublicRoute:
Type: AWS::EC2::Route
DependsOn: InternetGatewayAttachment
Properties:
RouteTableId: !Ref PublicRouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway

PublicSubnet1RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PublicRouteTable
SubnetId: !Ref PublicSubnet1

关于amazon-web-services - AWS 云形成 : how do I refer to the default/main route table (that is created when a VPC is created) in a cloudformation template?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53474044/

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