要在不中断客户的情况下更改AWS API网关的自定义域名的base_mapping,可以采用以下解决方法:
import boto3
client = boto3.client('apigateway')
domain_name = 'your_domain_name'
rest_api_id = 'your_rest_api_id'
response = client.get_domain_name(
domainName=domain_name
)
base_path_mapping = response['domainName']['basePathMappings'][0]
basePath
更改为新的路径:response = client.update_base_path_mapping(
domainName=domain_name,
basePathMappingId=base_path_mapping['basePathMappingId'],
patchOperations=[
{
'op': 'replace',
'path': '/basePath',
'value': '/new_base_path'
},
]
)
basePath
设置为新的路径:response = client.create_base_path_mapping(
domainName=domain_name,
restApiId=rest_api_id,
stage='your_stage_name',
basePath='/new_base_path'
)
请注意,这些示例代码使用Python和AWS SDK for Python(Boto3)进行演示,您需要根据自己的实际情况进行适当的调整。确保替换your_domain_name
、your_rest_api_id
、your_stage_name
和/new_base_path
为实际的值。
这个解决方法可以在不中断现有客户的情况下更改自定义域名的base_mapping。