Binary requests and responses
AWS Lambda is only used for executing code. Serving assets via PHP does not make sense as this would be a waste of resources and money.
Deploying a website with assets (e.g. CSS, JavaScript, images) is covered in the “Websites” documentation.
In some cases however, you want to serve images (or other assets) via PHP. One example would be if you served generated images or PDFs via PHP.
Bref returns binary responses (images, PDF, files…) as is: when a response body is not text (UTF-8), Bref encodes it in base64, which API Gateway, Function URLs and ALBs decode. There is nothing to configure.
If you use API Gateway v1 REST APIs (http events instead of httpApi), set binaryMediaTypes, otherwise API Gateway does not decode binary requests and responses (clients receive the base64 text):
provider:
# ...
apiGateway:
binaryMediaTypes:
- '*/*'Be aware that the max upload and download size is 6MB and because base64 encoding adds a ~33% overhead to the response, downloads are limited to ~4.5MB in size. For larger files, use AWS S3. An example is available in Serverless Visually Explained .