Skip to content

Commit

Permalink
Merge pull request #1678 from skhrapko-amplify/python_handle_base64_e…
Browse files Browse the repository at this point in the history
…ncoded_binary_response_from_aws_lambda_function

Python handle base64 encoded binary response from aws lambda function
  • Loading branch information
dherault authored Aug 17, 2024
2 parents 7a74692 + fd6b6d0 commit 8c260f0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/lambda/handler-runner/python-runner/invoke.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# copy/pasted entirely as is from:
# https://github.com/serverless/serverless/blob/v1.50.0/lib/plugins/aws/invokeLocal/invoke.py

import base64
import subprocess
import argparse
import json
Expand All @@ -10,6 +11,7 @@
from time import strftime, time
from importlib import import_module


class FakeLambdaContext(object):
def __init__(self, name='Fake', version='LATEST', timeout=6, **kwargs):
self.name = name
Expand Down Expand Up @@ -102,5 +104,9 @@ def log(self):
'__offline_payload__': result
}

if isinstance(result['body'], bytes):
data['__offline_payload__']['body'] = base64.b64encode(result['body']).decode('utf-8')
data['isBase64Encoded'] = True

sys.stdout.write(json.dumps(data))
sys.stdout.write('\n')

0 comments on commit 8c260f0

Please sign in to comment.