Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lambda - invoke as event, no return data to deserialize results in error #407

Closed
andrevdm opened this issue Sep 23, 2017 · 2 comments
Closed

Comments

@andrevdm
Copy link

When a lambda is invoked as an event (or DryRun) there is no data in the response body. Aeson then gets an empty string and fails with a SerializeError

E.g.

[Raw Response Body] {

}
[SerializeError] {
  service = Lambda
  status  = 202 Accepted
  message = Error in $: not enough input
  body    = Just 
}
aws01: SerializeError (SerializeError' {_serializeAbbrev = Abbrev "Lambda", _serializeStatus = Status {statusCode = 202, statusMessage = "Accepted"}, _serializeBody = Just "", _serializeMessage = "Error in $: not enough input"})

An AWSRequest instance like this avoids the issue

instance AWSRequest Invoke where
        type Rs Invoke = InvokeResponse
        request = postBody lambda
        response =
           (deserialise bodyDecode')
              (\ s h x ->
                 InvokeResponse' <$>
                   (h .#? "X-Amz-Function-Error") <*>
                     (h .#? "X-Amz-Log-Result")
                     <*> (pure (Just x))
                     <*> (pure (fromEnum s)))

          where
            bodyDecode' :: LazyByteString -> Either [Char] (HashMap Text Value)
            bodyDecode' bs =
              if bs == ""
              then Right $ Map.empty
              else eitherDecode' bs

@utdemir
Copy link
Contributor

utdemir commented Apr 29, 2018

I think this is a duplicate of #394 .

@brendanhay
Copy link
Owner

Closing as duplicate of #394

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants