I have a lambda function which does return audio buffer in response, when I invoke lambda from code, it works fine but when I call lambda behind ALB ,I get an error -
502 Bad Gateway
// Lambda function handler
'use strict';
module.exports.handler = async (event, context) => {
// ALB expects following response format
// see: https://docs.aws.amazon.com/lambda/latest/dg/services-alb.html
const response = {
headers: {
'Access-Control-Allow-Origin': '*',
'Content-Type': 'application/json',
},
isBase64Encoded: true,
statusCode: 200,
statusDescription: '200 OK',
};
// getting buffer from backend api
const answer = 'This is my audio buffer'.toString('base64');
return {
response,
body: JSON.stringify({
id: 123,
myBuffer: answer,
}),
};
};
Your return
param doesn't seem to be correct according to JSON format.
What about this?
...
const answer = 'This is my audio buffer'.toString('base64');
response.body = JSON.stringify({
id: 123,
myBuffer: answer
});
return response;
};