I have a Lambda function that has an exposed API Gateway endpoint, and I can get the URL for that via the AWS console. However, I would like to get that URL via API call. Neithe
I'm not seeing a direct answer to the OP's question (get endpoint URL using API). Here's a snippet of Python code that I hope will guide the way, even if you're using other language bindings or the CLI. Note the difference in approach for getting the internal endpoint vs getting any associated custom domain endpoints.
import boto3
apigw = boto3.client('apigateway')
def get_rest_api_internal_endpoint(api_id, stage_name, region=None):
if region is None:
region = apigw.meta.region_name
return f"https://{api_id}.execute-api.{region}.amazonaws.com/{stage_name}"
def get_rest_api_public_endpoints(api_id, stage_name):
endpoints = []
for item in apigw.get_domain_names().get('items',[]):
domain_name = item['domainName']
for mapping in apigw.get_base_path_mappings(domainName=domain_name).get('items', []):
if mapping['restApiId'] == api_id and mapping['stage'] == stage_name:
path = mapping['basePath']
endpoint = f"https://{domain_name}"
if path != "(none)":
endpoint += path
endpoints.append(endpoint)
return endpoints