AWS API Gateway支持启用https协议,但默认情况下不启用。要启用https,您需要创建一个自定义域名并使用自己的证书或从AWS Certificate Manager中获取证书。下面是一个使用自己的证书的Python脚本示例:
import boto3
client = boto3.client('apigateway')
api_id = 'your_api_id'
stage_name = 'your_stage_name'
certificate_arn = 'your_certificate_arn'
endpoint_type = 'EDGE'
response = client.create_domain_name(
domainName='example.com',
certificateArn=certificate_arn,
endpointConfiguration={
'types': [
endpoint_type,
]
}
)
base_url = 'https://' + response['distributionDomainName'] + '/' + stage_name
response = client.create_base_path_mapping(
domainName='example.com',
restApiId=api_id,
basePath='/',
stage=stage_name
)
print('API Gateway base URL:', base_url)
这个脚本会创建一个自定义域名和基本路径映射,从而启用https协议,并返回API Gateway的基本URL。您需要将上述示例中的“your_api_id”替换为您的API Gateway ID,“your_stage_name”替换为您的阶段名称,“your_certificate_arn”替换为您的证书ARN。