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.
1 2 3 |
aws lambda get-function --function-name my_lambda echo $? |
And you can use it like below:
(paste this in your terminal)
1 2 3 4 5 6 7 8 9 10 11 |
function does_lambda_exist() { aws lambda get-function --function-name $1 > /dev/null 2>&1 if [ 0 -eq $? ]; then echo "Lambda '$1' exists" else echo "Lambda '$1' does not exist" fi } does_lambda_exist my_lambda_fn_name |