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,
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?