1

I have an AWS lambda function that provides configuration objects. Whenever this lambda function is updated(i.e deployed again), I need to trigger another lambda function, that detects changes in those config objects and takes some action. How do I monitor this lambda deployment, which cloud watch event do I need to subscribe to?

2 Answers 2

5

I assume that your lambda deployments are not managed by CodeDeploy. If so, I would recommend looking into creating a CloudTrial trial.

Once CT trial is created with default settings, it will monitor all management API calls to your lambda function. One of them is UpdateFunctionCode. Thus you can create a CloudWatch rule for AWS API Call via CloudTrail. The rule would be triggered on the function update API call.

Example of such a rule:

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

Then you can trigger a second lambda, based on the captured update event of the first function.

Sign up to request clarification or add additional context in comments.

3 Comments

Yes, lambda deployments are done using node serverless package. I will try the method you have mentioned here.Thanks a lot.
Hi Marcin, Where do I specify the particular function name in the rule?
@pras007 You would have to check the structure of the event object for UpdateFunctionCode, and modify based on this. For example for the DeleteFunction, the function name is in "requestParameters": { "functionName": "basic-node-task" }. Sadly, I don't know what is the event structure for UpdateFunctionCode. You can run it once as it is and print out the event to cloudwatch logs in lambda function, and check there.
1

Based on @Marcin's suggestion, used console log to print the event. The below rule helped to filter a specific function;

{
  "source": [
    "aws.lambda"
  ],
  "detail-type": [
    "AWS API Call via CloudTrail"
  ],
  "detail": {
    "eventSource": [
      "lambda.amazonaws.com"
    ],
    "eventName": [
      "UpdateFunctionCode20150331v2"
    ],
    "responseElements": {
      "functionName": [
        "myFunction"
      ]
    }
  }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.