Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create cloudwatch event using cloudformation template?

I am using cloudwatch scheduled event to trigger my lambda function after specific time interval. I would like to use cloud-formation template to add this rule in cloudwatch. I have gone through cloudformation templates documentation but I am not able to find out way to configure events using cloud formation template. Can anyone please suggest how to implement it using cloud formation template.

I am using below template.

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "Provision environment specific",
  "Resources": {
    "lambdaScheduler": {
      "Type": "AWS::CloudWatch::Event",
      "Properties": {
        "detail-type": "Scheduled Event",
        "source": "aws.events",
        "name": "TEST_EVENT_10_MINS_RULE",
        "schedule-expression": "rate(5 minutes)"
      }
    }
  }
}

I am getting A client error (ValidationError) occurred when calling the ValidateTemplate operation: Template format error: Unrecognized resource type: AWS::CloudWatch::Event error message when I validate it using aws cli.

like image 575
Chetan Shirke Avatar asked Mar 01 '16 05:03

Chetan Shirke


People also ask

How do you make CloudWatch dashboard with CloudFormation?

The following steps are needed to create a CloudWatch dashboard with a custom resource. Create a CloudFormation template and add a Lambda-backed custom resource. Write the code creating, updating, and deleting a CloudWatch dashboard. Generate the JSON code describing the customized dashboard.

How do I enable CloudWatch logs for CloudFormation?

To enable CloudWatch logs for an ApiGateway Stage using CloudFormation for every method call to your API, you need to set the DataTraceEnabled property to true for all methods in your AWS::ApiGateway::Stage resource.

Does CloudFormation log to CloudWatch?

Use the AWS CloudFormation console to monitor the status of your AWS CloudFormation stack and detect if stack creation fails. The ArcGIS for Server web GIS templates also create logs, which are copied to a CloudWatch log group, to help you troubleshoot issues.


2 Answers

Adding CloudWatch event rules and schedules in now available, see https://aws.amazon.com/about-aws/whats-new/2016/04/amazon-cloudwatch-events-now-supported-in-aws-cloudformation-templates/

like image 194
user947661 Avatar answered Nov 10 '22 18:11

user947661


I am pretty sure the CloudWatch Event is yet to be exposed via the CloudFormation API. There is normally some lag between new features in AWS and them being implemented/exposed by the CloudFormation team.

Here is the list of resources currently available via CloudFormation. http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html

As one can see there is only one resource in the Cloudwatch namespace.

like image 37
TerryB Avatar answered Nov 10 '22 19:11

TerryB