无服务器计划,检测 cron

Serverless scheduled, detect cron

我想通过 HTTP 和 cron 运行 一个函数,但没有看到任何让我确定它是 http 请求还是 cron 请求(明确)的文档:

    events:
      - http:
          path: /foo
          method: ANY
          cors:
            origin: '*'
      - schedule: rate(5 minute)

eventcontext 中是否有 属性 可以让我检测触发函数的原因?

您始终可以将输入传递给您的日程安排事件,并使用它来确定这是一个日程安排事件

events:
  - http:
      path: /foo
      method: ANY
      cors:
        origin: '*'
  - schedule:
      rate: rate(5 minute)
      input:
          isSchedule: true

这里有更多示例:https://serverless.com/framework/docs/providers/aws/events/schedule/

编辑:

忘了这个

{
    "version": "0",
    "id": "53dc4d37-cffa-4f76-80c9-8b7d4a4d2eaa",
    "detail-type": "Scheduled Event",
    "source": "aws.events",
    "account": "123456789012",
    "time": "2015-10-08T16:53:06Z",
    "region": "us-east-1",
    "resources": [
        "arn:aws:events:us-east-1:123456789012:rule/my-scheduled-rule"
    ],
    "detail": {}
}

您还可以检查 detail-type 字段 https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/RunLambdaSchedule.html