2018-12-03 10:59:49 -08:00
< ? php
2020-04-02 15:46:13 -07:00
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
2024-02-05 10:49:20 -07:00
2019-01-30 18:35:51 -08:00
// snippet-start:[apigateway.php.get_base_path_mapping.complete]
// snippet-start:[apigateway.php.get_base_path_mapping.import]
2018-12-03 10:59:49 -08:00
require 'vendor/autoload.php' ;
2024-02-05 10:49:20 -07:00
2020-04-02 15:46:13 -07:00
use Aws\ApiGateway\ApiGatewayClient ;
2018-12-03 10:59:49 -08:00
use Aws\Exception\AwsException ;
2024-02-05 10:49:20 -07:00
2019-01-30 18:35:51 -08:00
// snippet-end:[apigateway.php.get_base_path_mapping.import]
2024-02-05 10:49:20 -07:00
2020-04-15 14:25:50 -07:00
/* ////////////////////////////////////////////////////////////////////////////
2021-11-11 16:25:06 -07:00
* Purpose: Gets the base path mapping for a custom domain name in
2020-04-15 14:25:50 -07:00
* Amazon API Gateway.
2021-11-11 16:25:06 -07:00
*
2020-04-15 14:25:50 -07:00
* Prerequisites: A custom domain name in API Gateway. For more information,
* see "Custom Domain Names" in the Amazon API Gateway Developer Guide.
*
* Inputs:
2021-11-11 16:25:06 -07:00
* - $apiGatewayClient: An initialized AWS SDK for PHP API client for
2020-04-17 16:11:47 -07:00
* API Gateway.
2021-11-11 16:25:06 -07:00
* - $basePath: The base path name that callers must provide as part of the
2020-04-15 14:25:50 -07:00
* URL after the domain name.
* - $domainName: The custom domain name for the base path mapping.
*
2020-04-17 16:11:47 -07:00
* Returns: The base path mapping, if available; otherwise, the error message.
2020-04-15 14:25:50 -07:00
* ///////////////////////////////////////////////////////////////////////// */
2024-02-05 10:49:20 -07:00
2021-11-11 16:25:06 -07:00
// snippet-start:[apigateway.php.get_base_path_mapping.main]
2020-04-15 14:25:50 -07:00
function getBasePathMapping ( $apiGatewayClient , $basePath , $domainName )
2020-04-02 15:46:13 -07:00
{
2020-04-15 14:25:50 -07:00
try {
$result = $apiGatewayClient -> getBasePathMapping ([
'basePath' => $basePath ,
'domainName' => $domainName ,
]);
2021-11-11 16:25:06 -07:00
return 'The base path mapping\'s effective URI is: ' .
2020-04-15 14:25:50 -07:00
$result [ '@metadata' ][ 'effectiveUri' ];
} catch ( AwsException $e ) {
return 'Error: ' . $e [ 'message' ];
}
2024-02-05 10:49:20 -07:00
}
2020-04-15 14:25:50 -07:00
function getsTheBasePathMapping ()
{
$apiGatewayClient = new ApiGatewayClient ([
'profile' => 'default' ,
'region' => 'us-east-1' ,
'version' => '2015-07-09'
]);
2024-02-05 10:49:20 -07:00
2020-04-15 14:25:50 -07:00
echo getBasePathMapping ( $apiGatewayClient , '(none)' , 'example.com' );
}
2024-02-05 10:49:20 -07:00
2020-04-15 14:25:50 -07:00
// Uncomment the following line to run this code in an AWS account.
// getsTheBasePathMapping();
2019-01-30 18:35:51 -08:00
// snippet-end:[apigateway.php.get_base_path_mapping.main]
// snippet-end:[apigateway.php.get_base_path_mapping.complete]