3

I have on Lambda function which input is

input_str = "<html><body><h1>Title</h1><Hello World></body></html>"
input_base64 = base64.b64encode(bytes(input_str, 'utf-8'))
payload = {"html_base64" : input_base64} 

here input_base64 is bytes type variable

I am invoking this Lambda function from other Lambda function, but I am not able pass this payload

invoke_response = lambda_client.invoke(FunctionName="vivek_05",
                                       InvocationType='RequestResponse',
                                       Payload=payload
                                       )

Getting following exception:

  "errorMessage": "Parameter validation failed:\nInvalid type for parameter Payload, value: {'html_base64': b'PGh0bWw+PGJvZHk+PGgxPlRpdGxlPC9oMT48SGVsbG8gV29ybGQ+PC9ib2R5PjwvaHRtbD4='}, type: <class 'dict'>, valid types: <class 'bytes'>, <class 'bytearray'>, file-like object",

Can you help me?

2
  • 1
    Please try Payload=json.dumps(payload). Commented Oct 7, 2018 at 11:16
  • @IftekharDani: Object of type 'bytes' is not JSON serializable Commented Oct 7, 2018 at 14:25

2 Answers 2

4

You can encode and decode bytes using this example. This might help you.

Encode by :

Payload=json.dumps({
            'imageName': image_name,
            'imageBytes': base64.b85encode(image_bytes).decode('utf-8'),
    })

You can decode by :

let imageBytes = base64.b85decode(event['imageBytes']);
let imageName = event['imageName'];
Sign up to request clarification or add additional context in comments.

Comments

2

Since the data is a binary or bytes, you need to convert into string before sending it across.

input_base64str = str(input_base64,'utf-8')

Should fix it.

When you convert back, change it to bytes and pass it to base64 decoder.

input_base64 = bytes(input_base64str, 'utf-8')

Hope it helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.