Ops/AWS
AWS Lamdba code - maintenance (node.js)
mkdir.chandler
2023. 11. 27. 00:00
반응형
AWS Lamdba code - maintenance (node.js)
점검 작업이 있을 경우 web 페이지로 접속하면 점검 안내 페이지 (혹은 이미지)를 보여주는 함수 세팅입니다.
exports.handler = (event, context, callback) => {
const request = event.Records[0].cf.request;
const headers = request.headers;
console.log('request_ip', request.clientIp);
// if (user_agent && user_agent.match(bot.toLowerCase()) && 1===0) {
if(request.clientIp != "192.168.1.50" && request.clientIp != "192.168.1.51") {
const response = {
status: '200',
statusDescription: 'OK',
headers: {
'cache-control': [{
key: 'Cache-Control',
value: 'no-cache, no-store, must-revalidate'
}],
'content-type': [{
key: 'Content-Type',
value: 'text/html'
}]
},
body: `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="https://mkdir-chandler.com/test.svg" />
<link rel="icon" type="image/png" sizes="32x32" href="https://mkdir-chandler.com/test-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="https://mkdir-chandler.com/test-16x16.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<title>NAEMO Creator</title>
<meta name="title" content="chandler" />
<meta name="author" content="mkdir" />
<meta name="robots" content="noindex, nofollow" />
</head>
<body style="margin: 0px; background-color: #2e2e2e">
<div id="shutdown" style="display: flex; justify-content: center; background: linear-gradient(180deg, #101010 0%, #2E2E2E 91.27%);min-height:100%;">
<picture>
<source media="(min-width: 1080px)" srcset="https://mkdir-chandler.com/test/shutdown_pc_v2.png" />
<source media="(min-width: 640px)" srcset="https://mkdir-chandler.com/test/shutdown_tablet_v2.png" />
<img src="https://mkdir-chandler.com/test/shutdown_mobile_v2.png" />
</picture>
</div>
</body>
</html>>`
};
console.log(response);
callback(null, response);
} else {
const uri = request.uri;
const host = request.headers.host[0].value;
// Check whether the URI is missing a file name.
if (uri.endsWith('/')) {
request.uri = `/index.html`;
}
// Check whether the URI is missing a file extension.
else if (!uri.includes('.')) {
request.uri = `/index.html`;
}
callback(null, request);
}
}
by mkdir-chandler
728x90
반응형