aws-lambdaamazon-cloudwatchaws-ssmamazon-cloudwatch-events

Using wildcard in Custom event pattern for the event SSM parameter


I am having a lambda function that trigger a Jenkins job. I want to invoke this lambda when a new ssm parameter is added. I have added the below Custom event pattern in the cloud-watch event pattern.

{
  "source": [
    "aws.ssm"
  ],
  "detail-type": [
    "Parameter Store Change",
    "Parameter Store Policy Action"
  ],
  "detail": {
      "name": [
          "/dev/*"
        ],
        "operation": [
          "Create",
          "Update",
          "Delete",
          "LabelParameterVersion"
  ]

}

}

This means, the lambda need to trigger if i create a ssm parameter start with "/dev/anystring" But the lambda is not triggering if i provide wild card. Any suggestion on this.?


Solution

  • In this case you want to use the prefix comparison operator to filter based on values in the detail.name field.

    {
      "source": [
        "aws.ssm"
      ],
      "detail-type": [
        "Parameter Store Change",
        "Parameter Store Policy Action"
      ],
      "detail": {
        "name": [ { "prefix": "/dev/" } ],
        "operation": [
          "Create",
          "Update",
          "Delete",
          "LabelParameterVersion"
        ]
      }
    }
    

    For more details, see Reducing custom code by using advanced rules in Amazon EventBridge, especially example 2. All ATMs in New York City in the section Filtering events in a custom application.

    I am contributing this on behalf of my employer, Amazon. My contribution is licensed under the MIT license. See here for a more detailed explanation.