Class: Aws::EC2::Subnet

Inherits:
Object
  • Object
show all
Extended by:
Deprecations
Defined in:
lib/aws-sdk-ec2/subnet.rb

Defined Under Namespace

Classes: Collection

Read-Only Attributes collapse

Actions collapse

Associations collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, options = {}) ⇒ Subnet #initialize(options = {}) ⇒ Subnet

Returns a new instance of Subnet.

Overloads:

  • #initialize(id, options = {}) ⇒ Subnet

    Parameters:

    • id (String)

    Options Hash (options):

  • #initialize(options = {}) ⇒ Subnet

    Options Hash (options):

    • :id (required, String)
    • :client (Client)


19
20
21
22
23
24
# File 'lib/aws-sdk-ec2/subnet.rb', line 19

def initialize(*args)
  options = Hash === args.last ? args.pop.dup : {}
  @id = extract_id(args, options)
  @data = options.delete(:data)
  @client = options.delete(:client) || Client.new(options)
end

Instance Method Details

#assign_ipv_6_address_on_creationBoolean

Indicates whether a network interface created in this subnet (including a network interface created by RunInstances) receives an IPv6 address.

Returns:

  • (Boolean)


95
96
97
# File 'lib/aws-sdk-ec2/subnet.rb', line 95

def assign_ipv_6_address_on_creation
  data[:assign_ipv_6_address_on_creation]
end

#availability_zoneString

The Availability Zone of the subnet.

Returns:

  • (String)


36
37
38
# File 'lib/aws-sdk-ec2/subnet.rb', line 36

def availability_zone
  data[:availability_zone]
end

#availability_zone_idString

The AZ ID of the subnet.

Returns:

  • (String)


42
43
44
# File 'lib/aws-sdk-ec2/subnet.rb', line 42

def availability_zone_id
  data[:availability_zone_id]
end

#available_ip_address_countInteger

The number of unused private IPv4 addresses in the subnet. The IPv4 addresses for any stopped instances are considered unavailable.

Returns:

  • (Integer)


49
50
51
# File 'lib/aws-sdk-ec2/subnet.rb', line 49

def available_ip_address_count
  data[:available_ip_address_count]
end

#cidr_blockString

The IPv4 CIDR block assigned to the subnet.

Returns:

  • (String)


55
56
57
# File 'lib/aws-sdk-ec2/subnet.rb', line 55

def cidr_block
  data[:cidr_block]
end

#clientClient

Returns:



120
121
122
# File 'lib/aws-sdk-ec2/subnet.rb', line 120

def client
  @client
end

#create_instances(options = {}) ⇒ Instance::Collection

Examples:

Request syntax with placeholder values


instance = subnet.create_instances({
  block_device_mappings: [
    {
      device_name: "String",
      virtual_name: "String",
      ebs: {
        delete_on_termination: false,
        iops: 1,
        snapshot_id: "String",
        volume_size: 1,
        volume_type: "standard", # accepts standard, io1, gp2, sc1, st1
        encrypted: false,
        kms_key_id: "String",
      },
      no_device: "String",
    },
  ],
  image_id: "String",
  instance_type: "t1.micro", # accepts t1.micro, t2.nano, t2.micro, t2.small, t2.medium, t2.large, t2.xlarge, t2.2xlarge, t3.nano, t3.micro, t3.small, t3.medium, t3.large, t3.xlarge, t3.2xlarge, m1.small, m1.medium, m1.large, m1.xlarge, m3.medium, m3.large, m3.xlarge, m3.2xlarge, m4.large, m4.xlarge, m4.2xlarge, m4.4xlarge, m4.10xlarge, m4.16xlarge, m2.xlarge, m2.2xlarge, m2.4xlarge, cr1.8xlarge, r3.large, r3.xlarge, r3.2xlarge, r3.4xlarge, r3.8xlarge, r4.large, r4.xlarge, r4.2xlarge, r4.4xlarge, r4.8xlarge, r4.16xlarge, r5.large, r5.xlarge, r5.2xlarge, r5.4xlarge, r5.8xlarge, r5.12xlarge, r5.16xlarge, r5.24xlarge, r5.metal, r5a.large, r5a.xlarge, r5a.2xlarge, r5a.4xlarge, r5a.12xlarge, r5a.24xlarge, r5d.large, r5d.xlarge, r5d.2xlarge, r5d.4xlarge, r5d.8xlarge, r5d.12xlarge, r5d.16xlarge, r5d.24xlarge, r5d.metal, x1.16xlarge, x1.32xlarge, x1e.xlarge, x1e.2xlarge, x1e.4xlarge, x1e.8xlarge, x1e.16xlarge, x1e.32xlarge, i2.xlarge, i2.2xlarge, i2.4xlarge, i2.8xlarge, i3.large, i3.xlarge, i3.2xlarge, i3.4xlarge, i3.8xlarge, i3.16xlarge, i3.metal, hi1.4xlarge, hs1.8xlarge, c1.medium, c1.xlarge, c3.large, c3.xlarge, c3.2xlarge, c3.4xlarge, c3.8xlarge, c4.large, c4.xlarge, c4.2xlarge, c4.4xlarge, c4.8xlarge, c5.large, c5.xlarge, c5.2xlarge, c5.4xlarge, c5.9xlarge, c5.18xlarge, c5d.large, c5d.xlarge, c5d.2xlarge, c5d.4xlarge, c5d.9xlarge, c5d.18xlarge, c5n.large, c5n.xlarge, c5n.2xlarge, c5n.4xlarge, c5n.9xlarge, c5n.18xlarge, cc1.4xlarge, cc2.8xlarge, g2.2xlarge, g2.8xlarge, g3.4xlarge, g3.8xlarge, g3.16xlarge, g3s.xlarge, cg1.4xlarge, p2.xlarge, p2.8xlarge, p2.16xlarge, p3.2xlarge, p3.8xlarge, p3.16xlarge, p3dn.24xlarge, d2.xlarge, d2.2xlarge, d2.4xlarge, d2.8xlarge, f1.2xlarge, f1.4xlarge, f1.16xlarge, m5.large, m5.xlarge, m5.2xlarge, m5.4xlarge, m5.12xlarge, m5.24xlarge, m5a.large, m5a.xlarge, m5a.2xlarge, m5a.4xlarge, m5a.12xlarge, m5a.24xlarge, m5d.large, m5d.xlarge, m5d.2xlarge, m5d.4xlarge, m5d.12xlarge, m5d.24xlarge, h1.2xlarge, h1.4xlarge, h1.8xlarge, h1.16xlarge, z1d.large, z1d.xlarge, z1d.2xlarge, z1d.3xlarge, z1d.6xlarge, z1d.12xlarge, u-6tb1.metal, u-9tb1.metal, u-12tb1.metal, a1.medium, a1.large, a1.xlarge, a1.2xlarge, a1.4xlarge
  ipv_6_address_count: 1,
  ipv_6_addresses: [
    {
      ipv_6_address: "String",
    },
  ],
  kernel_id: "String",
  key_name: "String",
  max_count: 1, # required
  min_count: 1, # required
  monitoring: {
    enabled: false, # required
  },
  placement: {
    availability_zone: "String",
    affinity: "String",
    group_name: "String",
    partition_number: 1,
    host_id: "String",
    tenancy: "default", # accepts default, dedicated, host
    spread_domain: "String",
  },
  ramdisk_id: "String",
  security_group_ids: ["String"],
  security_groups: ["String"],
  user_data: "String",
  additional_info: "String",
  client_token: "String",
  disable_api_termination: false,
  dry_run: false,
  ebs_optimized: false,
  iam_instance_profile: {
    arn: "String",
    name: "String",
  },
  instance_initiated_shutdown_behavior: "stop", # accepts stop, terminate
  network_interfaces: [
    {
      associate_public_ip_address: false,
      delete_on_termination: false,
      description: "String",
      device_index: 1,
      groups: ["String"],
      ipv_6_address_count: 1,
      ipv_6_addresses: [
        {
          ipv_6_address: "String",
        },
      ],
      network_interface_id: "String",
      private_ip_address: "String",
      private_ip_addresses: [
        {
          primary: false,
          private_ip_address: "String",
        },
      ],
      secondary_private_ip_address_count: 1,
      subnet_id: "String",
    },
  ],
  private_ip_address: "String",
  elastic_gpu_specification: [
    {
      type: "String", # required
    },
  ],
  elastic_inference_accelerators: [
    {
      type: "String", # required
    },
  ],
  tag_specifications: [
    {
      resource_type: "customer-gateway", # accepts customer-gateway, dedicated-host, dhcp-options, elastic-ip, fleet, fpga-image, image, instance, internet-gateway, launch-template, natgateway, network-acl, network-interface, reserved-instances, route-table, security-group, snapshot, spot-instances-request, subnet, transit-gateway, transit-gateway-attachment, transit-gateway-route-table, volume, vpc, vpc-peering-connection, vpn-connection, vpn-gateway
      tags: [
        {
          key: "String",
          value: "String",
        },
      ],
    },
  ],
  launch_template: {
    launch_template_id: "String",
    launch_template_name: "String",
    version: "String",
  },
  instance_market_options: {
    market_type: "spot", # accepts spot
    spot_options: {
      max_price: "String",
      spot_instance_type: "one-time", # accepts one-time, persistent
      block_duration_minutes: 1,
      valid_until: Time.now,
      instance_interruption_behavior: "hibernate", # accepts hibernate, stop, terminate
    },
  },
  credit_specification: {
    cpu_credits: "String", # required
  },
  cpu_options: {
    core_count: 1,
    threads_per_core: 1,
  },
  capacity_reservation_specification: {
    capacity_reservation_preference: "open", # accepts open, none
    capacity_reservation_target: {
      capacity_reservation_id: "String",
    },
  },
  hibernation_options: {
    configured: false,
  },
  license_specifications: [
    {
      license_configuration_arn: "String",
    },
  ],
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :block_device_mappings (Array<Types::BlockDeviceMapping>)

    One or more block device mapping entries. You can’t specify both a snapshot ID and an encryption value. This is because only blank volumes can be encrypted on creation. If a snapshot is the basis for a volume, it is not blank and its encryption status is used for the volume encryption status.

  • :image_id (String)

    The ID of the AMI, which you can get by calling DescribeImages. An AMI is required to launch an instance and must be specified here or in a launch template.

  • :instance_type (String)

    The instance type. For more information, see [Instance Types] in the *Amazon Elastic Compute Cloud User Guide*.

    Default: ‘m1.small`

    [1]: docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html

  • :ipv_6_address_count (Integer)

    [EC2-VPC] A number of IPv6 addresses to associate with the primary network interface. Amazon EC2 chooses the IPv6 addresses from the range of your subnet. You cannot specify this option and the option to assign specific IPv6 addresses in the same request. You can specify this option if you’ve specified a minimum number of instances to launch.

  • :ipv_6_addresses (Array<Types::InstanceIpv6Address>)

    [EC2-VPC] Specify one or more IPv6 addresses from the range of the subnet to associate with the primary network interface. You cannot specify this option and the option to assign a number of IPv6 addresses in the same request. You cannot specify this option if you’ve specified a minimum number of instances to launch.

  • :kernel_id (String)

    The ID of the kernel.

    We recommend that you use PV-GRUB instead of kernels and RAM disks. For more information, see [ PV-GRUB] in the *Amazon Elastic Compute Cloud User Guide*.

    [1]: docs.aws.amazon.com/AWSEC2/latest/UserGuide/UserProvidedkernels.html

  • :key_name (String)

    The name of the key pair. You can create a key pair using CreateKeyPair or ImportKeyPair.

    If you do not specify a key pair, you can’t connect to the instance unless you choose an AMI that is configured to allow users another way to log in.

  • :max_count (required, Integer)

    The maximum number of instances to launch. If you specify more instances than Amazon EC2 can launch in the target Availability Zone, Amazon EC2 launches the largest possible number of instances above ‘MinCount`.

    Constraints: Between 1 and the maximum number you’re allowed for the specified instance type. For more information about the default limits, and how to request an increase, see [How many instances can I run in Amazon EC2] in the Amazon EC2 FAQ.

    [1]: aws.amazon.com/ec2/faqs/#How_many_instances_can_I_run_in_Amazon_EC2

  • :min_count (required, Integer)

    The minimum number of instances to launch. If you specify a minimum that is more instances than Amazon EC2 can launch in the target Availability Zone, Amazon EC2 launches no instances.

    Constraints: Between 1 and the maximum number you’re allowed for the specified instance type. For more information about the default limits, and how to request an increase, see [How many instances can I run in Amazon EC2] in the Amazon EC2 General FAQ.

    [1]: aws.amazon.com/ec2/faqs/#How_many_instances_can_I_run_in_Amazon_EC2

  • :monitoring (Types::RunInstancesMonitoringEnabled)

    The monitoring for the instance.

  • :placement (Types::Placement)

    The placement for the instance.

  • :ramdisk_id (String)

    The ID of the RAM disk.

    We recommend that you use PV-GRUB instead of kernels and RAM disks. For more information, see [ PV-GRUB] in the *Amazon Elastic Compute Cloud User Guide*.

    [1]: docs.aws.amazon.com/AWSEC2/latest/UserGuide/UserProvidedkernels.html

  • :security_group_ids (Array<String>)

    One or more security group IDs. You can create a security group using CreateSecurityGroup.

    Default: Amazon EC2 uses the default security group.

  • :security_groups (Array<String>)

    [EC2-Classic, default VPC] One or more security group names. For a nondefault VPC, you must use security group IDs instead.

    Default: Amazon EC2 uses the default security group.

  • :user_data (String)

    The user data to make available to the instance. For more information, see [Running Commands on Your Linux Instance at Launch] (Linux) and

    Adding User Data][2

    (Windows). If you are using a command line tool,

    base64-encoding is performed for you, and you can load the text from a file. Otherwise, you must provide base64-encoded text.

    [1]: docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html [2]: docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ec2-instance-metadata.html#instancedata-add-user-data

  • :additional_info (String)

    Reserved.

  • :client_token (String)

    Unique, case-sensitive identifier you provide to ensure the idempotency of the request. For more information, see [Ensuring Idempotency].

    Constraints: Maximum 64 ASCII characters

    [1]: docs.aws.amazon.com/AWSEC2/latest/APIReference/Run_Instance_Idempotency.html

  • :disable_api_termination (Boolean)

    If you set this parameter to ‘true`, you can’t terminate the instance using the Amazon EC2 console, CLI, or API; otherwise, you can. To change this attribute to ‘false` after launch, use ModifyInstanceAttribute. Alternatively, if you set `InstanceInitiatedShutdownBehavior` to `terminate`, you can terminate the instance by running the shutdown command from the instance.

    Default: ‘false`

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is ‘DryRunOperation`. Otherwise, it is `UnauthorizedOperation`.

  • :ebs_optimized (Boolean)

    Indicates whether the instance is optimized for Amazon EBS I/O. This optimization provides dedicated throughput to Amazon EBS and an optimized configuration stack to provide optimal Amazon EBS I/O performance. This optimization isn’t available with all instance types. Additional usage charges apply when using an EBS-optimized instance.

    Default: ‘false`

  • :iam_instance_profile (Types::IamInstanceProfileSpecification)

    The IAM instance profile.

  • :instance_initiated_shutdown_behavior (String)

    Indicates whether an instance stops or terminates when you initiate shutdown from the instance (using the operating system command for system shutdown).

    Default: ‘stop`

  • :network_interfaces (Array<Types::InstanceNetworkInterfaceSpecification>)

    One or more network interfaces.

  • :private_ip_address (String)

    [EC2-VPC] The primary IPv4 address. You must specify a value from the IPv4 address range of the subnet.

    Only one private IP address can be designated as primary. You can’t specify this option if you’ve specified the option to designate a private IP address as the primary IP address in a network interface specification. You cannot specify this option if you’re launching more than one instance in the request.

  • :elastic_gpu_specification (Array<Types::ElasticGpuSpecification>)

    An elastic GPU to associate with the instance.

  • :elastic_inference_accelerators (Array<Types::ElasticInferenceAccelerator>)

    An elastic inference accelerator.

  • :tag_specifications (Array<Types::TagSpecification>)

    The tags to apply to the resources during launch. You can only tag instances and volumes on launch. The specified tags are applied to all instances or volumes that are created during launch. To tag a resource after it has been created, see CreateTags.

  • :launch_template (Types::LaunchTemplateSpecification)

    The launch template to use to launch the instances. Any parameters that you specify in RunInstances override the same parameters in the launch template. You can specify either the name or ID of a launch template, but not both.

  • :instance_market_options (Types::InstanceMarketOptionsRequest)

    The market (purchasing) option for the instances.

    For RunInstances, persistent Spot Instance requests are only supported when InstanceInterruptionBehavior is set to either ‘hibernate` or `stop`.

  • :credit_specification (Types::CreditSpecificationRequest)

    The credit option for CPU usage of the instance. Valid values are ‘standard` and `unlimited`. To change this attribute after launch, use ModifyInstanceCreditSpecification. For more information, see

    Burstable Performance Instances][1

    in the *Amazon Elastic Compute

    Cloud User Guide*.

    Default: ‘standard` (T2 instances) or `unlimited` (T3 instances)

    [1]: docs.aws.amazon.com/AWSEC2/latest/UserGuide/burstable-performance-instances.html

  • :cpu_options (Types::CpuOptionsRequest)

    The CPU options for the instance. For more information, see

    Optimizing CPU Options][1

    in the *Amazon Elastic Compute Cloud User

    Guide*.

    [1]: docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-optimize-cpu.html

  • :capacity_reservation_specification (Types::CapacityReservationSpecification)

    Information about the Capacity Reservation targeting option.

  • :hibernation_options (Types::HibernationOptionsRequest)

    Indicates whether an instance is enabled for hibernation. For more information, see [Hibernate Your Instance] in the *Amazon Elastic Compute Cloud User Guide*.

    [1]: docs.aws.amazon.com/AWSEC2/latest/UserGuide/Hibernate.html

  • :license_specifications (Array<Types::LicenseConfigurationRequest>)

    The license configurations.

Returns:



609
610
611
612
613
614
615
616
617
618
619
620
621
# File 'lib/aws-sdk-ec2/subnet.rb', line 609

def create_instances(options = {})
  batch = []
  options = options.merge(subnet_id: @id)
  resp = @client.run_instances(options)
  resp.data.instances.each do |i|
    batch << Instance.new(
      id: i.instance_id,
      data: i,
      client: @client
    )
  end
  Instance::Collection.new([batch], size: batch.size)
end

#create_network_interface(options = {}) ⇒ NetworkInterface

Examples:

Request syntax with placeholder values


networkinterface = subnet.create_network_interface({
  description: "String",
  dry_run: false,
  groups: ["String"],
  ipv_6_address_count: 1,
  ipv_6_addresses: [
    {
      ipv_6_address: "String",
    },
  ],
  private_ip_address: "String",
  private_ip_addresses: [
    {
      primary: false,
      private_ip_address: "String",
    },
  ],
  secondary_private_ip_address_count: 1,
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :description (String)

    A description for the network interface.

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is ‘DryRunOperation`. Otherwise, it is `UnauthorizedOperation`.

  • :groups (Array<String>)

    The IDs of one or more security groups.

  • :ipv_6_address_count (Integer)

    The number of IPv6 addresses to assign to a network interface. Amazon EC2 automatically selects the IPv6 addresses from the subnet range. You can’t use this option if specifying specific IPv6 addresses. If your subnet has the ‘AssignIpv6AddressOnCreation` attribute set to `true`, you can specify `0` to override this setting.

  • :ipv_6_addresses (Array<Types::InstanceIpv6Address>)

    One or more specific IPv6 addresses from the IPv6 CIDR block range of your subnet. You can’t use this option if you’re specifying a number of IPv6 addresses.

  • :private_ip_address (String)

    The primary private IPv4 address of the network interface. If you don’t specify an IPv4 address, Amazon EC2 selects one for you from the subnet’s IPv4 CIDR range. If you specify an IP address, you cannot indicate any IP addresses specified in ‘privateIpAddresses` as primary (only one IP address can be designated as primary).

  • :private_ip_addresses (Array<Types::PrivateIpAddressSpecification>)

    One or more private IPv4 addresses.

  • :secondary_private_ip_address_count (Integer)

    The number of secondary private IPv4 addresses to assign to a network interface. When you specify a number of secondary IPv4 addresses, Amazon EC2 selects these IP addresses within the subnet’s IPv4 CIDR range. You can’t specify this option and specify more than one private IP address using ‘privateIpAddresses`.

    The number of IP addresses you can assign to a network interface varies by instance type. For more information, see [IP Addresses Per ENI Per Instance Type] in the *Amazon Virtual Private Cloud User Guide*.

    [1]: docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html#AvailableIpPerENI

Returns:



688
689
690
691
692
693
694
695
696
# File 'lib/aws-sdk-ec2/subnet.rb', line 688

def create_network_interface(options = {})
  options = options.merge(subnet_id: @id)
  resp = @client.create_network_interface(options)
  NetworkInterface.new(
    id: resp.data.network_interface.network_interface_id,
    data: resp.data.network_interface,
    client: @client
  )
end

#create_tags(options = {}) ⇒ Tag::Collection

Examples:

Request syntax with placeholder values


tag = subnet.create_tags({
  dry_run: false,
  tags: [ # required
    {
      key: "String",
      value: "String",
    },
  ],
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is ‘DryRunOperation`. Otherwise, it is `UnauthorizedOperation`.

  • :tags (required, Array<Types::Tag>)

    One or more tags. The ‘value` parameter is required, but if you don’t want the tag to have a value, specify the parameter with no value, and we set the value to an empty string.

Returns:



720
721
722
723
724
725
726
727
728
729
730
731
732
733
# File 'lib/aws-sdk-ec2/subnet.rb', line 720

def create_tags(options = {})
  batch = []
  options = Aws::Util.deep_merge(options, resources: [@id])
  resp = @client.create_tags(options)
  options[:tags].each do |t|
    batch << Tag.new(
      resource_id: @id,
      key: t[:key],
      value: t[:value],
      client: @client
    )
  end
  Tag::Collection.new([batch], size: batch.size)
end

#dataTypes::Subnet

Returns the data for this Aws::EC2::Subnet. Calls Client#describe_subnets if #data_loaded? is ‘false`.

Returns:



140
141
142
143
# File 'lib/aws-sdk-ec2/subnet.rb', line 140

def data
  load unless @data
  @data
end

#data_loaded?Boolean

Returns ‘true` if this resource is loaded. Accessing attributes or #data on an unloaded resource will trigger a call to #load.

Returns:

  • (Boolean)

    Returns ‘true` if this resource is loaded. Accessing attributes or #data on an unloaded resource will trigger a call to #load.



148
149
150
# File 'lib/aws-sdk-ec2/subnet.rb', line 148

def data_loaded?
  !!@data
end

#default_for_azBoolean

Indicates whether this is the default subnet for the Availability Zone.

Returns:

  • (Boolean)


62
63
64
# File 'lib/aws-sdk-ec2/subnet.rb', line 62

def default_for_az
  data[:default_for_az]
end

#delete(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


subnet.delete({
  dry_run: false,
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is ‘DryRunOperation`. Otherwise, it is `UnauthorizedOperation`.

Returns:

  • (EmptyStructure)


747
748
749
750
751
# File 'lib/aws-sdk-ec2/subnet.rb', line 747

def delete(options = {})
  options = options.merge(subnet_id: @id)
  resp = @client.delete_subnet(options)
  resp.data
end

#idString Also known as: subnet_id

Returns:

  • (String)


29
30
31
# File 'lib/aws-sdk-ec2/subnet.rb', line 29

def id
  @id
end

#identifiersObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Deprecated.


1235
1236
1237
# File 'lib/aws-sdk-ec2/subnet.rb', line 1235

def identifiers
  { id: @id }
end

#instances(options = {}) ⇒ Instance::Collection

Examples:

Request syntax with placeholder values


instances = subnet.instances({
  filters: [
    {
      name: "String",
      values: ["String"],
    },
  ],
  instance_ids: ["String"],
  dry_run: false,
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :filters (Array<Types::Filter>)

    One or more filters.

    • ‘affinity` - The affinity setting for an instance running on a Dedicated Host (`default` | `host`).

    • ‘architecture` - The instance architecture (`i386` | `x86_64`).

    • ‘availability-zone` - The Availability Zone of the instance.

    • ‘block-device-mapping.attach-time` - The attach time for an EBS volume mapped to the instance, for example, `2010-09-15T17:15:20.000Z`.

    • ‘block-device-mapping.delete-on-termination` - A Boolean that indicates whether the EBS volume is deleted on instance termination.

    • ‘block-device-mapping.device-name` - The device name specified in the block device mapping (for example, `/dev/sdh` or `xvdh`).

    • ‘block-device-mapping.status` - The status for the EBS volume (`attaching` | `attached` | `detaching` | `detached`).

    • ‘block-device-mapping.volume-id` - The volume ID of the EBS volume.

    • ‘client-token` - The idempotency token you provided when you launched the instance.

    • ‘dns-name` - The public DNS name of the instance.

    • ‘group-id` - The ID of the security group for the instance. EC2-Classic only.

    • ‘group-name` - The name of the security group for the instance. EC2-Classic only.

    • ‘hibernation-options.configured` - A Boolean that indicates whether the instance is enabled for hibernation. A value of `true` means that the instance is enabled for hibernation.

    • ‘host-id` - The ID of the Dedicated Host on which the instance is running, if applicable.

    • ‘hypervisor` - The hypervisor type of the instance (`ovm` | `xen`).

    • ‘iam-instance-profile.arn` - The instance profile associated with the instance. Specified as an ARN.

    • ‘image-id` - The ID of the image used to launch the instance.

    • ‘instance-id` - The ID of the instance.

    • ‘instance-lifecycle` - Indicates whether this is a Spot Instance or a Scheduled Instance (`spot` | `scheduled`).

    • ‘instance-state-code` - The state of the instance, as a 16-bit unsigned integer. The high byte is used for internal purposes and should be ignored. The low byte is set based on the state represented. The valid values are: 0 (pending), 16 (running), 32 (shutting-down), 48 (terminated), 64 (stopping), and 80 (stopped).

    • ‘instance-state-name` - The state of the instance (`pending` | `running` | `shutting-down` | `terminated` | `stopping` | `stopped`).

    • ‘instance-type` - The type of instance (for example, `t2.micro`).

    • ‘instance.group-id` - The ID of the security group for the instance.

    • ‘instance.group-name` - The name of the security group for the instance.

    • ‘ip-address` - The public IPv4 address of the instance.

    • ‘kernel-id` - The kernel ID.

    • ‘key-name` - The name of the key pair used when the instance was launched.

    • ‘launch-index` - When launching multiple instances, this is the index for the instance in the launch group (for example, 0, 1, 2, and so on).

    • ‘launch-time` - The time when the instance was launched.

    • ‘monitoring-state` - Indicates whether detailed monitoring is enabled (`disabled` | `enabled`).

    • ‘network-interface.addresses.private-ip-address` - The private IPv4 address associated with the network interface.

    • ‘network-interface.addresses.primary` - Specifies whether the IPv4 address of the network interface is the primary private IPv4 address.

    • ‘network-interface.addresses.association.public-ip` - The ID of the association of an Elastic IP address (IPv4) with a network interface.

    • ‘network-interface.addresses.association.ip-owner-id` - The owner ID of the private IPv4 address associated with the network interface.

    • ‘network-interface.association.public-ip` - The address of the Elastic IP address (IPv4) bound to the network interface.

    • ‘network-interface.association.ip-owner-id` - The owner of the Elastic IP address (IPv4) associated with the network interface.

    • ‘network-interface.association.allocation-id` - The allocation ID returned when you allocated the Elastic IP address (IPv4) for your network interface.

    • ‘network-interface.association.association-id` - The association ID returned when the network interface was associated with an IPv4 address.

    • ‘network-interface.attachment.attachment-id` - The ID of the interface attachment.

    • ‘network-interface.attachment.instance-id` - The ID of the instance to which the network interface is attached.

    • ‘network-interface.attachment.instance-owner-id` - The owner ID of the instance to which the network interface is attached.

    • ‘network-interface.attachment.device-index` - The device index to which the network interface is attached.

    • ‘network-interface.attachment.status` - The status of the attachment (`attaching` | `attached` | `detaching` | `detached`).

    • ‘network-interface.attachment.attach-time` - The time that the network interface was attached to an instance.

    • ‘network-interface.attachment.delete-on-termination` - Specifies whether the attachment is deleted when an instance is terminated.

    • ‘network-interface.availability-zone` - The Availability Zone for the network interface.

    • ‘network-interface.description` - The description of the network interface.

    • ‘network-interface.group-id` - The ID of a security group associated with the network interface.

    • ‘network-interface.group-name` - The name of a security group associated with the network interface.

    • ‘network-interface.ipv6-addresses.ipv6-address` - The IPv6 address associated with the network interface.

    • ‘network-interface.mac-address` - The MAC address of the network interface.

    • ‘network-interface.network-interface-id` - The ID of the network interface.

    • ‘network-interface.owner-id` - The ID of the owner of the network interface.

    • ‘network-interface.private-dns-name` - The private DNS name of the network interface.

    • ‘network-interface.requester-id` - The requester ID for the network interface.

    • ‘network-interface.requester-managed` - Indicates whether the network interface is being managed by AWS.

    • ‘network-interface.status` - The status of the network interface (`available`) | `in-use`).

    • ‘network-interface.source-dest-check` - Whether the network interface performs source/destination checking. A value of `true` means that checking is enabled, and `false` means that checking is disabled. The value must be `false` for the network interface to perform network address translation (NAT) in your VPC.

    • ‘network-interface.subnet-id` - The ID of the subnet for the network interface.

    • ‘network-interface.vpc-id` - The ID of the VPC for the network interface.

    • ‘owner-id` - The AWS account ID of the instance owner.

    • ‘placement-group-name` - The name of the placement group for the instance.

    • ‘placement-partition-number` - The partition in which the instance is located.

    • ‘platform` - The platform. Use `windows` if you have Windows instances; otherwise, leave blank.

    • ‘private-dns-name` - The private IPv4 DNS name of the instance.

    • ‘private-ip-address` - The private IPv4 address of the instance.

    • ‘product-code` - The product code associated with the AMI used to launch the instance.

    • ‘product-code.type` - The type of product code (`devpay` | `marketplace`).

    • ‘ramdisk-id` - The RAM disk ID.

    • ‘reason` - The reason for the current state of the instance (for example, shows “User Initiated [date]” when you stop or terminate the instance). Similar to the state-reason-code filter.

    • ‘requester-id` - The ID of the entity that launched the instance on your behalf (for example, AWS Management Console, Auto Scaling, and so on).

    • ‘reservation-id` - The ID of the instance’s reservation. A reservation ID is created any time you launch an instance. A reservation ID has a one-to-one relationship with an instance launch request, but can be associated with more than one instance if you launch multiple instances using the same launch request. For example, if you launch one instance, you get one reservation ID. If you launch ten instances using the same launch request, you also get one reservation ID.

    • ‘root-device-name` - The device name of the root device volume (for example, `/dev/sda1`).

    • ‘root-device-type` - The type of the root device volume (`ebs` | `instance-store`).

    • ‘source-dest-check` - Indicates whether the instance performs source/destination checking. A value of `true` means that checking is enabled, and `false` means that checking is disabled. The value must be `false` for the instance to perform network address translation (NAT) in your VPC.

    • ‘spot-instance-request-id` - The ID of the Spot Instance request.

    • ‘state-reason-code` - The reason code for the state change.

    • ‘state-reason-message` - A message that describes the state change.

    • ‘subnet-id` - The ID of the subnet for the instance.

    • ‘tag`:&lt;key&gt; - The key/value combination of a tag assigned to the resource. Use the tag key in the filter name and the tag value as the filter value. For example, to find all resources that have a tag with the key `Owner` and the value `TeamA`, specify `tag:Owner` for the filter name and `TeamA` for the filter value.

    • ‘tag-key` - The key of a tag assigned to the resource. Use this filter to find all resources that have a tag with a specific key, regardless of the tag value.

    • ‘tenancy` - The tenancy of an instance (`dedicated` | `default` | `host`).

    • ‘virtualization-type` - The virtualization type of the instance (`paravirtual` | `hvm`).

    • ‘vpc-id` - The ID of the VPC that the instance is running in.

  • :instance_ids (Array<String>)

    One or more instance IDs.

    Default: Describes all your instances.

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is ‘DryRunOperation`. Otherwise, it is `UnauthorizedOperation`.

Returns:



1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
# File 'lib/aws-sdk-ec2/subnet.rb', line 1040

def instances(options = {})
  batches = Enumerator.new do |y|
    options = Aws::Util.deep_merge(options, filters: [{
      name: "subnet-id",
      values: [@id]
    }])
    resp = @client.describe_instances(options)
    resp.each_page do |page|
      batch = []
      page.data.reservations.each do |r|
        r.instances.each do |i|
          batch << Instance.new(
            id: i.instance_id,
            data: i,
            client: @client
          )
        end
      end
      y.yield(batch)
    end
  end
  Instance::Collection.new(batches)
end

#ipv_6_cidr_block_association_setArray<Types::SubnetIpv6CidrBlockAssociation>

Information about the IPv6 CIDR blocks associated with the subnet.



101
102
103
# File 'lib/aws-sdk-ec2/subnet.rb', line 101

def ipv_6_cidr_block_association_set
  data[:ipv_6_cidr_block_association_set]
end

#loadself Also known as: reload

Loads, or reloads #data for the current Aws::EC2::Subnet. Returns ‘self` making it possible to chain methods.

subnet.reload.data

Returns:

  • (self)


130
131
132
133
134
# File 'lib/aws-sdk-ec2/subnet.rb', line 130

def load
  resp = @client.describe_subnets(subnet_ids: [@id])
  @data = resp.subnets[0]
  self
end

#map_public_ip_on_launchBoolean

Indicates whether instances launched in this subnet receive a public IPv4 address.

Returns:

  • (Boolean)


69
70
71
# File 'lib/aws-sdk-ec2/subnet.rb', line 69

def map_public_ip_on_launch
  data[:map_public_ip_on_launch]
end

#network_interfaces(options = {}) ⇒ NetworkInterface::Collection

Examples:

Request syntax with placeholder values


network_interfaces = subnet.network_interfaces({
  filters: [
    {
      name: "String",
      values: ["String"],
    },
  ],
  dry_run: false,
  network_interface_ids: ["String"],
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :filters (Array<Types::Filter>)

    One or more filters.

    • ‘addresses.private-ip-address` - The private IPv4 addresses associated with the network interface.

    • ‘addresses.primary` - Whether the private IPv4 address is the primary IP address associated with the network interface.

    • ‘addresses.association.public-ip` - The association ID returned when the network interface was associated with the Elastic IP address (IPv4).

    • ‘addresses.association.owner-id` - The owner ID of the addresses associated with the network interface.

    • ‘association.association-id` - The association ID returned when the network interface was associated with an IPv4 address.

    • ‘association.allocation-id` - The allocation ID returned when you allocated the Elastic IP address (IPv4) for your network interface.

    • ‘association.ip-owner-id` - The owner of the Elastic IP address (IPv4) associated with the network interface.

    • ‘association.public-ip` - The address of the Elastic IP address (IPv4) bound to the network interface.

    • ‘association.public-dns-name` - The public DNS name for the network interface (IPv4).

    • ‘attachment.attachment-id` - The ID of the interface attachment.

    • ‘attachment.attach.time` - The time that the network interface was attached to an instance.

    • ‘attachment.delete-on-termination` - Indicates whether the attachment is deleted when an instance is terminated.

    • ‘attachment.device-index` - The device index to which the network interface is attached.

    • ‘attachment.instance-id` - The ID of the instance to which the network interface is attached.

    • ‘attachment.instance-owner-id` - The owner ID of the instance to which the network interface is attached.

    • ‘attachment.nat-gateway-id` - The ID of the NAT gateway to which the network interface is attached.

    • ‘attachment.status` - The status of the attachment (`attaching` | `attached` | `detaching` | `detached`).

    • ‘availability-zone` - The Availability Zone of the network interface.

    • ‘description` - The description of the network interface.

    • ‘group-id` - The ID of a security group associated with the network interface.

    • ‘group-name` - The name of a security group associated with the network interface.

    • ‘ipv6-addresses.ipv6-address` - An IPv6 address associated with the network interface.

    • ‘mac-address` - The MAC address of the network interface.

    • ‘network-interface-id` - The ID of the network interface.

    • ‘owner-id` - The AWS account ID of the network interface owner.

    • ‘private-ip-address` - The private IPv4 address or addresses of the network interface.

    • ‘private-dns-name` - The private DNS name of the network interface (IPv4).

    • ‘requester-id` - The ID of the entity that launched the instance on your behalf (for example, AWS Management Console, Auto Scaling, and so on).

    • ‘requester-managed` - Indicates whether the network interface is being managed by an AWS service (for example, AWS Management Console, Auto Scaling, and so on).

    • ‘source-desk-check` - Indicates whether the network interface performs source/destination checking. A value of `true` means checking is enabled, and `false` means checking is disabled. The value must be `false` for the network interface to perform network address translation (NAT) in your VPC.

    • ‘status` - The status of the network interface. If the network interface is not attached to an instance, the status is `available`; if a network interface is attached to an instance the status is `in-use`.

    • ‘subnet-id` - The ID of the subnet for the network interface.

    • ‘tag`:&lt;key&gt; - The key/value combination of a tag assigned to the resource. Use the tag key in the filter name and the tag value as the filter value. For example, to find all resources that have a tag with the key `Owner` and the value `TeamA`, specify `tag:Owner` for the filter name and `TeamA` for the filter value.

    • ‘tag-key` - The key of a tag assigned to the resource. Use this filter to find all resources assigned a tag with a specific key, regardless of the tag value.

    • ‘vpc-id` - The ID of the VPC for the network interface.

  • :dry_run (Boolean)

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is ‘DryRunOperation`. Otherwise, it is `UnauthorizedOperation`.

  • :network_interface_ids (Array<String>)

    One or more network interface IDs.

    Default: Describes all your network interfaces.

Returns:



1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
# File 'lib/aws-sdk-ec2/subnet.rb', line 1199

def network_interfaces(options = {})
  batches = Enumerator.new do |y|
    options = Aws::Util.deep_merge(options, filters: [{
      name: "subnet-id",
      values: [@id]
    }])
    resp = @client.describe_network_interfaces(options)
    resp.each_page do |page|
      batch = []
      page.data.network_interfaces.each do |n|
        batch << NetworkInterface.new(
          id: n.network_interface_id,
          data: n,
          client: @client
        )
      end
      y.yield(batch)
    end
  end
  NetworkInterface::Collection.new(batches)
end

#owner_idString

The ID of the AWS account that owns the subnet.

Returns:

  • (String)


87
88
89
# File 'lib/aws-sdk-ec2/subnet.rb', line 87

def owner_id
  data[:owner_id]
end

#stateString

The current state of the subnet.

Returns:

  • (String)


75
76
77
# File 'lib/aws-sdk-ec2/subnet.rb', line 75

def state
  data[:state]
end

#subnet_arnString

The Amazon Resource Name (ARN) of the subnet.

Returns:

  • (String)


113
114
115
# File 'lib/aws-sdk-ec2/subnet.rb', line 113

def subnet_arn
  data[:subnet_arn]
end

#tagsArray<Types::Tag>

Any tags assigned to the subnet.

Returns:



107
108
109
# File 'lib/aws-sdk-ec2/subnet.rb', line 107

def tags
  data[:tags]
end

#vpcVpc?

Returns:



1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
# File 'lib/aws-sdk-ec2/subnet.rb', line 1222

def vpc
  if data[:vpc_id]
    Vpc.new(
      id: data[:vpc_id],
      client: @client
    )
  else
    nil
  end
end

#vpc_idString

The ID of the VPC the subnet is in.

Returns:

  • (String)


81
82
83
# File 'lib/aws-sdk-ec2/subnet.rb', line 81

def vpc_id
  data[:vpc_id]
end

#wait_until(options = {}, &block) ⇒ Resource

Deprecated.

Use [Aws::EC2::Client] #wait_until instead

Note:

The waiting operation is performed on a copy. The original resource remains unchanged

Waiter polls an API operation until a resource enters a desired state.

## Basic Usage

Waiter will polls until it is successful, it fails by entering a terminal state, or until a maximum number of attempts are made.

# polls in a loop until condition is true
resource.wait_until(options) {|resource| condition}

## Example

instance.wait_until(max_attempts:10, delay:5) {|instance| instance.state.name == 'running' }

## Configuration

You can configure the maximum number of polling attempts, and the delay (in seconds) between each polling attempt. The waiting condition is set by passing a block to #wait_until:

# poll for ~25 seconds
resource.wait_until(max_attempts:5,delay:5) {|resource|...}

## Callbacks

You can be notified before each polling attempt and before each delay. If you throw ‘:success` or `:failure` from these callbacks, it will terminate the waiter.

started_at = Time.now
# poll for 1 hour, instead of a number of attempts
proc = Proc.new do |attempts, response|
  throw :failure if Time.now - started_at > 3600
end

  # disable max attempts
instance.wait_until(before_wait:proc, max_attempts:nil) {...}

## Handling Errors

When a waiter is successful, it returns the Resource. When a waiter fails, it raises an error.

begin
  resource.wait_until(...)
rescue Aws::Waiters::Errors::WaiterFailed
  # resource did not enter the desired state in time
end

attempts attempt in seconds invoked before each attempt invoked before each wait

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :max_attempts (Integer) — default: 10

    Maximum number of

  • :delay (Integer) — default: 10

    Delay between each

  • :before_attempt (Proc) — default: nil

    Callback

  • :before_wait (Proc) — default: nil

    Callback

Returns:

  • (Resource)

    if the waiter was successful

Raises:

  • (Aws::Waiters::Errors::FailureStateError)

    Raised when the waiter terminates because the waiter has entered a state that it will not transition out of, preventing success.

    yet successful.

  • (Aws::Waiters::Errors::UnexpectedError)

    Raised when an error is encountered while polling for a resource that is not expected.

  • (NotImplementedError)

    Raised when the resource does not



230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/aws-sdk-ec2/subnet.rb', line 230

def wait_until(options = {}, &block)
  self_copy = self.dup
  attempts = 0
  options[:max_attempts] = 10 unless options.key?(:max_attempts)
  options[:delay] ||= 10
  options[:poller] = Proc.new do
    attempts += 1
    if block.call(self_copy)
      [:success, self_copy]
    else
      self_copy.reload unless attempts == options[:max_attempts]
      :retry
    end
  end
  Aws::Waiters::Waiter.new(options).wait({})
end