Tibberzz
Tibberzz

Reputation: 551

Cloudformation Cloudwatch InputTemplate Formatting

I'm attempting to use a cloudformation template to create a cloudwatch event rule that matches a glue event and targets an SNS topic to send a message to, I can create it in the cloudwatch console, but not via a cloud watch template. Here is my event rule:

NotifyEventRule:
  Type: AWS::Events::Rule
  Properties:
    Name: JobNotifyEvent
    Description: Notification event on job status change.
    EventPattern:
      source:
        - aws.glue
      account:
        - !Ref AWS::AccountId
      detail-type:
        - Glue Job State Change
      detail:
        jobName:
          - !Ref GlueJobName
    Targets:
        - 
          Arn: 
              Ref: "JobNotificationTopic"
          Id: 
              Ref: "JobNotificationTopicName"
          InputTransformer:
            InputTemplate: "Job finished in the following state: <state>."
            InputPathsMap: 
              state: "$.detail.state"

The problem is with InputTemplate. The error I get is:

Invalid InputTemplate for target JobNotificationTopic : [Source: (String)"Job finished in the following state: null."; line: 1, column: 10]. (Service: AmazonCloudWatchEvents; Status Code: 400; Error Code: ValidationException; Request ID: 12345678...)

It seems like <state> may be the problem.

Upvotes: 9

Views: 10324

Answers (3)

lznt
lznt

Reputation: 2576

I believe the issue is that the InputTemplate is not a valid JSON. See: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-inputtransformer.html#cfn-events-rule-inputtransformer-inputtemplate

The InputTemplate must be valid JSON.

Upvotes: 1

user2821716
user2821716

Reputation: 51

This is not an issue with YAML format as you get the same error using JSON.

The InputTemplate must be a string inside AWS:

InputTemplate=
                "\"The Pipeline <pipeline> Started\""

This AWS Developer Forum topic gave me the answer: https://forums.aws.amazon.com/thread.jspa?messageID=798687

Upvotes: 5

Vikyol
Vikyol

Reputation: 5625

The syntax for InputTemplate is for some reason quite strict in CloudFormation. It is of type string but it does not accept any form of valid YAML string.

In your case, you should use YAML Literal Block Scalar, |, before the input string.

InputTransformer:
    InputPathsMap: 
        state: "$.detail.state"
    InputTemplate: |
        "Job finished in the following state: <state>."

If the input string is multiline, each line has to be enclosed in double quotes.

InputTransformer:
    InputPathsMap:
        state: $.detail.state
        name: $.detail.name
    InputTemplate: |
        "Job <name> has just been run."
        "Job finished in the following state: <state>."

Just to note that your string uses plain flow scalars, which is picky about the : character. Colon cannot appear before a space or newline. See Yaml multiline for further details. However, as I pointed out most of these YAML multiline rules does not apply to InputTemplate.

Upvotes: 25

Related Questions