amazon-web-servicesaws-lambdaamazon-cloudwatchamazon-cloudwatch-events

Trigger AWS Lambda function based on ELB Events


I need to trigger a Lambda function based on ELB Events. I need to create the cloud watch event rule for ELB creation, deletion, register instances, deregister the instances. Based on this my lambda function should get trigger and call the appropriate functions based on the events i received.

can any one help me to accomplish this.


Solution

  • The only CloudWatch Events supported by ELB are AWS API Call Using AWS. For this to work however, you have to create a CloudTrial trial for the region you are interested, i.e. where your ALB is located.

    Having CT trial enabled, you can then create a CW rule to catch ELB API events (e.g. for ALB they are listed here. For instance, the rule for CreateLoadBalancer and DeleteLoadBalancer would be:

    {
      "source": [
        "aws.elasticloadbalancing"
      ],
      "detail-type": [
        "AWS API Call via CloudTrail"
      ],
      "detail": {
        "eventSource": [
          "elasticloadbalancing.amazonaws.com"
        ],
        "eventName": [
          "CreateLoadBalancer",
          "DeleteLoadBalancer"
        ]
      }
    }