News for hackers. Stuff that matters.
Re:Going Serverless: Migrating an Express App to AWS API Gat... by pmontra on Tuesday October 11, 2016 @05:20AM (#12682741)
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?

Re:Going Serverless: Migrating an Express App to AWS API Gat... by brianwawok on Tuesday October 11, 2016 @09:01AM (#12683928)
If there are enough requests to keep your container up all the time, why are you using lambda??
Re:Going Serverless: Migrating an Express App to AWS API Gat... by pmontra on Tuesday October 11, 2016 @02:16PM (#12687027)
Exactly 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.