1

When invoking an Amazon Web Service Lambda function from the ruby SDK is there any way of determining if the function encountered a context.fail?

ie. if I invoke an AWS Lambda function like this in the ruby sdk:

    resp = LAMBDA.invoke({
                  function_name: "cropSomeStuff", 
                  invocation_type: "RequestResponse", 
                  log_type: "Tail", # accepts None, Tail
                  payload: payload.to_json
              })

and the function encounters a context.fail(err)

resp.successful? still return true. I can look at the logs with Base64.decode64(resp.log_result), however, I don't see an easy way to programmatically tell the function invocation failed at the ruby level.

2 Answers 2

1

The response object should include both a response code (#status_code) and an error string (#function_error). You can use either of these to detect an error:

Using #function_error:

unless resp.function_error.empty?
  # An error occured
end

Using #status_code:

unless resp.status_code.between?(200, 299)
  # An error occured
end

(Note that the documentation only specifies success as being "within the 200 range.")

There's no #successful? method in the documentation, so not sure where that is coming from.

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

2 Comments

It returns 200 regardless of wether it failed or not and the function_error only says that it's been handled.
Handled and Unhandled would both mean there was an error, but you'll likely need to parse the payload if you need specifics.
0

It appears as though parsing the resp.payload is the best course of action, if there is an error, the only key in that response dictionary will be errorMessage. 200 is returns so long as the function was invoked, and it's better to deal with the cases by looking at the returned result passed to a context.fail.

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.