Amazon Elastic Compute Cloud
API Reference (API Version 2013-02-01)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Did this page help you?  Yes | No |  Tell us about it...

CreateRoute

Description

Creates a route in a route table within a VPC. The route's target can be either a gateway attached to the VPC or a NAT instance in the VPC.

When determining how to route traffic, we use the route with the most specific match. For example, let's say the traffic is destined for 192.0.2.3, and the route table includes the following two routes:

  • 192.0.2.0/24 (goes to some target A)

  • 192.0.2.0/28 (goes to some target B)

Both routes apply to the traffic destined for 192.0.2.3. However, the second route in the list covers a smaller number of IP addresses and is therefore more specific, so we use that route to determine where to target the traffic.

For more information about route tables, see Route Tables in the Amazon Virtual Private Cloud User Guide.

Request Parameters

RouteTableId

The ID of the route table where the route will be added.

Type: String

Default: None

Required: Yes

DestinationCidrBlock

The CIDR address block used for the destination match. Routing decisions are based on the most specific match.

Type: String

Default: None

Required: Yes

GatewayId

The ID of a gateway attached to your VPC.

Type: String

Default: None

Required: Conditional

Condition: You must provide only one of the following: a GatewayId, InstanceId, or NetworkInterfaceId.

InstanceId

The ID of a NAT instance in your VPC.

Type: String

Default: None

Required: Conditional

Condition: You must provide only one of the following: a GatewayId, InstanceId, or NetworkInterfaceId.

NetworkInterfaceId

Allows the routing of network interface IDs. Exactly one interface must be attached when specifying an instance ID or it fails.

Type: String

Default: None

Required: Conditional

Condition: You must provide only one of the following: a GatewayId, InstanceId, or NetworkInterfaceId.

Response Elements

The following elements are returned in a CreateRouteResponse element.

requestId

The ID of the request.

Type: xsd:string

return

Returns true if the request succeeds. Otherwise, returns an error.

Type: xsd:boolean

Examples

Example Request

This example creates a route in the route table with ID rtb-e4ad488d. The route matches all traffic (0.0.0.0/0) and routes it to the Internet gateway with ID igw-eaad4883.

https://ec2.amazonaws.com/?Action=CreateRoute
&RouteTableId=rtb-e4ad488d
&DestinationCidrBlock=0.0.0.0/0
&GatewayId=igw-eaad4883
&AUTHPARAMS

Example Request

This example creates a route in the route table with ID rtb-g8ff4ea2. The route sends all traffic (0.0.0.0/0) to the NAT instance with ID i-1a2b3c4d.

https://ec2.amazonaws.com/?Action=CreateRoute
&RouteTableId=rtb-g8ff4ea2
&DestinationCidrBlock=0.0.0.0/0
&InstanceId=i-1a2b3c4d
&AUTHPARAMS

Example Response

<CreateRouteResponse xmlns="http://ec2.amazonaws.com/doc/2013-02-01/">
   <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId> 
   <return>true</return>
</CreateRouteResponse>