API Gateway to Lambda function Form Data issue

Viewed 24

I am setting up a Lambda function that will be triggered by an API Gateway V2 endpoint.

There will be Form Data sent through however when it reaches the lambda function it is in a strange way.

The Event Body is base64 encoded. So I have to decode it.

event = base64.b64decode(event['body'])

b'----------------------------809582309949071767113581\r\nContent-Disposition: form-data; name="command"\r\n\r\n\r\n----------------------------809582309949071767113581\r\nContent-Disposition: form-data; name="text"\r\n\r\this is the text \r\n----------------------------809582309949071767113581\r\nContent-Disposition: form-data; name="token"\r\n\r\nXXXXXXXXXXXXXXXX\r\n----------------------------809582309949071767113581\r\nContent-Disposition: form-data; name="user_name"\r\n\r\nkim_d\r\n----------------------------809582309949071767113581\r\nContent-Disposition: form-data; name="user_id"\r\n\r\n14239\r\n----------------------------809582309949071767113581\r\nContent-Disposition: form-data; name="response_url"\r\n\r\nhttp:"//example.com\r\n----------------------------809582309949071767113581--\r\n'

Am I missing a setting somewhere?

1 Answers

No you are not missing anything. That's how the data gets to lambda from API Gateway, after receiving the arguments upon getting triggered you have to decode and use it.

I was facing the same challenge when I tried to read data from a file and send it to lambda through API gateway. I was unable to any other way apart from sending the data as byte string.

Not Sure what is the necessity to design it this way.

Related