AWS CloudFormation: How to get a subnet list from VPC?

In CloudFormation, I create a VPC, two instances of EC2 and Elasticache in front of them. In the template, I am trying to add elasticity to vpc. Problem encountered while creating AWS :: Elasticache :: SubnetGroup

    "CacheSubnetGroup" : {
      "Type" : "AWS::ElastiCache::SubnetGroup",
      "Properties" : {
        "Description" : "Subnets available for the ElastiCache Cluster",
        "SubnetIds" : [ ... ]
      }
    },

I do not want to ask the user to enter a list of subnets, as suggested here , because I assume the user does not know what a subnet is. Is there any function similar to {"Fn :: GetAtt": ["myVpc", "SubnetList"]}?

edit After jarmod answers, I create subnets, vpc and everything else. But one problem remains. I can run EC2 in the created VPC, but the instances are created and in the middle when the instance is initialized, they are completed and the new instances are deployed. This loop continues until I remove the cf stack. Here is the part where I think the problem arises:

"WebServerGroup" : {
  "Type" : "AWS::AutoScaling::AutoScalingGroup",
  "Properties" : {
    "VPCZoneIdentifier" : [{ "Ref" : "InstanceSubnet1" }, { "Ref" : "InstanceSubnet2" }, { "Ref" : "InstanceSubnet3" }, { "Ref" : "InstanceSubnet4" }],
    "LaunchConfigurationName" : { "Ref" : "LaunchConfig" },
    "MinSize" : "1",
    "MaxSize" : "4",
    ...
  }
}
+4
source share
2 answers

If your template created VPCs, it is assumed that your template also created subnets for this VPC. Can't you just populate SubnetIds from separate subnet identifiers for each subnet you create?

Something like that:

"SubnetIds" : [ {"Ref":"mysubnet1"}, {"Ref":"mysubnet2"} ]
+2
source

( ):

  • , ref.

  • , , , , , .

  • ( CloudFormation), .

VPC, , - VpcId, .

+3

All Articles