3 ms·
DynamoDB is not immune from that problem. There is no way out: if the container is terminated the connection goes down. The key is not making Lambda stop and rm
by pmontra 10y ago
DynamoDB is not immune from that problem. There is no way out: if the container is terminated the connection goes down. The key is not making Lambda stop and rm the container (in docker terms). If there are enough requests the container is reused and the connection stays up, but you must initialize it outside the function. An example with 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?
- brianwawok 10y agoIf there are enough requests to keep your container up all the time, why are you using lambda??
- pmontra 10y agoExactly what I was asking but I didn't do the math. Maybe it's OK for burst shaped traffic. The first request pays a toll, the others are quick.