AWS CLI check if a lambda function exists

Question:

How do I do a one-time check if a lambda function exists via the CLI? I saw this function-exists option – https://docs.aws.amazon.com/cli/latest/reference/lambda/wait/function-exists.html

But it polls every second and returns a failure after 20 failed checks. I only want to check once and fail if it isn’t found. Is there a way to do that?

Answer:

You can check the exit code of get-function in bash. If the function does not exists it returns exit code 255 else it returns 0 on success.
e.g.


And you can use it like below:
(paste this in your terminal)

Leave a Reply