Notice
Recent Posts
Recent Comments
Link
투케이2K
189. (Aws/Amazon) [Amazon CloudWatch] 특정 로그 그룹안에 존재하는 로그 스트림 목록 조회 DescribeLogStreams API 설명 정리 본문
Aws (Amazon)
189. (Aws/Amazon) [Amazon CloudWatch] 특정 로그 그룹안에 존재하는 로그 스트림 목록 조회 DescribeLogStreams API 설명 정리
투케이2K 2026. 2. 26. 19:35728x90
반응형
[개발 환경 설정]
개발 환경 : Aws / Amazon Web Services

[설명 정리]
// --------------------------------------------------------------------------------------
[개발 및 환경]
// --------------------------------------------------------------------------------------
- 인프라 : Aws / Amazon Web Services
- 기술 구분 : Aws / CloudWatch / DescribeLogStreams
- 사전) AWS CloudWatch 간단 설명 :
>> Aws CloudWatch 는 Amazon Web Services (AWS) 리소스 및 AWS 에서 실행되는 애플리케이션을 실시간으로 모니터링 할 수 있는 서비스입니다
>> Aws CloudWatch 를 사용하면 시스템 전체의 리소스 사용률, 애플리케이션 성능, 운영 상태를 파악할 수 있습니다
>> Aws CloudWatch 와 함께 사용할 수 있는 서비스 :
- Amazon Simple Notification Service (Amazon SNS) : CloudWatch 와 함께 Amazon SNS를 사용하여 구독 중인 엔드포인트 또는 클라이언트에 메시지를 전달 또는 전송하는 것을 조정하고 관리합니다
- Amazon EC2 Auto Scaling : Amazon EC2 Auto Scaling 과 함께 CloudWatch 경보를 사용하여 사용자 정의 정책, 상태 확인, 일정에 따라 Amazon EC2 인스턴스를 자동으로 시작하거나 종료할 수 있습니다
- AWS CloudTrail : AWS CloudTrail 을 사용해 AWS Management Console, AWS CLI 및 기타 서비스에서 수행한 호출을 포함하여 계정의 Amazon CloudWatch API에 대한 호출을 모니터링할 수 있습니다
- AWS Identity and Access Management (IAM) : IAM 을 사용하여 AWS 리소스를 사용할 수 있는 사용자를 제어(인증)하고 해당 사용자가 사용할 수 있는 리소스 및 사용 방법을 제어(권한 부여)할 수 있습니다
// --------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------
[설 명]
// --------------------------------------------------------------------------------------
1. DescribeLogStreams 는 특정 로그 그룹 (Log Group) 안에 존재하는 로그 스트림 (Log Stream) 목록을 조회하는 CloudWatch Logs API 입니다.
2. DescribeLogStreams API 를 통해 반환 되는 로그 스트림은 개별 애플리케이션 인스턴스, 컨테이너, 로그 파일 등에 해당하는 단위이며, 이 API는 해당 스트림들의 메타데이터를 제공합니다.
3. DescribeLogStreams 주요 기능 :
>> 지정한 로그 그룹의 로그 스트림 목록 조회 :
- logGroupName 을 기준으로 모든 스트림을 조회할 수 있습니다.
>> 접두사 (prefix) 로 필터링 가능 :
- logStreamNamePrefix 사용 시 특정 이름으로 시작하는 스트림만 조회할 수 있습니다.
- 단, orderBy = LastEventTime 사용 시 prefix 필터는 사용할 수 없습니다.
>> 정렬 옵션 제공 :
- orderBy = LogStreamName (기본값) : 스트림 이름순 정렬
- orderBy = LastEventTime : 가장 최근 이벤트 시간 기반 정렬
- descending = true 로 최신순 정렬 가능
>> 페이징 (Pagination) 지원 :
- NextToken을 기반으로 여러 번 호출하여 전체 스트림 목록을 가져옵니다.
4. ✅ DescribeLogStreams 호출 시 요청 전문
>> GET /?Action=DescribeLogStreams
>> logGroupName (필수) : 조회할 로그 그룹 이름
>> logStreamNamePrefix : 접두사 기반 스트림 필터링
>> orderBy : LogStreamName 또는 LastEventTime
>> descending : true 설정 시 내림차순 정렬
>> nextToken : 페이징 토큰
5. ✅ DescribeLogStreams 응답 전문
>> DescribeLogStreams 응답 JSON 예시 :
{
"logStreams": [
{
"logStreamName": "20150531",
"creationTime": 1433189871774,
"arn": "arn:aws:logs:region:acct:log-group:my-logs:log-stream:20150531",
"storedBytes": 0
}
],
"nextToken": "..."
}
6. ❌ DescribeLogStreams 호출 주요 에러 발생 코드 :
>> ThrottlingException : CloudWatch Logs 에서 과한 API 호출(스크립트/자동화)이 있을 때 발생
>> ResourceNotFoundException : logGroupName 또는 지정한 로그 그룹이 존재하지 않을 때 발생
>> InvalidParameterException : orderBy = LastEventTime 사용하면서 logStreamNamePrefix를 함께 지정한 경우
>> ServiceUnavailableException : CloudWatch Logs 서비스의 임시 장애 시 발생
>> UnrecognizedClientException : 잘못된 AWS 자격증명 또는 인증 실패 시 발생
>> AccessDeniedException : IAM 권한 부족으로 DescribeLogStreams 호출이 거부될 때
7. ✅ DescribeLogStreams 호출 자바스크립트 예시 소스 코드 :
<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';
// [AWS 그룹 명칭 선언]
const logGroupName = '/aws/lambda/device-queue-manager';
window.onload = async function() {
// -----------------------------------------
// [AWS.config 지정]
// -----------------------------------------
AWS.config.update({
region: region,
accessKeyId: accessKey,
secretAccessKey: secretKey
});
// -----------------------------------------
// [AWS 객체 생성]
// -----------------------------------------
const aws = AWS.CloudWatchLogs();
// -----------------------------------------
// Aws CloudWatch Logs 로그 그룹에 대한 정보 조회 수행
// -----------------------------------------
// AWS 참고 사이트 : https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_DescribeLogStreams.html
// -----------------------------------------
const param = { // ✅ Request_파라미터
logGroupName: logGroupName, // 로그 그룹 명칭
orderBy: 'LastEventTime', // 'LogStreamName'도 가능
descending: true, // 최근 이벤트 순으로 내림차순
limit: 50 // 한번에 조회할 제한 개수
};
aws.describeLogStreams( param , (err, data) => {
if (err) console.error(err);
else console.log(JSON.stringify(data));
});
};
</script>
// --------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------
[참고 사이트]
// --------------------------------------------------------------------------------------
[Amazon CloudWatch] Aws CloudWatch 클라우드 와치 개념 및 설정 정리 - Aws 애플리케이션 실시간으로 모니터링 서비스
https://kkh0977.tistory.com/7920
https://blog.naver.com/kkh0977/223834321984?trackingCode=blog_bloghome_searchlist
[Amazon 모니터링 및 로깅 서비스] AWS CloudWatch 와 CloudTrail 차이점 정리
https://kkh0977.tistory.com/8143
https://blog.naver.com/kkh0977/223934869835?trackingCode=blog_bloghome_searchlist
[Amazon CloudWatch] DescribeLogGroups AWS CloudWatch Logs 로그 그룹 목록 조회 API 설명 정리
https://kkh0977.tistory.com/8640
https://blog.naver.com/kkh0977/224188525167
// --------------------------------------------------------------------------------------
728x90
반응형
'Aws (Amazon)' 카테고리의 다른 글
Comments
