phpaws-lambdaaws-api-gatewayaws-lambda-containers

AWS Lambda with API Gateway Proxy using PHP code deployed using docker el2 runtime returns base64 instead of binary image


So we have a legacy code which returns a gif image, running on-prem. Recently decided to, migrate the same aws lambda using al2 docker image. I've used the aws sample code on github and modified the boostrap to suit my needs. API Gateway is used as the proxy in front of the lambda. I have followed the exact pattern given here, encoding as base64 and isBase64Encoded as true and content-type as image/gif etc. Testing locally and checking the Cloudwatch logs, I can clearly see the base64 and the json formatted correctly. But on the chrome browser the image is not displayed, and when I saved the preview of the image dot using chrome's devtools it's in Base64. API Gateway is not converting it back to binary. I ma using the APIGW HTTP api. Note: I've successfully used Bref and it works fine, but our Infosec and devops wants to use docker images from aws. I thought I'll give it a try - came this far, but stuck at this frustrating issue.

The PHP sample code is below (I am not a php expert, it's the first time I am working on PHP code, but lots of experience in Java, C#, node etc so please excuse for any mistakes):

1. Code which converts the binary to base64

Code which converts the binary to base64

2. Part of the bootstrap code

Part of the bootstrap code

3. Cloudwatch logs

Cloudwatch logs

4. The Chrome response headers

The Chrome response headers


Solution

  • Ok I found the issue. It was an upper case in the IsBase64Encoded. After changing it to isBase64Encoded (lower case i), it worked. Never thought it was case sensitive!