Search code examples
amazon-web-servicesaws-lambda

AWS API Gateway: {"message":"Not Found"}


I'm trying out AWS API Gateway for the first time, using HTTP Gateway as the gateway style and Lambda as the execution method. My Lambda function requires no input, and outputs a number. This has been confirmed using the Test button. But then I configure the Gateway to use this function, and it gives me an invoke URL. I click the URL, and what comes back is {"message":"Not Found"}.

Can anyone give me a clue where to look? I am wondering, what sort of object at what level was not found?

(I did not use the Deploy button on the API's page, because that looks like a deeper level of complexity only needed if one is going to employ more versions or configurations.)

The function is configured to use lambda_function.second as the entry point, and this has been tested within Lambda. Here's the relevant code:

import logging

logger = logging.getLogger()
logger.setLevel(logging.INFO)

def second(event, context):
    ...
    result = None
    action = 'increment'
    number = event.get('number', 17)
    if action == 'increment':
        result = number + 1
        logger.info('Calculated result of %s', result)
    else:
        logger.error("%s is not a valid action.", action)

    response = {'result': result}
    return response

Solution

  • Turns out that the URL provided on the API Gateway page may not be complete. They gave me

    https://js6g8a6b3l.execute-api.us-east-2.amazonaws.com
    

    But then there are also routes. And I had defined only one route, named incrementTest. So the correct URL was in fact

    https://js6g8a6b3l.execute-api.us-east-2.amazonaws.com/incrementTest