This is part of my code in lambda to insert some values into an oracle database (from Amplify cli)
exports.handler = async (event, context, callback) => {
console.log(`EVENT: ${JSON.stringify(event)}`);
let conn;
try {
conn = await oracledb.getConnection(connAttr);
let result = await conn.execute(
"INSERT INTO employee VALUES (:name, :id, TO_TIMESTAMP(:date1, 'DD-MM-YYYY HH24:MI:SS'), TO_TIMESTAMP(:date2, 'DD-MM-YYYY HH24:MI:SS'))",
[req.body.name, req.body.discount, req.body.date1, req.body.date2],
{
name : req.body.name,
id : req.body.id,
date1 : req.body.date1,
date2 : req.body.date2
}
);
);
const response = {
statusCode: 200,
body: JSON.stringify(result),
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*",
"Access-Control-Allow-Methods": "*",
"Access-Control-Allow-Credentials" : "true",
"content-type": "application/json"
}
};
callback(null, response);
console.log('Query executed');
}
catch (err) {
const response = {
statusCode: 400,
body: JSON.stringify({message: err}),
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*",
"Access-Control-Allow-Methods": "*",
"Access-Control-Allow-Credentials" : "true",
"content-type": "application/json"
}
};
}
}
When I call the api connected, I get no response so I decided to use the aws console for some quick debugging and the code editor is giving me the warning: req is not defined; please fix or add /*globalreq*/
How can I fix this?
req. There is no such variable defined anywhere in your code. You probably need to be pulling those values out ofevent. You're going through the effort of logging theeventobject, but you aren't doing anything with it at all. - Mark B