public function getRoutingTable($type, $aws, $networkInterfaceId = null, $vpcId) { //Check for routing table $filter = array(array('name' => RouteTableFilterNameType::vpcId(), 'value' => $vpcId), array('name' => RouteTableFilterNameType::tagKey(), 'value' => 'scalr-rt-type'), array('name' => RouteTableFilterNameType::tagValue(), 'value' => $type)); $list = $aws->ec2->routeTable->describe(null, $filter); if ($list->count() > 0) { if ($type == \Scalr_Role_Behavior_Router::INTERNET_ACCESS_FULL) { $routingTable = $list->get(0); } else { /* @var $routingTable \Scalr\Service\Aws\Ec2\DataType\RouteTableData */ foreach ($list as $rTable) { foreach ($rTable->tagSet as $tag) { if ($tag->key == 'scalr-vpc-nid' && $tag->value == $networkInterfaceId) { $routingTable = $rTable; break; } } if ($routingTable) { break; } } } } $tags = array(array('key' => "scalr-id", 'value' => SCALR_ID), array('key' => "scalr-rt-type", 'value' => $type), array('key' => "Name", 'value' => "Scalr System Routing table for {$type} internet access")); if (!$routingTable) { // Create routing table for FULL internet access $routingTable = $aws->ec2->routeTable->create($vpcId); // Add new route for internet if ($type == \Scalr_Role_Behavior_Router::INTERNET_ACCESS_FULL) { // GET IGW $igwList = $aws->ec2->internetGateway->describe(null, array(array('name' => InternetGatewayFilterNameType::attachmentVpcId(), 'value' => $vpcId))); $igw = $igwList->get(0); if (!$igw) { $igw = $aws->ec2->internetGateway->create(); $aws->ec2->internetGateway->attach($igw->internetGatewayId, $vpcId); try { $igw->createTags(array(array('key' => "scalr-id", 'value' => SCALR_ID), array('key' => "Name", 'value' => 'Scalr System IGW'))); } catch (Exception $e) { } } $igwId = $igw->internetGatewayId; // Add new route for internet $aws->ec2->routeTable->createRoute($routingTable->routeTableId, '0.0.0.0/0', $igwId); } else { //outbound-only $aws->ec2->routeTable->createRoute($routingTable->routeTableId, '0.0.0.0/0', null, null, $networkInterfaceId); $tags[] = array('key' => "scalr-vpc-nid", 'value' => $networkInterfaceId); } try { $routingTable->createTags($tags); } catch (Exception $e) { } } return $routingTable->routeTableId; }