1

I've cloned and deployed the example Serverless Lambda function from this repository, https://github.com/serverless/examples/tree/master/aws-python-simple-http-endpoint, which has an endpoint which simply prints the current time:

import json
import datetime


def endpoint(event, context):
    current_time = datetime.datetime.now().time()
    body = {
        "message": "Hello, the current time is " + str(current_time)
    }

    response = {
        "statusCode": 200,
        "body": json.dumps(body)
    }

    return response

I've deployed it:

> serverless deploy list functions
Serverless: Listing functions and their last 5 versions:
Serverless: -------------
Serverless: currentTime: $LATEST, 1

and am able to invoke it using serverless invoke:

> serverless invoke --function currentTime --log
{
    "body": "{\"message\": \"Hello, the current time is 22:51:06.872660\"}",
    "statusCode": 200
}
--------------------------------------------------------------------
START RequestId: d4629611-e16b-4afa-80ef-5ac1a7331679 Version: $LATEST
END RequestId: d4629611-e16b-4afa-80ef-5ac1a7331679
REPORT RequestId: d4629611-e16b-4afa-80ef-5ac1a7331679  Duration: 0.32 ms   Billed Duration: 100 ms     Memory Size: 1024 MB    Max Memory Used: 43 MB  

In the AWS console, I looked up the Lambda's function's endpoint under the 'API Gateway' service,

enter image description here

and tried to curl it. However, I get an error for a missing authorization token:

curl https://x6gnvhuuzh.execute-api.us-east-1.amazonaws.com/dev
{"message":"Missing Authentication Token"}⏎  

According to the README.md for that example, I should see the same output as for the serverless invoke. Any idea why the endpoint is returning a Missing Authentication Token message?

Kurt Peek
  • 52,165
  • 91
  • 301
  • 526
  • **See Also**: [Missing Authentication Token while accessing API Gateway?](https://stackoverflow.com/q/39655048/1366033) – KyleMit Mar 10 '21 at 21:08

1 Answers1

0

Apparently I forgot to append /ping to the URL as in the Github example. As documented at https://docs.aws.amazon.com/apigateway/latest/developerguide/amazon-api-gateway-using-stage-variables.html,

enter image description here

So I entered the URL with /ping and got the expected result:

enter image description here

Kurt Peek
  • 52,165
  • 91
  • 301
  • 526