【问题标题】:{"message":"Missing Authentication Token"} when curling and endpoint for a Serverless Lambda function{"message":"Missing Authentication Token"} 无服务器 Lambda 函数的 curl 和端点
【发布时间】:2020-01-04 03:12:33
【问题描述】:

我已经从这个存储库https://github.com/serverless/examples/tree/master/aws-python-simple-http-endpoint 克隆并部署了示例无服务器 Lambda 函数,它有一个简单地打印当前时间的端点:

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

我已经部署了它:

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

并且可以使用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  

在 AWS 控制台中,我在“API Gateway”服务下查找了 Lambda 函数的端点,

并尝试curl 它。但是,我收到一个缺少授权令牌的错误:

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

根据该示例的README.md,我应该看到与serverless invoke 相同的输出。知道为什么端点会返回 Missing Authentication Token 消息吗?

【问题讨论】:

标签: python serverless-framework serverless


【解决方案1】:

显然我忘记将/ping 附加到 URL 中,就像在 Github 示例中一样。如https://docs.aws.amazon.com/apigateway/latest/developerguide/amazon-api-gateway-using-stage-variables.html 所述,

于是我输入了/ping的网址,得到了预期的结果:

【讨论】:

  • 是的,当您收到此错误消息时通常是 404。
猜你喜欢
  • 2020-03-05
  • 2017-05-19
  • 2021-10-19
  • 2014-07-31
  • 1970-01-01
  • 2021-12-20
  • 2021-11-01
  • 2022-01-04
  • 1970-01-01
相关资源
最近更新 更多