Notice
Recent Posts
Recent Comments
Link
투케이2K
490. (javaScript) 자바스크립트 describeLogGroups 사용해 AWS CloudWatchLogs 로그 그룹 목록 리스트 조회 본문
JavaScript
490. (javaScript) 자바스크립트 describeLogGroups 사용해 AWS CloudWatchLogs 로그 그룹 목록 리스트 조회
투케이2K 2026. 2. 19. 19:52728x90
반응형
[개발 환경 설정]
개발 툴 : Edit++
개발 언어 : JavaScript

[소스 코드]
-----------------------------------------------------------------------------------------
[사전 설명 및 설정 사항]
-----------------------------------------------------------------------------------------
- 개발 환경 : Web
- 개발 기술 : JavaScript (자바스크립트) / AWS / CloudWatchLogs / describeLogGroups
- 사전) AWS CloudWatchLogs 간다 설명 정리 :
>> Aws CloudWatch 는 Amazon Web Services (AWS) 리소스 및 AWS에서 실행되는 애플리케이션을 실시간으로 모니터링 할 수 있는 서비스입니다
>> Aws CloudWatch 를 사용하여 리소스 및 애플리케이션에 대해 측정할 수 있는 변수인 지표를 수집하고 추적할 수 있습니다
>> Aws CloudWatch 액세스 방법 :
- Amazon CloudWatch 콘솔 : https://console.aws.amazon.com/cloudwatch/
- AWS CLI : 자세한 내용은 AWS Command Line Interface 사용 설명서의 AWS Command Line Interface 설정 단원을 참조하세요.
- CloudWatch API : 자세한 내용은 Amazon CloudWatch API 참조 단원을 참조하세요.
- AWS SDK : 자세한 내용은 Amazon Web Services용 도구를 참조하세요.
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
[소스 코드]
-----------------------------------------------------------------------------------------
<!DOCTYPE HTML>
<html lang="ko">
<head>
<title>javaScriptTest</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- 반응형 구조 만들기 -->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<!-- 내부 CSS 스타일 지정 -->
<style>
html, body {
width: 100%;
height: 100%;
margin : 0 auto;
padding : 0;
border : none;
background-color: #666;
}
</style>
<!-- [CDN 주소 설정] -->
<script src="https://code.jquery.com/jquery-latest.min.js"></script>
<script src="https://sdk.amazonaws.com/js/aws-sdk-2.1416.0.min.js"></script>
<!-- [자바스크립트 코드 지정] -->
<script>
// --------------------------------------------------------------------------------------------------------------
// [AWS 인증 변수 선언]
const accessKey = 'AK..A6';
const secretKey = 'mP..5J';
const region = 'ap-northeast-2';
// [필요 변수 선언]
var continueSelect = null;
var innerFunction = null;
const selectAllList = [];
// --------------------------------------------------------------------------------------------------------------
// [html 최초 로드 및 이벤트 상시 대기 실시]
window.onload = async function() {
console.log("");
console.log("=========================================");
console.log("[window onload] : [start]");
console.log("=========================================");
console.log("");
try {
// -----------------------------------------
// [초기 변수 초기화]
// -----------------------------------------
continueSelect = null;
innerFunction = null;
selectAllList.length = 0;
// -----------------------------------------
// [AWS.config 지정]
// -----------------------------------------
AWS.config.update({
region: region,
accessKeyId: accessKey,
secretAccessKey: secretKey
});
// -----------------------------------------
// [AWS 객체 생성]
// -----------------------------------------
const aws = new AWS.CloudWatchLogs();
// -----------------------------------------
// [내부 함수 생성]
// -----------------------------------------
innerFunction = async function() {
try {
while (true) { // 반복 조회 수행
// -----------------------------------------
// [요청 파라미터 생성]
// -----------------------------------------
var param = null;
if (continueSelect != null && continueSelect != undefined && continueSelect != ''){
param = {
limit: 10, // 한번에 조회할 제한 개수
nextToken : continueSelect // ✅ 반복 조회 요청
};
}
else {
param = {
limit: 10, // 한번에 조회할 제한 개수
};
}
// -----------------------------------------
// Aws CloudWatch Logs 로그 그룹에 대한 정보 조회 수행
// -----------------------------------------
// AWS 참고 사이트 : https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_DescribeLogGroups.html
// -----------------------------------------
const [err, res] = await aws.describeLogGroups(param).promise()
.then(data => [null, data])
.catch(error => [error, null]);
if (err) {
console.error("[aws result] : [Error] : ", err);
// [반복 조회 종료 위한 값 초기화]
continueSelect = null;
} else {
console.log("[aws result] : [Success] : ", JSON.stringify(res));
// ---------------------------------------------
// [로그 출력 예시 첨부]
// ---------------------------------------------
/*
{
"logGroups": [
{
"logGroupName": "/aws/lambda/my-lambda-function",
"creationTime": 1672531200000,
"retentionInDays": 14,
"metricFilterCount": 2,
"arn": "arn:aws:logs:ap-northeast-2:123456789012:log-group:/aws/lambda/my-lambda-function:*",
"storedBytes": 458762,
"kmsKeyId": "arn:aws:kms:ap-northeast-2:123456789012:key/abcd-1234-efgh-5678"
},
{
"logGroupName": "/aws/api-gateway/my-api",
"creationTime": 1669900800000,
"retentionInDays": 30,
"metricFilterCount": 0,
"arn": "arn:aws:logs:ap-northeast-2:123456789012:log-group:/aws/api-gateway/my-api:*",
"storedBytes": 982143
},
{
"logGroupName": "/ecs/service-a",
"creationTime": 1654041600000,
"metricFilterCount": 1,
"arn": "arn:aws:logs:ap-northeast-2:123456789012:log-group:/ecs/service-a:*",
"storedBytes": 12500480
},
{
"logGroupName": "/application/app-server",
"creationTime": 1651132800000,
"retentionInDays": 7,
"metricFilterCount": 0,
"arn": "arn:aws:logs:ap-northeast-2:123456789012:log-group:/application/app-server:*",
"storedBytes": 562304
}
],
"nextToken": "eyJ2IjoiMSIsImsiOiIxMjM0NTYifQ=="
}
*/
// ---------------------------------------------
// ---------------------------------------------
// [배열에 리스트 정보 추가]
// ---------------------------------------------
const resList = res.logGroups;
if (resList != null && resList != undefined){
selectAllList.push(...resList); // ✅ Array Add List
}
// ---------------------------------------------
// [반복 조회에 사용 될 정보가 있는지 확인]
// ---------------------------------------------
const resNext = res.nextToken;
if (resNext != null && resNext != undefined && resNext != ''){
continueSelect = resNext; // ✅ Set
}
else {
continueSelect = null; // Clear
}
}
// ---------------------------------------------
// [반복 조회에 사용 될 정보가 있는지 확인 후 무한 루프 탈출 수행]
// ---------------------------------------------
if (continueSelect == null || continueSelect == undefined || continueSelect == ''){
console.error("[innerFunction] : [continueSelect] : Is Null >> Stop While True");
break;
}
else {
console.warn("[innerFunction] : [continueSelect] : Exists >> Go To While True");
}
}
console.log("");
console.log("=========================================");
console.log("[innerFunction] : Result");
console.log("---------------------------------------");
console.log("Length : ", selectAllList.length);
console.log("---------------------------------------");
console.log(JSON.stringify(selectAllList));
console.log("=========================================");
console.log("");
}
catch(exception){
console.error("[innerFunction] : [Exception] : ", exception);
}
};
// -----------------------------------------
// [내부 클로저 함수 호출]
// -----------------------------------------
await innerFunction();
// ---------------------------------------------
// [Body 표시 JSON]
// ---------------------------------------------
var resJson = {
response: "result",
data: selectAllList
}
// ---------------------------------------------
// ---------------------------------------------
// [로그 출력]
// ---------------------------------------------
document.write(JSON.stringify(resJson));
// ---------------------------------------------
}
catch (exception) {
console.error("");
console.error("=========================================");
console.error("[window onload] : [Exception] : 예외 상황 발생");
console.error("-----------------------------------------");
console.error(exception);
console.error("=========================================");
console.error("");
// ---------------------------------------------
// [Body 표시 JSON]
// ---------------------------------------------
var errJson = {
response: "exception",
data: exception.message
}
// ---------------------------------------------
// ---------------------------------------------
// [에러 출력]
// ---------------------------------------------
document.write(JSON.stringify(errJson));
// ---------------------------------------------
}
};
// --------------------------------------------------------------------------------------------------------------
</script>
</head>
<body>
</body>
</html>
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
[참고 사이트]
-----------------------------------------------------------------------------------------
[Amazon CloudWatch] Aws CloudWatch 클라우드 와치 개념 및 설정 정리 - Aws 애플리케이션 실시간으로 모니터링 서비스
https://kkh0977.tistory.com/7920
https://blog.naver.com/kkh0977/223834321984?trackingCode=blog_bloghome_searchlist
[AWS] [Lambda] 런타임 Python 3.13 - boto3 모듈 사용해 AWS CloudWatch 로그 그룹 목록 조회
https://kkh0977.tistory.com/8216
https://blog.naver.com/kkh0977/223970759098?trackingCode=blog_bloghome_searchlist
[AWS] [Lambda] 런타임 Python 3.13 - boto3 모듈 사용해 AWS CloudWatch 특정 로그 그룹 스트림 목록 조회
https://kkh0977.tistory.com/8217
https://blog.naver.com/kkh0977/223971181373?trackingCode=blog_bloghome_searchlist
[AWS] [Lambda] 런타임 Python 3.13 - boto3 모듈 사용해 AWS CloudWatch 특정 로그 스트림의 로그 이벤트 조회
https://blog.naver.com/kkh0977/223974859391?trackingCode=blog_bloghome_searchlist
-----------------------------------------------------------------------------------------
728x90
반응형
'JavaScript' 카테고리의 다른 글
Comments
