AWS CLI check if a lambda function exists

Viewed 4034
1 Answers

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.

aws lambda get-function --function-name my_lambda
echo $?

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

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
Related