Uso de GetBasePathMapping con un SDK de AWS o la CLI - Ejemplos de código de AWS SDK

Hay más ejemplos de AWS SDK disponibles en el repositorio de GitHub de ejemplos de AWS SDK de documentos.

Uso de GetBasePathMapping con un SDK de AWS o la CLI

Los siguientes ejemplos de código muestran cómo utilizar GetBasePathMapping.

CLI
AWS CLI

Obtención de la asignación de ruta base para un nombre de dominio personalizado

Comando:

aws apigateway get-base-path-mapping --domain-name subdomain.domain.tld --base-path v1

Salida:

{ "basePath": "v1", "restApiId": "1234w4321e", "stage": "api" }
  • Para obtener información sobre la API, consulte GetBasePathMapping en la Referencia de comandos de la AWS CLI.

PHP
SDK para PHP
nota

Hay más en GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

require 'vendor/autoload.php'; use Aws\ApiGateway\ApiGatewayClient; use Aws\Exception\AwsException; /* //////////////////////////////////////////////////////////////////////////// * Purpose: Gets the base path mapping for a custom domain name in * Amazon API Gateway. * * Prerequisites: A custom domain name in API Gateway. For more information, * see "Custom Domain Names" in the Amazon API Gateway Developer Guide. * * Inputs: * - $apiGatewayClient: An initialized AWS SDK for PHP API client for * API Gateway. * - $basePath: The base path name that callers must provide as part of the * URL after the domain name. * - $domainName: The custom domain name for the base path mapping. * * Returns: The base path mapping, if available; otherwise, the error message. * ///////////////////////////////////////////////////////////////////////// */ function getBasePathMapping($apiGatewayClient, $basePath, $domainName) { try { $result = $apiGatewayClient->getBasePathMapping([ 'basePath' => $basePath, 'domainName' => $domainName, ]); return 'The base path mapping\'s effective URI is: ' . $result['@metadata']['effectiveUri']; } catch (AwsException $e) { return 'Error: ' . $e['message']; } } function getsTheBasePathMapping() { $apiGatewayClient = new ApiGatewayClient([ 'profile' => 'default', 'region' => 'us-east-1', 'version' => '2015-07-09' ]); echo getBasePathMapping($apiGatewayClient, '(none)', 'example.com'); } // Uncomment the following line to run this code in an AWS account. // getsTheBasePathMapping();
  • Para obtener información sobre la API, consulte GetBasePathMapping en la Referencia de la API de AWS SDK para PHP.