无服务器 - 安排事件不创建 CloudWatch Events

Serverless - Schedule event not creating CloudWatch Events

Serverless 不会创建 CloudWatch Events 作为 lambda 的触发器。没有警告或错误。

functions:
  aggregate:
    handler: statistics.handler
    events:
      - schedule:
          rate: rate(10 minutes)

Serverless 的例子没有证明缩进的关键性质。 https://serverless.com/framework/docs/providers/aws/events/schedule/#schedule

functions:
  aggregate:
    handler: statistics.handler
    events:
    # "- schedule:" has to start at the same indentation as the "events:" above it.
    - schedule:
        # The CloudWatch Events Rules have to be exactly 4 spaces indented below the "- schedule:"
        rate: rate(10 minutes)
        # ... other fields

严重:

  • - schedule: 与其上方的 events: 对齐。
  • 对齐下一行​​,例如rate: rate(6 minutes)- schedule:
  • 开始缩进 4 个空格

示例代码:

service: my-service
provider:
  name: aws
  region: us-west-2
  runtime: nodejs10.x
functions:
  hello:
    handler: handler.hello
    events:
    - schedule:
        rate: cron(*/5 * * * ? *)
        enabled: true

module.exports.hello = (event, context, callback) => {
  console.log("Hello, world!");
  callback(null);
};

简单缩进 - 像我期望的那样安排 2 个空格不会在 AWS 中创建 cloudwatch 事件。仅更改 2 个空格就决定了是否创建 cloudwatch 事件规则。

注意:两个缩进之间没有错误,但它创建了 6 对 8 个 AWS 资源(缺少 2 个不会创建 cloudwatch 事件规则)。