/**
  * Get an endpoint for a specific region from a service description
  *
  * @param ServiceDescriptionInterface $description Service description
  * @param string                      $region      Region of the endpoint
  * @param string                      $scheme      URL scheme
  *
  * @return string
  * @throws InvalidArgumentException
  */
 public static function getEndpoint(ServiceDescriptionInterface $description, $region, $scheme)
 {
     $service = $description->getData('serviceFullName');
     // Lookup the region in the service description
     if (!($regions = $description->getData('regions'))) {
         throw new InvalidArgumentException("No regions found in the {$service} description");
     }
     // Ensure that the region exists for the service
     if (!isset($regions[$region])) {
         throw new InvalidArgumentException("{$region} is not a valid region for {$service}");
     }
     // Ensure that the scheme is valid
     if ($regions[$region][$scheme] == false) {
         throw new InvalidArgumentException("{$scheme} is not a valid URI scheme for {$service} in {$region}");
     }
     return $scheme . '://' . $regions[$region]['hostname'];
 }
Example #2
0
 /**
  * Get an endpoint for a specific region from a service description
  * @deprecated This function will no longer be updated to work with new regions.
  */
 public static function getEndpoint(ServiceDescriptionInterface $description, $region, $scheme)
 {
     try {
         $service = $description->getData('endpointPrefix');
         $provider = RulesEndpointProvider::fromDefaults();
         $result = $provider(array('service' => $service, 'region' => $region, 'scheme' => $scheme));
         return $result['endpoint'];
     } catch (\InvalidArgumentException $e) {
         throw new InvalidArgumentException($e->getMessage(), 0, $e);
     }
 }