by Everhusk · 10y ago · 0 comments
It's a pretty big deal that every single API call requires a new database connection. The only solutions I've seen so far are to run a separate app to interface with the database, or moving the connection outside of the handler (which still has issues).
Am I missing something or is everyone just really happy to use DynamoDB?
const AWS = require("aws-sdk");
const docClient = new AWS.DynamoDB.DocumentClient();
module.exports.theFunction = (event, context, callback) => {
var params = {
TableName: "table",
Item: {
"attribute": "value"
}
};
docClient.put(params, function (err, data) {
...
});
callback(null, {...});
};
I didn't try but it should work with any other db.However, is Lambda cost effective for services with the amount of requests required to have their containers almost never terminated?
Maybe it's OK for burst shaped traffic. The first request pays a toll, the others are quick.
Stop by the Zappa slack if you want to explore this in more detail! https://slack.zappa.io It could always use more investigation, but there are quite a few Zappa users at extremely high loads now without any issues.
MySQL has a really fast server side connection pool.
Also adds a fairly big server load. I suspect if a given MySQL instance supports 1000 long lived connections.. it would only support 100-200 connections that are closing every request. (Have not benchmarked this side, would be curious to see )