-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (30 loc) · 1.02 KB
/
index.js
File metadata and controls
32 lines (30 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const fs = require('fs');
exports.initializer = (context, callback) => {
console.log('initializing');
callback(null, '');
};
module.exports.handler = function (event, context, callback) {
console.log(event.toString());
console.log(JSON.stringify(context));
const functionName = context.function.name;
console.log(`functionName: ${functionName}`);
const nasDir = `/mnt/${functionName}`;
const ossDir = `/mnt/oss_${functionName}`;
const nasFile = `${nasDir}/test.txt`;
const ossFile = `${ossDir}/test.txt`;
if (fs.existsSync(nasFile)) {
const content = fs.readFileSync(nasFile, 'utf8');
console.log(`nasFile content: ${content}`);
} else {
fs.writeFileSync(nasFile, 'hello world');
console.log(`nasFile created: ${nasFile}`);
}
if (fs.existsSync(ossFile)) {
const content = fs.readFileSync(ossFile, 'utf8');
console.log(`ossFile content: ${content}`);
} else {
fs.writeFileSync(ossFile, 'hello world');
console.log(`ossFile created: ${ossFile}`);
}
callback(null, 'hello world');
};