【发布时间】:2019-01-28 21:32:48
【问题描述】:
我知道我可以通过 AWS 控制台创建计划的 Cloud Watch 事件:
有没有办法在 Cloud Formation 模板中声明类似事件?
【问题讨论】:
标签: amazon-web-services amazon-cloudformation amazon-cloudwatch
我知道我可以通过 AWS 控制台创建计划的 Cloud Watch 事件:
有没有办法在 Cloud Formation 模板中声明类似事件?
【问题讨论】:
标签: amazon-web-services amazon-cloudformation amazon-cloudwatch
以下是在 cloudwatch 中创建计划事件的示例,它创建一个规则,每 10 分钟调用一次指定的 Lambda 函数。 PermissionForEventsToInvokeLambda 资源授予 EventBridge 调用关联函数的权限。
"ScheduledRule": {
"Type": "AWS::Events::Rule",
"Properties": {
"Description": "ScheduledRule",
"ScheduleExpression": "rate(10 minutes)",
"State": "ENABLED",
"Targets": [{
"Arn": { "Fn::GetAtt": ["LambdaFunction", "Arn"] },
"Id": "TargetFunctionV1"
}]
}
},
"PermissionForEventsToInvokeLambda": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"FunctionName": { "Ref": "LambdaFunction" },
"Action": "lambda:InvokeFunction",
"Principal": "events.amazonaws.com",
"SourceArn": { "Fn::GetAtt": ["ScheduledRule", "Arn"] }
}
}
示例引用自AWS官方文档。
【讨论】:
是的,这是可能的。
AWS::Events::Rule 资源创建一个规则来匹配传入的 Amazon CloudWatch 事件 (CloudWatch Events) 事件并将它们路由到一个或多个目标进行处理。
这是示例 CloudFormation 代码段:
Type: AWS::Events::Rule
Properties:
Description: String
EventPattern: JSON object
Name: String
ScheduleExpression: String
State: String
Targets:
- Target
这里是official documentation,如果您还有其他问题。
【讨论】:
是的,@bhalothia 可以分享。请找到一篇能让您深入了解它的文章。
实际实施:
http://marcelog.github.io/articles/serverless_cloudwatch_event_cloudformation_template.html
详细记录:
希望对你有帮助。
【讨论】: