-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda.js
More file actions
64 lines (58 loc) · 1.86 KB
/
lambda.js
File metadata and controls
64 lines (58 loc) · 1.86 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* After importing the VPC & EFS (in that order) via AWS Cloudformation Console,
* Copy & Paste the contents of this file into a new Lambda via the AWS Lambda
* console to test the EFS & VPC.
*/
'use strict';
const exec = require('child_process').exec;
const fs = require('fs');
const ping = function (url) {
return new Promise((resolve, reject) => {
const lib = url.startsWith('https') ? require('https') : require('http');
const request = lib.get(url, (response) => {
resolve(response.statusCode);
});
request.on('error', (err) => reject(err))
})
};
exports.handler = async (event, context) => {
console.log('@ EVENT @', event);
console.log('@ CONTEXT @', context);
const kMNT_PATH = event.mountPath;
try {
const content = await ping( 'https://www.google.com' );
console.log(
content === 200
? 'SUCCESS! You have access to the internet'
: 'DOH! You do not have internet access',
`HTTP Reponse code ${content}`
);
return {
statusCode: 200,
body: JSON.stringify((() => {
try {
fs.writeFileSync(`${kMNT_PATH}/test.txt`, 'Testing 1,2,3', 'utf-8');
return {
exists : fs.existsSync(kMNT_PATH),
isdir : fs.lstatSync(kMNT_PATH).isDirectory(),
readdir : fs.readdirSync(kMNT_PATH)
};
}
catch (e) {
return {
error: e.toString()
}
}
})()),
};
}
catch (e) {
console.error(e);
return {
statusCode: 500,
body: JSON.stringify({
message: e.toString(),
}),
};
}
}