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 with iInvocationType Event tries to parse a non-existing response #394

Closed
koterpillar opened this issue Jul 25, 2017 · 3 comments
Assignees
Labels

Comments

@koterpillar
Copy link
Contributor

send $ invoke lambdaName mempty & iInvocationType .~ Just Event

This produces the following logs:

[Client Request] {
host = lambda.SNIP.amazonaws.com:443
secure = True
method = POST
target = Nothing
timeout = ResponseTimeoutMicro 70000000
redirects = 0
path = /2015-03-31/functions/SNIP/invocations
query = 
headers = host: lambda.SNIP.amazonaws.com; x-amz-date: SNIP; x-amz-content-sha256: SNIP; x-amz-security-token: SNIP; x-amz-invocation-type: Event; authorization: AWS4-HMAC-SHA256 Credential=SNIP/SNIP/ap-southeast-2/lambda/aws4_request, SignedHeaders=host;x-amz-content-sha256;x-amz-date;x-amz-invocation-type;x-amz-security-token, Signature=SNIP
body = {}
}
[Client Response] {
status = 202 Accepted
headers = content-type: ; date: SNIP; x-amzn-remapped-content-length: 0; x-amzn-requestid: SNIP; x-amzn-trace-id: root=SNIP;sampled=0; content-length: 0; connection: keep-alive
}

Note that the response body is empty, as specified in http://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html. Amazonka then throws:

[Raw Response Body]
{}

[SerializeError] {
service = Lambda
status = 202 Accepted
message = Error in $: not enough input
body = Just 
}
@utdemir
Copy link
Contributor

utdemir commented May 14, 2018

@brendanhay I was also hit by this issue. I guess there might not be an easy fix if the AWS's documentation is lacking. Do you know any workaround for that?

I was able to run it by creating a newtype wrapper around Invoke and implemented AWSRequest instance manually, but it is less than ideal since I can not construct InvokeResponse, because the constructor is hidden.

@brendanhay
Copy link
Owner

brendanhay commented May 14, 2018

Looking at the Lambda service definition for Invoke - my interpretation is that the response data structure will be populated from the status code, headers, and the empty body - the {} in the response above is unfortunately coming from the pretty printer, and is not an empty object.

The parser attempts to parse the body into Maybe (HashMap Text Value), which fails as follows:

> eitherDecode "" :: Either String (HashMap Text Value)
Left "Error in $: not enough input"

🤦‍♂️

Fixable in the library proper - an empty response should result in a Nothing since it has a type of Maybe ...), there just needs to be a check for an empty body added to the Network.AWS.Response deserialization functions at a guess. I'm working on a new release now and will try to get this released at the same time.

@brendanhay
Copy link
Owner

I added a test for the updated generation logic which will be released as part of 1.6.0:

stack test --fast amazonka-lambda
  fixtures
    response
      InvokeResponse: FAIL
        src/Test/AWS/Assert.hs:17:
        SerializeError (SerializeError'
            { _serializeAbbrev = Abbrev "Lambda"
            , _serializeStatus = Status {statusCode = 200, statusMessage = "OK"}
            , _serializeBody = Just ""
            , _serializeMessage = "Error in $: not enough input"
            })

Versus:

  fixtures
    response
      InvokeResponse: OK

This is a breaking change as the response body will no longer be parsed into a HashMap Text Value and instead returns a raw ByteString - less convenient, but also less magic based on service definition subtleties.

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

No branches or pull requests

3 participants