[英]How to create cloudwatch event using cloudformation template?
[英]Can I create a CloudWatch scheduled event in CloudFormation template?
我知道我可以通過 AWS 控制台創建計划的 Cloud Watch 事件:
有沒有辦法在 Cloud Formation 模板中聲明類似的事件?
下面是在 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 Events (CloudWatch Events) 事件並將它們路由到一個或多個目標進行處理。
這是示例 CloudFormation 代碼段:
Type: AWS::Events::Rule
Properties:
Description: String
EventPattern: JSON object
Name: String
ScheduleExpression: String
State: String
Targets:
- Target
這是官方文檔,如果您有更多問題。
是的,這可能是@bhalothia 分享的。 請找到一篇文章,讓您深入了解它。
實際實施:
http://marcelog.github.io/articles/serverless_cloudwatch_event_cloudformation_template.html
詳細文檔:
我希望這可以幫助你。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.