Reputation: 18790
How can I get the endpoint or URI from AWS API Gateway ? I see only arn from the management console
Upvotes: 4
Views: 4005
Reputation: 5859
If you know the name of your rest-api endpoint (and it's been deployed as @pogul described), you can construct the URL. Here's a short python commandline app using boto3 that will return the URL given a name.
#!/usr/bin/env python
import argparse
import boto3
# for example:
# https://abcd123456.execute-api.us-east-2.amazonaws.com/mydeploystage
SUBDOMAIN = 'execute-api'
SECOND_LEVEL_DOMAIN = "amazonaws"
EXT = "com"
session = boto3.session.Session()
default_region = session.region_name
DEFAULT_PROTOCOL = 'https'
parser = argparse.ArgumentParser(description="guess the urls given a rest endpoint")
parser.add_argument("name", help="name of the rest-api endpoint")
parser.add_argument("--region", default=default_region, help=f"region (default: {default_region})")
parser.add_argument("--protocol", default=DEFAULT_PROTOCOL, help=f"protocol (default: {DEFAULT_PROTOCOL})")
args = parser.parse_args()
client = boto3.client('apigateway')
response = client.get_rest_apis()
name_to_result = {result.get('name'): result for result in response.get('items')}
api_endpoint = name_to_result[args.name]
api_id = api_endpoint['id']
response = client.get_stages(restApiId=api_id)
for stage in response['item']:
stage_name = stage['stageName']
domain_name = ".".join([api_id, SUBDOMAIN, args.region, SECOND_LEVEL_DOMAIN, EXT])
url = f"{args.protocol}://{domain_name}/{stage_name}"
print(url)
Upvotes: 0
Reputation: 458
You need to deploy an API in order to get an endpoint URL. The same API may be deployed under different guises — you might call it "dev" for a development deployment or "prod" for production purposes.
The API can only be accessed in this way once deployed, so:
Upvotes: 4