AWS CloudFormation: how do I refer to the default/main route table (that is created when a VPC is created) in...












1















I have a CloudFormation template that creates a custom VPC.
The template creates the following resources - a VPC, an Internet Gateway, attaches the IGW to the VPC, and creates a Public Subnet.
I want to add a route (destination 0.0.0.0/0, target IGW) to the Route Table that gets created as part of the VPC.



I have read through the cloudformation documentation for routes, route tables to figure out how to do this, but to no avail.



I can use the Fn::Ref function to refer to resources or parameters that are explicitly created as part of the template, but how do I refer to resources that get created inherently with the VPC?



Any insights on how to re-use the existing route table, NACL and Security Group are much appreciated.



Thanks,










share|improve this question



























    1















    I have a CloudFormation template that creates a custom VPC.
    The template creates the following resources - a VPC, an Internet Gateway, attaches the IGW to the VPC, and creates a Public Subnet.
    I want to add a route (destination 0.0.0.0/0, target IGW) to the Route Table that gets created as part of the VPC.



    I have read through the cloudformation documentation for routes, route tables to figure out how to do this, but to no avail.



    I can use the Fn::Ref function to refer to resources or parameters that are explicitly created as part of the template, but how do I refer to resources that get created inherently with the VPC?



    Any insights on how to re-use the existing route table, NACL and Security Group are much appreciated.



    Thanks,










    share|improve this question

























      1












      1








      1








      I have a CloudFormation template that creates a custom VPC.
      The template creates the following resources - a VPC, an Internet Gateway, attaches the IGW to the VPC, and creates a Public Subnet.
      I want to add a route (destination 0.0.0.0/0, target IGW) to the Route Table that gets created as part of the VPC.



      I have read through the cloudformation documentation for routes, route tables to figure out how to do this, but to no avail.



      I can use the Fn::Ref function to refer to resources or parameters that are explicitly created as part of the template, but how do I refer to resources that get created inherently with the VPC?



      Any insights on how to re-use the existing route table, NACL and Security Group are much appreciated.



      Thanks,










      share|improve this question














      I have a CloudFormation template that creates a custom VPC.
      The template creates the following resources - a VPC, an Internet Gateway, attaches the IGW to the VPC, and creates a Public Subnet.
      I want to add a route (destination 0.0.0.0/0, target IGW) to the Route Table that gets created as part of the VPC.



      I have read through the cloudformation documentation for routes, route tables to figure out how to do this, but to no avail.



      I can use the Fn::Ref function to refer to resources or parameters that are explicitly created as part of the template, but how do I refer to resources that get created inherently with the VPC?



      Any insights on how to re-use the existing route table, NACL and Security Group are much appreciated.



      Thanks,







      amazon-web-services amazon-cloudformation






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 26 '18 at 2:30









      N.ChetN.Chet

      62




      62
























          2 Answers
          2






          active

          oldest

          votes


















          1















          1. Don't use the default route table (see https://serverfault.com/questions/588904/aws-vpc-default-route-table-in-cloudformation)

          2. You can get default security group as per https://serverfault.com/questions/544439/aws-cloudformation-vpc-default-security-group

          3. And finally you can also get the DefaultNetworkAcl in the same as DefaultSecurityGroup above. See also https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpc.html)






          share|improve this answer































            0














            Good job so far - you have your internet gateway, route table, and a public subnet. Now you need to create the route and attach the route table to the subnet if you haven't already done so. If you're using YAML it might look something like this:



             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





            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53474044%2faws-cloudformation-how-do-i-refer-to-the-default-main-route-table-that-is-crea%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1















              1. Don't use the default route table (see https://serverfault.com/questions/588904/aws-vpc-default-route-table-in-cloudformation)

              2. You can get default security group as per https://serverfault.com/questions/544439/aws-cloudformation-vpc-default-security-group

              3. And finally you can also get the DefaultNetworkAcl in the same as DefaultSecurityGroup above. See also https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpc.html)






              share|improve this answer




























                1















                1. Don't use the default route table (see https://serverfault.com/questions/588904/aws-vpc-default-route-table-in-cloudformation)

                2. You can get default security group as per https://serverfault.com/questions/544439/aws-cloudformation-vpc-default-security-group

                3. And finally you can also get the DefaultNetworkAcl in the same as DefaultSecurityGroup above. See also https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpc.html)






                share|improve this answer


























                  1












                  1








                  1








                  1. Don't use the default route table (see https://serverfault.com/questions/588904/aws-vpc-default-route-table-in-cloudformation)

                  2. You can get default security group as per https://serverfault.com/questions/544439/aws-cloudformation-vpc-default-security-group

                  3. And finally you can also get the DefaultNetworkAcl in the same as DefaultSecurityGroup above. See also https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpc.html)






                  share|improve this answer














                  1. Don't use the default route table (see https://serverfault.com/questions/588904/aws-vpc-default-route-table-in-cloudformation)

                  2. You can get default security group as per https://serverfault.com/questions/544439/aws-cloudformation-vpc-default-security-group

                  3. And finally you can also get the DefaultNetworkAcl in the same as DefaultSecurityGroup above. See also https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-vpc.html)







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 28 at 23:21









                  chimpskichimpski

                  113




                  113

























                      0














                      Good job so far - you have your internet gateway, route table, and a public subnet. Now you need to create the route and attach the route table to the subnet if you haven't already done so. If you're using YAML it might look something like this:



                       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





                      share|improve this answer




























                        0














                        Good job so far - you have your internet gateway, route table, and a public subnet. Now you need to create the route and attach the route table to the subnet if you haven't already done so. If you're using YAML it might look something like this:



                         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





                        share|improve this answer


























                          0












                          0








                          0







                          Good job so far - you have your internet gateway, route table, and a public subnet. Now you need to create the route and attach the route table to the subnet if you haven't already done so. If you're using YAML it might look something like this:



                           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





                          share|improve this answer













                          Good job so far - you have your internet gateway, route table, and a public subnet. Now you need to create the route and attach the route table to the subnet if you haven't already done so. If you're using YAML it might look something like this:



                           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






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 26 '18 at 2:49









                          Ben WhaleyBen Whaley

                          19k25366




                          19k25366






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53474044%2faws-cloudformation-how-do-i-refer-to-the-default-main-route-table-that-is-crea%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              404 Error Contact Form 7 ajax form submitting

                              How to know if a Active Directory user can login interactively

                              TypeError: fit_transform() missing 1 required positional argument: 'X'