Serverless 不会创建 CloudWatch Events 作为 lambda 的触发器。没有警告或错误。
functions:
aggregate:
handler: statistics.handler
events:
- schedule:
rate: rate(10 minutes)
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:
示例代码:
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 事件规则)。