How do you write to the file system of an aws lambda instance?

前端 未结 2 1288
既然无缘
既然无缘 2021-02-05 00:42

I am unsuccessfully trying to write to the file system of an aws lambda instance. The docs say that a standard lambda instance has 512mb of space available at /tmp/

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-05 01:19

    Modifying your code into the Lambda template worked for me. I think you need to assign a function to exports.handler and call the appropriate context.succeed() or context.fail() method. Otherwise, you just get generic errors.

    var fs = require("fs");
    
    exports.handler = function(event, context) {
        fs.writeFile("/tmp/test.txt", "testing", function (err) {
            if (err) {
                context.fail("writeFile failed: " + err);
            } else {
                context.succeed("writeFile succeeded");
            }
        });
    };
    

提交回复
热议问题