Returning binary body and http headers from an AWS lambda through API gateway

前端 未结 3 1953

I have a lambda that needs to return a binary object and some http headers (e.g. content-type) through an api gateway (using lambda integration) OR redirect to another URL.

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-06 22:11

    I recently got this working after facing a similar problem.

    In my case, I was missing two things:

    First, I needed to change the list of types AWS will send to the upstream in the "Accept" header"

    "x-amazon-apigateway-binary-media-types" : [
      "image/jpeg"
    ]
    

    Secondly, I needed to set the Integration Response to "Convert to binary (if needed)":

    "contentHandling": "CONVERT_TO_BINARY"
    

    See this answer for the details, and sample config.

    I also found that I wasn't being patient enough. Whenever I deployed the API, I was checking immediately, instead of waiting a few minutes for the changes to propagate.

提交回复
热议问题