Menu
Amazon Elastic Compute Cloud
API Reference (API Version 2016-11-15)

CreateRoute

Creates a route in a route table within a VPC.

You must specify one of the following targets: Internet gateway or virtual private gateway, NAT instance, NAT gateway, VPC peering connection, network interface, or egress-only Internet gateway.

When determining how to route traffic, we use the route with the most specific match. For example, traffic is destined for the IPv4 address 192.0.2.3, and the route table includes the following two IPv4 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

The following parameters are for this specific action. For more information about required and optional parameters that are common to all actions, see Common Query Parameters.

DestinationCidrBlock

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

Type: String

Required: No

DestinationIpv6CidrBlock

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

Type: String

Required: No

DryRun

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.

Type: Boolean

Required: No

EgressOnlyInternetGatewayId

[IPv6 traffic only] The ID of an egress-only Internet gateway.

Type: String

Required: No

GatewayId

The ID of an Internet gateway or virtual private gateway attached to your VPC.

Type: String

Required: No

InstanceId

The ID of a NAT instance in your VPC. The operation fails if you specify an instance ID unless exactly one network interface is attached.

Type: String

Required: No

NatGatewayId

[IPv4 traffic only] The ID of a NAT gateway.

Type: String

Required: No

NetworkInterfaceId

The ID of a network interface.

Type: String

Required: No

RouteTableId

The ID of the route table for the route.

Type: String

Required: Yes

VpcPeeringConnectionId

The ID of a VPC peering connection.

Type: String

Required: No

Response Elements

The following elements are returned by the service.

requestId

The ID of the request.

Type: String

return

Returns true if the request succeeds; otherwise, it returns an error.

Type: Boolean

Errors

For information about the errors that are common to all actions, see Common Errors.

Examples

Example 1

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

Sample Request

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

Example 2

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

Sample Request

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

Example 3

This example creates a route in route table rtb-g8ff4ea2. The route matches traffic for the IPv4 CIDR block 10.0.0.0/16 and routes it to VPC peering connection, pcx-111aaa22. This route enables IPv4 traffic to be directed to the other peered VPC in the VPC peering connection.

Sample Request

Copy
https://ec2.amazonaws.com/?Action=CreateRoute &RouteTableId=rtb-g8ff4ea2 &DestinationCidrBlock=10.0.0.0/16 &vpcPeeringConnectionId=pcx-111aaa22 &AUTHPARAMS

Example 4

This example creates a route in route table rtb-g8ff4ea2. The route sends all IPv6 traffic ::/0 to an egress-only Internet gateway.

Sample Request

Copy
https://ec2.amazonaws.com/?Action=CreateRoute &RouteTableId=rtb-g8ff4ea2 &DestinationIpv6CidrBlock=::/0 &EgressOnlyInternetGatewayId=eigw-1234567890abc1234 &AUTHPARAMS

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following: