Search code examples
boto3amazon-cloudwatch-eventsamazon-guardduty

Boto3 Guard Duty Put Target is having error while executing


I am creating boto3 for Cloudwatch rule and I have the following error when i use client.put_targets function.

https://boto3.amazonaws.com/v1/documentation/api/1.9.42/reference/services/events.html#CloudWatchEvents.Client.put_targets

raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the PutTargets operation: Invalid InputTemplate for target GuardDuty : [Source: (String)"null is in region null"; line: 1, column: 8].

Here is how the code looks like

client.put_targets(Rule='GuardDutyAlarm',
                   Targets=[{'Id': 'GuardDuty',
                             'Arn': 'arn:aws:sns:us-west-2:****:GuardDutyAlarmTeams',
                             'InputTransformer': {
                                 'InputPathsMap': {'severity': '$.detail.severity', 'region': '$.region'},
                                 'InputTemplate': "<severity> is in region <region>"}}])

Solution

  • We had a similar issue and we found how to fix it. You have to do something like that

    client.put_targets(Rule='GuardDutyAlarm',
                       Targets=[{'Id': 'GuardDuty',
                                 'Arn': 'arn:aws:sns:us-west-2:****:GuardDutyAlarmTeams',
                                 'InputTransformer': {
    'InputPathsMap': {'severity': '$.detail.severity', 'region': '$.region'},
    'InputTemplate': "\" <severity> is in region <region>  \"\n" }}])