


The repo contains a test image rainbow-small.jpg and a test text file multiline.txt.įor both examples, the HTTP API endpoint received an unaltered binary file, using the -data-binary flag. It also allows uploading text and rendering it to an image before applying noise to it The Lambda function POST path accepts images and adds some noise.
SENDING BASE64 ENCODING WITH JSON HOW TO
The following examples show how to handle both text and binary media types on the same API. The HTTP API endpoint has converted the base64 encoded string back into text. The following response from Lambda results in the corresponding text “ base64 encoded”: ?demo64Flag=1" -H 'Accept: image/unknown' Ī Lambda function can inspect the isBase64Encoded flag and reverse the encoding to obtain the original data.įor the response path, API Gateway inspects the isBase64Encoding flag returned from Lambda. When passing a binary object: curl -X POST -H 'content-type: image/jpeg' -data-binary $ECHO_JSON_API | jq. When using curl to pass a plaintext object: curl -X POST -H 'content-type: text/plain' -data-binary "Hello World" $ECHO_JSON_API | jq. The HTTP API Lambda integration automatically infers the need for encoding based on the content-type header passed with the request. Binary and non-binary data is passed to a Lambda function as a string in a JSON object.

In this post, I show how to use HTTP APIs and AWS Lambda to build an API that accepts and returns either text or images.ĪPI Gateway’s base64-encoding unifies the handling of text and binary data in Lambda. It supports a new payload format version and infers encoding based on request and response formats. API Gateway HTTP APIs makes it easier to work with both binary and text media types. This post is written by Rudolf Potucek, Startup Solutions Architect.Īmazon API Gateway REST APIs have supported binary data since 2016.
