我没有成功写入aws lambda实例的文件系统. 文档说标准的lambda实例有512mb的可用空间/tmp/.但是,在本地计算机上运行的以下代码在lambda实例上根本不起作用:
var fs = require('fs');
fs.writeFile("/tmp/test.txt", "testing", function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
Run Code Online (Sandbox Code Playgroud)
匿名回调函数中的代码永远不会在lambda实例上调用.这有什么成功的吗?非常感谢你的帮助.
这可能是一个相关的问题.是否有可能在s3代码和我正在尝试用fs回调函数之间发生某种冲突?下面的代码是当前正在运行的代码.
console.log('Loading function');
var aws = require('aws-sdk');
var s3 = new aws.S3({ apiVersion: '2006-03-01' });
var fs = require('fs');
exports.handler = function(event, context) {
//console.log('Received event:', JSON.stringify(event, null, 2));
// Get the object from the event and show its content type
var bucket = event.Records[0].s3.bucket.name;
var key = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, ' '));
var params …Run Code Online (Sandbox Code Playgroud) 我正在尝试将带有用户身份验证数据的文件写入磁盘.为实现这一点,我写了以下函数:
function writeAuthFile(data, success, fail) {
var fs = require('fs');
fs.writeFile('auth.json', JSON.stringify(data), function(error) {
if(error) {
console.log('[write auth]: ' + err);
if (fail)
fail(error);
} else {
console.log('[write auth]: success');
if (success)
success();
}
});
}
Run Code Online (Sandbox Code Playgroud)
但它从不称呼回调.我查看了nodeJS文档,fs似乎一切都结束了.所有其他异步执行似乎都已停止.
这是我第一次在nodeJS中开发一些认真的东西,所以我在这个环境中的经验并不是那么多.