[英]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.