Sending an image asynchronously to api-gateway

Viewed 16

I'm trying to POST an image from a user to api-gateway asynchronously. the payload I'm sending looks like

{
    "headers":{
       "content-type":"image/jpeg"
     }
    "body": "image".decode('utf-8'),
}

When I test locally I get the proper response. But when I send the image via api-gateway I get a 200 and nothing gets returned, or if I send it testing the method request I get {"message": "Unsupported Media Type"}

I've went to settings and made the binary media type */* to accept all content-types and I've added the X-Amz-Invocation-Type to the integration request to handle the asynchronous part. I also added error handling for my integration and method responses but I'm still getting 200.

Integration response: enter image description here

Method response: enter image description here

Not sure what I'm missing here.

EDIT So when you're doing a non-proxy lambda integration you need to specify a model for the requests so the api-gateway knows how to format that incoming request going into the lambda function.

my Model here:

{
    "$schema": "https://json-schema.org/draft/2019-09/schema",
    "title": "UserPicture",
    "type": "object",
    "properties": {
        "body": {"type": "string"}
    }
}

for anyone else struggling to make a model just use this pass in your json and it'll build the schema from there. It's really extra and will add some fields that aws doesn't like but it speeds the process up.

Then I created a mapping template in integration requests:

#set($inputRoot = $input.path('$'))
{
  "body" : "$inputRoot.body"
}

But now it looks like my problem is the image I'm sending. Error from api-gateway:

{"message": "Could not parse request body into json: Could not parse payload into json: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value\n at

The base64encoded image is really long.

0 Answers
Related