Scalr\Service\Aws\Ec2\V20140615\Ec2Api::createRoute PHP Method

createRoute() public method

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. Condition:You must provide only one of the following: a GatewayId, InstanceId, or NetworkInterfaceId.
public createRoute ( string $routeTableId, string $destinationCidrBlock, string $gatewayId = null, string $instanceId = null, string $networkInterfaceId = null, string $vpcPeeringConnectionId = null ) : boolean
$routeTableId string The ID of the route table where the route will be added.
$destinationCidrBlock string The CIDR address block used for the destination match.
$gatewayId string optional The ID of a gataway attached to your VPC.
$instanceId string optional The ID of a NAT instance in your VPC.
$networkInterfaceId string optional Allows the routing of network interface IDs. Exactly one interface must be attached when specifying an instance ID or it fails.
$vpcPeeringConnectionId string optional The ID of a VPC peering connection.
return boolean Returns TRUE on success
    public function createRoute($routeTableId, $destinationCidrBlock, $gatewayId = null, $instanceId = null, $networkInterfaceId = null, $vpcPeeringConnectionId = null)
    {
        $result = false;
        $options = array('DestinationCidrBlock' => (string) $destinationCidrBlock, 'RouteTableId' => (string) $routeTableId);
        $f = 0;
        if ($gatewayId !== null) {
            $options['GatewayId'] = (string) $gatewayId;
            $f++;
        }
        if ($instanceId !== null) {
            $options['InstanceId'] = (string) $instanceId;
            $f++;
        }
        if ($networkInterfaceId !== null) {
            $options['NetworkInterfaceId'] = (string) $networkInterfaceId;
            $f++;
        }
        if ($vpcPeeringConnectionId !== null) {
            $options['VpcPeeringConnectionId'] = (string) $vpcPeeringConnectionId;
            $f++;
        }
        if ($f > 1) {
            throw new \InvalidArgumentException(sprintf('You must provide only one of the following: a GatewayId, InstanceId, VpcPeeringConnectionId or NetworkInterfaceId.'));
        }
        $action = ucfirst(__FUNCTION__);
        $response = $this->client->call($action, $options);
        if ($response->getError() === false) {
            $sxml = simplexml_load_string($response->getRawContent());
            if ((string) $sxml->return != 'true') {
                throw new Ec2Exception(sprintf('Amazon Ec2 could not %s RouteTableId:"%s". It returned "%s"', $action, $options['RouteTableId'], $sxml->return));
            }
            $result = true;
        }
        return $result;
    }
Ec2Api