Reputation: 43
Have a lambda function in production, however I need to verify that upon an execution error, the configured cloudwatch alarm will successfully go to Alarm state. One option is to update the code and simply break it temporarily, but this isn't feasible.
Looking for an API call that can force an AWS Lambda to error without having to modify the actual code.
Upvotes: 1
Views: 1645
Reputation: 21510
As mentioned in other answers, there is no such API. There are however two ways I could imagine doing this:
Depending on your code, there might be a way by invoking your Lambda with faulty input data (see 1. above). Imagine a Go Lambda for a party planning service like the following:
func handleRequest(event MyEvent) error {
if event.NumberOfGuests < 2 {
return errors.New("there should be at least 2 guests")
}
return nil
}
func main() {
lambda.Start(handleRequest)
}
You could now invoke your Lambda with a payload like this:
{
"NumberOfGuests": 1
}
This would force the Lambda above to return an error.
Obviously, this highly depends on the code of your Lambda, but if you have code paths like this, all you need to do is to invoke the Lambda with input data that would run this code paths.
Upvotes: 0
Reputation: 238199
Looking for an API call that can force an AWS Lambda to error without having to modify the actual code.
This is no such call. But some lambda errors (specially runtime errors) can be "forced" without changing a source code. For example, but removing lambda permissions or changing function execution timeout.
You can also manually set your CW alarm into alarm state using set-alarm-state API call.
Upvotes: 1