Class | AWS::EC2::SubnetCollection |
In: |
lib/aws/ec2/subnet_collection.rb
|
Parent: | Collection |
Represents a collection of VPC subnets. You can get a subnet collection two ways. You can get a collection that represents ALL subnets (across all your VPCs). You can also get a subnet collection that represents subnets within a single vpc.
# represents all subnets subnets = ec2.subnets # represents subnets within the named vpc subnets = ec2.vpcs['vpc-12345'].subnets
## Creating a Subnet
To create a subnet, call {create} on a subnet collection, passing in a suitable CIDR block.
subnet = subnets.create('10.0.0.0/20')
You can optionally pass the availability zone you want the subnet created in.
## Getting a Subnet
If you know the subnet id, you can get a subnet using {#[]}.
subnet = subnets['subnet-id-here']
You can filter subnets as well. See the EC2 API documentation (docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeSubnets.html) for a complete list of accepted filters.
subnet = subnets.filter('state', 'available').first
Creates a Subnet. Subnets require a valid CIDR block and are created inside an existing VPC. If you do not set an AvailabilityZone, then Amazon EC2 will select one for you (this is recommended).
For complete information about creating subnets, see {docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-CreateSubnet.html CreateSubnet} in the Amazon EC2 API Reference.
@param [String] cidr_block The CIDR block you want the subnet to
cover (e.g., 10.0.0.0/24).
@param [Hash] options
@option options [VPC,String] :vpc The VPC (or VPC id string) to
create the subnet in.
@option options [String,AvailabilityZone] :availability_zone
The Availability Zone you want the subnet in. AWS selects a default zone for you (recommended).
@return [Subnet]