AWS SDK for Ruby
Developer Guide

Creating a Public Subnet for Amazon EC2

The following example creates a public subnet MyGroovySubnet in the us-west-2 region and the Availablity Zone us-west-2a. The example attaches the public subnet to a VPC with the ID VPC_ID that uses the CIDR block 10.200.10.0/24, and then displays the subnet's ID.

The public subnet created in this example has 256 private IP addresses within the VPC.

require 'aws-sdk-ec2' # v2: require 'aws-sdk' ec2 = Aws::EC2::Resource.new(region: 'us-west-2') subnet = ec2.create_subnet({ vpc_id: VPC_ID, cidr_block: '10.200.10.0/24', availability_zone: 'us-west-2a' }) subnet.create_tags({ tags: [{ key: 'Name', value: 'MyGroovySubnet' }]}) puts subnet.id