In CloudFormation, I'm creating a VPC, two EC2 instances, and an Elasticache in front of them. In the template, I'm trying to add the elasticache to the vpc. The problem's happening in creating the 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 input the subnet list as suggested here because I'm assuming the user doesn't know what a subnet is. Is there any function similar to { "Fn::GetAtt" : ["myVpc", "SubnetList"] }?
edit After jarmod's response, I'm creating the subnets, vpc, and everything else. But one problem still remains. I can launch the EC2's in the created VPC, but the instances get created and in the middle on initializing the instance shuts down and new instances are spun up. This cycle goes on until I delete the cf stack. Here's the part where I think the problem is originating:
"WebServerGroup" : {
"Type" : "AWS::AutoScaling::AutoScalingGroup",
"Properties" : {
"VPCZoneIdentifier" : [{ "Ref" : "InstanceSubnet1" }, { "Ref" : "InstanceSubnet2" }, { "Ref" : "InstanceSubnet3" }, { "Ref" : "InstanceSubnet4" }],
"LaunchConfigurationName" : { "Ref" : "LaunchConfig" },
"MinSize" : "1",
"MaxSize" : "4",
...
}
}
To find the subnets for your VPC, you can search with the list-subnet-summaries command as shown. For information about using CLI queries, see How to Filter the Output with the --query Option and the query language reference, JMESPath Specification . In AWS, use describe-subnets.
View your default VPC and default subnets You can view your default VPC and subnets using the Amazon VPC console or the command line. Open the Amazon VPC console at https://console.aws.amazon.com/vpc/ . In the navigation pane, choose Your VPCs. In the Default VPC column, look for a value of Yes.
Currently you can create 200 subnets per VPC. If you would like to create more, please submit a case at the support center.
Each VPC network consists of one or more IP address range called subnets. Subnets are regional resources, and have IP address ranges associated with them. In Google Cloud, the terms subnet and subnetwork are synonymous.
There are three typical ways of handling this situation (in my preferred order):
If the subnets will only be used by this stack, create them as part of the stack and use ref.
If the subnets will be used by several stacks, create them in a separate stack, define them as outputs, do a describe-stack on the defining stack to get the values, and then pass them on to this stack as parameters.
If the subnets are created elsewhere (outside of CloudFormation), just pass them in as parameters.
If you really want to use all subnets from a VPC, which I wouldn't recommend in case new ones are created in the future for other purposes, then you can always do describe-subnets and filter on VpcId do get your list.
If your template created the VPC then presumably your template also created the subnets for that VPC. Can't you just populate SubnetIds from the individual subnet IDs for each subnet you created?
Something like this:
"SubnetIds" : [ {"Ref":"mysubnet1"}, {"Ref":"mysubnet2"} ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With