AWS SDK for Ruby
Developer Guide

Creating an Amazon EC2 Route Table and Associating It with a Subnet

The following example creates a route table named MyGroovyRouteTable in us-west-2 region on a VPC with the ID VPC_ID. The route table uses the route with the CIDR block, and the gateway with the ID IGW_ID. The example associates the route table with the subnet that has ID SUBNET_ID, and then displays the route table's ID.

require 'aws-sdk-ec2' # v2: require 'aws-sdk' ec2 = 'us-west-2') table = ec2.create_route_table({ vpc_id: VPC_ID }) table.create_tags({ tags: [{ key: 'Name', value: 'MyGroovyRouteTable' }]}) table.create_route({ destination_cidr_block: '', gateway_id: IGW_ID }) table.associate_with_subnet({ subnet_id: SUBNET_ID }) puts