How do I find the API endpoint of a lambda function?

Aws LambdaAws Api-Gateway

Aws Lambda Problem Overview


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. Neither the Lambda API documentation nor the API Gateway documentation seem to have that information (or perhaps I've missed it), so is this even possible in the first place?

Aws Lambda Solutions


Solution 1 - Aws Lambda

I don't really understand the above answer (maybe it's outdated?).

The absolute easiest way:

  1. Choose "API Gateway" under "Services" in AWS.
  2. Click on your API.
  3. Click on "Stages".
  4. Choose the stage you want to use
  5. Now you can see the entire URL very visible inside a blue box on the top with the heading "Invoke URL"

Solution 2 - Aws Lambda

Your API Gateway endpoint URL doesn't get exposed via an API call. However, since the URL of the API follows a certain structure, you could get all the necessary pieces and create the URI within your code.

https://API-ID.execute-api.REGION.amazonaws.com/STAGE

You could use apigateway:rest-apis to get your API-ID and restapi:stages to get the stage corresponding identifier.

Solution 3 - Aws Lambda

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

Solution 4 - Aws Lambda

Go to you lambda main page -> Click on "Application" [Function Overview section] -> Resource section -> LambdaAPIDefinition -> Stages tab -> [Select required stage] -> [Invoke URL] You can see the api endpoint visible.

Solution 5 - Aws Lambda

Following up on @larschanders comment, if you create the gateway using CloudFormation, the endpoint URL is surfaced as one of the stack outputs.

Solution 6 - Aws Lambda

If you use CloudFormation you can get this with Python and Boto3:

import boto3

cloudformation = boto3.resource('cloudformation')
stack = cloudformation.Stack(name=stack_name)
api_url = next(
    output['OutputValue'] for output in stack.outputs
    if output['OutputKey'] == 'EndpointURL')

This is from a working example of a REST service using Chalice that I put on GitHub. Here's a link to the pertinent code, in context: aws-doc-sdk-examples.

Solution 7 - Aws Lambda

To very precise Go to AWS Console search :

  1. Lambda under services
  2. Search the Function name which are looking for.
  3. In Function overview, you will find API GATEWAY (Click on this)
  4. Under API GATEWAY, click on Details (down arrow)
  5. Under Details, you will find all the details like API endpoint : API type : Authorization : Method : Resource path : Stage :

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionhowchengView Question on Stackoverflow
Solution 1 - Aws LambdalarschandersView Answer on Stackoverflow
Solution 2 - Aws LambdaJurgenView Answer on Stackoverflow
Solution 3 - Aws LambdaPeter HalversonView Answer on Stackoverflow
Solution 4 - Aws LambdakarthikpswamyView Answer on Stackoverflow
Solution 5 - Aws LambdaPeter HalversonView Answer on Stackoverflow
Solution 6 - Aws LambdaLaren CrawfordView Answer on Stackoverflow
Solution 7 - Aws LambdaAk_SinghView Answer on Stackoverflow