簡體   English   中英

我可以在 CloudFormation 模板中創建 CloudWatch 計划事件嗎?

[英]Can I create a CloudWatch scheduled event in CloudFormation template?

我知道我可以通過 AWS 控制台創建計划的 Cloud Watch 事件:

https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/Create-CloudWatch-Events-Scheduled-Rule.html

有沒有辦法在 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

詳細文檔:

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html

我希望這可以幫助你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM