Hello everyone,
I started playing with aws lambda since 2 days, everything is new for me there (nodejs, API gateway, lambda functions).
My first idea was to take some data from my database table and return it to a web page. So I created lambda function that return me the values that I want in test phase, but when I pass by the API Gateway I’m getting the malformed lambda proxy.
I’m not sure but it’s probably because of my data’s type that my API doesn’t work.
Here’s my function code :
‘use strict’;
const AWS = require(‘aws-sdk’);
const sql = require(‘mssql’);
exports.handler = (event, context, callback) => {
const config =
{
user: ‘xxxx’,
password: ‘xxxx’,
server: ‘xxx.xxx.xxx.xxx’,
database: ‘test’,
};
const done = function (err, res)
{
callback(null, {
statusCode: err ? ‘400’ : ‘200’,
body: err ? err : res,
headers: {
‘Content-Type’: ‘application/json’,
‘Access-Control-Allow-Origin’: ‘*’
}
});
};
var path = event.pathParameters.proxy;
if (path === ‘conversations’)
{
sql.connect(config, (err) =>
{
if(err)
{
console.log(err);
callback(err);
}
else
{
const req = new sql.Request();
req.query('SELECT * FROM prsn',(error, result) =>
{
if(error)
{
console.log(error);
callback(error);
}
else
{
callback(null, result.recordset);
sql.close();
}
});
}
});
}
else
{
done('No cases hit');
}
};
Someone can show me the right way to how to deal with that error please ?
Related discussions:
- AWS Cost Updates - 2026-10-23
- Every etl connector we built in aws glue breaks when saas vendors change their api
- New API Gateway timeout increase >29sec. Not working?
- Serverless with HIPAA and VPC
- All the AWS best practices in one Claude Code / Codex skill, so your agent doesn’t rely on stale memory or crawl docs every time