ruby/example_code/ec2/ec2-ruby-example-create-route-table.rb
def route_table_created_and_associated?(
  ec2_resource,
  vpc_id,
  subnet_id,
  gateway_id,
  destination_cidr_block,
  tag_key,
  tag_value
)
  route_table = ec2_resource.create_route_table(vpc_id: vpc_id)
  puts "Created route table with ID '#{route_table.id}'."
  route_table.create_tags(
    tags: [
      {
        key: tag_key,
        value: tag_value
      }
    ]
  )
  puts 'Added tags to route table.'
  route_table.create_route(
    destination_cidr_block: destination_cidr_block,
    gateway_id: gateway_id
  )
  puts 'Created route with destination CIDR block ' \
    "'#{destination_cidr_block}' and associated with gateway " \
    "with ID '#{gateway_id}'."
  route_table.associate_with_subnet(subnet_id: subnet_id)
  puts "Associated route table with subnet with ID '#{subnet_id}'."
  return true
rescue StandardError => e
  puts "Error creating or associating route table: #{e.message}"
  puts 'If the route table was created but not associated, you should ' \
    'clean up by deleting the route table.'
  return false
end
# Prerequisites:
#
# - A VPC in Amazon VPC.
# - A subnet in that VPC.
# - A gateway attached to that subnet.
#
# @param ec2_resource [Aws::EC2::Resource] An initialized
#   Amazon Elastic Compute Cloud (Amazon EC2) resource object.
# @param vpc_id [String] The ID of the VPC for the route table.
# @param subnet_id [String] The ID of the subnet for the route table.
# @param gateway_id [String] The ID of the gateway for the route.
# @param destination_cidr_block [String] The destination CIDR block
#   for the route.
# @param tag_key [String] The key portion of the tag for the route table.
# @param tag_value [String] The value portion of the tag for the route table.
# @return [Boolean] true if the route table was created and associated;
#   otherwise, false.
# @example
#   exit 1 unless route_table_created_and_associated?(
#     Aws::EC2::Resource.new(region: 'us-west-2'),
#     'vpc-0b6f769731EXAMPLE',
#     'subnet-03d9303b57EXAMPLE',
#     'igw-06ca90c011EXAMPLE',
#     '0.0.0.0/0',
#     'my-key',
#     'my-value'
#   )

A VPC in Amazon VPC.
A subnet in that VPC.
A gateway attached to that subnet.
A VPC in Amazon VPC . A subnet in that VPC . A gateway attached to that subnet .
def route_table_created_and_associated?(
  ec2_resource,
  vpc_id,
  subnet_id,
  gateway_id,
  destination_cidr_block,
  tag_key,
  tag_value
)
  route_table = ec2_resource.create_route_table(vpc_id: vpc_id)
  puts "Created route table with ID '#{route_table.id}'."
  route_table.create_tags(
    tags: [
      {
        key: tag_key,
        value: tag_value
      }
    ]
  )
  puts 'Added tags to route table.'
  route_table.create_route(
    destination_cidr_block: destination_cidr_block,
    gateway_id: gateway_id
  )
  puts 'Created route with destination CIDR block ' \
    "'#{destination_cidr_block}' and associated with gateway " \
    "with ID '#{gateway_id}'."
  route_table.associate_with_subnet(subnet_id: subnet_id)
  puts "Associated route table with subnet with ID '#{subnet_id}'."
  return true
rescue StandardError => e
  puts "Error creating or associating route table: #{e.message}"
  puts 'If the route table was created but not associated, you should ' \
    'clean up by deleting the route table.'
  return false
end
def route_table_created_and_associated? ( ec2_resource , vpc_id , subnet_id , gateway_id , destination_cidr_block , tag_key , tag_value ) route_table = ec2_resource . create_route_table ( vpc_id : vpc_id ) puts "Created route table with ID '#{route_table.id}'." route_table . create_tags ( tags : [ { key : tag_key , value : tag_value } ] ) puts 'Added tags to route table.' route_table . create_route ( destination_cidr_block : destination_cidr_block , gateway_id : gateway_id ) puts 'Created route with destination CIDR block ' "'#{destination_cidr_block}' and associated with gateway " "with ID '#{gateway_id}'." route_table . associate_with_subnet ( subnet_id : subnet_id ) puts "Associated route table with subnet with ID '#{subnet_id}'." return true rescue StandardError => e puts "Error creating or associating route table: #{e.message}" puts 'If the route table was created but not associated, you should ' 'clean up by deleting the route table.' return false end
Prerequisites:
 A VPC in Amazon VPC.
Prerequisites : A VPC in Amazon VPC .
true if the route table was created and associated; otherwise, false.
true if the route table was created and associated ; otherwise false .
Boolean
ec2_resource
An initialized Amazon Elastic Compute Cloud (Amazon EC2) resource object.
An initialized Amazon Elastic Compute Cloud ( Amazon EC2 ) resource object .
vpc_id
The ID of the VPC for the route table.
The ID of the VPC for the route table .
subnet_id
The ID of the subnet for the route table.
The ID of the subnet for the route table .
gateway_id
The ID of the gateway for the route.
The ID of the gateway for the route .
destination_cidr_block
The destination CIDR block for the route.
The destination CIDR block for the route .
tag_key
The key portion of the tag for the route table.
The key portion of the tag for the route table .
tag_value
The value portion of the tag for the route table.
The value portion of the tag for the route table .
example
None