简体   繁体   English

我可以在 CloudFormation 模板中创建 CloudWatch 计划事件吗?

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

I know I can create a Scheduled Cloud Watch event by means of AWS Console:我知道我可以通过 AWS 控制台创建计划的 Cloud Watch 事件:

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

Is there a way to declare the similar event in Cloud Formation template?有没有办法在 Cloud Formation 模板中声明类似的事件?

Below is the example to create a scheduled event in cloudwatch, It creates a rule that invokes the specified Lambda function every 10 minutes.下面是在 cloudwatch 中创建计划事件的示例,它创建了一个规则,每 10 分钟调用一次指定的 Lambda 函数。 The PermissionForEventsToInvokeLambda resource grants EventBridge permission to invoke the associated function. 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"] }
  }
}

The example is referenced from AWS official documentation.该示例引用自 AWS 官方文档。

Yes, it's possible.是的,这是可能的。

The AWS::Events::Rule resource creates a rule that matches incoming Amazon CloudWatch Events (CloudWatch Events) events and routes them to one or more targets for processing. AWS::Events::Rule资源创建了一个规则来匹配传入的 Amazon CloudWatch Events (CloudWatch Events) 事件并将它们路由到一个或多个目标进行处理。

Here's the sample CloudFormation Snippet:这是示例 CloudFormation 代码段:

Type: AWS::Events::Rule
Properties: 
  Description: String
  EventPattern: JSON object
  Name: String
  ScheduleExpression: String
  State: String
  Targets:
    - Target

Here's the official documentation , if you have more questions.这是官方文档,如果您有更多问题。

Yes, It's possible as share by @bhalothia.是的,这可能是@bhalothia 分享的。 Please find an article which will give you a deep dive into it.请找到一篇文章,让您深入了解它。

Practical Implementation:实际实施:

http://marcelog.github.io/articles/serverless_cloudwatch_event_cloudformation_template.html http://marcelog.github.io/articles/serverless_cloudwatch_event_cloudformation_template.html

Detail dodcumentation:详细文档:

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

I hope this helps you.我希望这可以帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 cloudformation 模板创建 cloudwatch 事件? - How to create cloudwatch event using cloudformation template? 如何为特定 CloudFormation 堆栈创建“aws.cloudformation”CloudWatch 事件类型? - How can I create an "aws.cloudformation" CloudWatch event type for a specific CloudFormation stack? 我可以在预定的Amazon CloudWatch Event中发布到SQS吗? - Can I publish to SQS in scheduled Amazon CloudWatch Event? 使用 Cloudformation 为 EBS 快照创建 Cloudwatch 事件 - Create Cloudwatch Event for EBS Snapshot using Cloudformation 如何使用 lambda function 目标为 cloudwatch 事件制作 cloudformation 模板? - How do I make a cloudformation template for a cloudwatch event with a lambda function target? cloudwatch事件触发cloudformation - cloudwatch event trigger cloudformation 如何在Cloudformation模板参数中创建IAM角色下拉列表 - How can I create IAM Role Dropdown in Cloudformation Template Parameters 如何在 CloudWatch 中查看 AWS CloudFormation 日志? - How can I see AWS CloudFormation logs in CloudWatch? CloudFormation 模板中具有过滤模式的 cloudwatch 指标过滤器 - cloudwatch metric filter with filter pattern in CloudFormation template 将现有 AWS CloudWatch 警报导出到 CloudFormation 模板 - Export existing AWS CloudWatch alarms to CloudFormation template
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM