CloudWatch 로그와 로그 그룹
문제 해결과 감사에 활용하도록 다양한 AWS 서비스 및 사용자 지정 애플리케이션의 로그를 수집하고 모니터링하며 저장합니다.
CloudWatch 로그와 로그 그룹은(는) CoddyKit의 무료 AWS for Backend Developers (EC2, S3, RDS, Lambda) 강의입니다. 이것은 4개 중 2번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 AWS for Backend Developers (EC2, S3, RDS, Lambda) 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. AWS for Backend Developers (EC2, S3, RDS, Lambda) 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
CloudWatch Logs Intro
Imagine trying to fix a problem in your application without knowing what happened! That's where logs come in.
CloudWatch Logs is an AWS service that helps you collect, monitor, and store logs from your applications and various AWS services.
It's crucial for troubleshooting, auditing, and understanding how your systems are performing.
Log Groups Explained
At the core of CloudWatch Logs is the concept of a Log Group.
Think of a Log Group as a dedicated folder or container for logs that share the same characteristics, like logs from a specific application or service.
For example, all logs from your 'WebApp-Production' service might go into one Log Group.
Log Streams within Groups
Inside each Log Group, you'll find Log Streams.
A Log Stream is a sequence of log events from a single source within that Log Group.
- For an EC2 instance, each instance might have its own Log Stream.
- For a Lambda function, each invocation or version could generate a Log Stream.
They help you pinpoint the exact source of your log data.
Setting Up Log Groups
Many AWS services automatically create Log Groups for you when they generate logs, like AWS Lambda or AWS Fargate.
For custom applications, you'll typically create a Log Group manually and then configure your application or the CloudWatch Agent to send logs to it.
You can create and manage Log Groups via the AWS Management Console, AWS CLI, or SDKs.
Ingesting EC2 Logs
To send logs from applications running on an EC2 instance to CloudWatch Logs, you use the CloudWatch Agent.
- Install the agent on your EC2 instance.
- Configure it to monitor specific log files (e.g.,
/var/log/myapp.log). - The agent then streams these logs to a specified Log Group and Log Stream in CloudWatch Logs.
Lambda's Automatic Logs
AWS Lambda automatically integrates with CloudWatch Logs! Any output your Lambda function generates (e.g., using print() in Python or console.log() in Node.js) is sent to CloudWatch Logs.
Try running this simple Python Lambda function and check its logs:
import json
def lambda_handler(event, context):
print("INFO: Lambda function execution started.")
# Simulate processing an event
if 'detail' in event and 'message' in event['detail']:
print(f"DEBUG: Processing message: {event['detail']['message']}")
else:
print("DEBUG: No specific message in event.")
# Simulate an error condition based on input
if 'statusCode' in event and event['statusCode'] >= 400:
print("ERROR: An error status was detected in the input event!")
return {
'statusCode': event['statusCode'],
'body': json.dumps('Error processed!')
}
print("INFO: Lambda function execution finished successfully.")
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}Finding Info in Logs
Once your logs are in CloudWatch Logs, you can easily search and filter them.
- Search: Look for specific keywords, phrases, or patterns across all your log events.
- Filter: Narrow down results by time range, Log Stream, or even specific fields if your logs are structured (e.g., JSON).
This helps you quickly diagnose issues or find relevant events.
Managing Log Retention
Logs can consume a lot of storage, and you might have compliance requirements for how long to keep them.
Log Retention Policies allow you to define how long CloudWatch Logs should store your log events.
- Options range from 'Never Expire' to 1 day, 30 days, 1 year, etc.
- Setting appropriate retention helps manage costs and adhere to data policies.
Log Metrics Filters
Beyond just viewing logs, you can extract meaningful data from them using Metric Filters.
A Metric Filter defines a pattern to look for in your log events (e.g., the word "ERROR" or a specific status code).
When the pattern is matched, CloudWatch increments a custom metric, which you can then use to create alarms (as seen in the previous lesson!).
Log Group Basics
Time for a quick check on CloudWatch Logs!
Which statement best describes the relationship between CloudWatch Log Groups and Log Streams?
Logs Recap
Great job! You've learned the essentials of CloudWatch Logs.
We covered:
- Log Groups for organizing logs.
- Log Streams for individual log sources.
- How to ingest logs from services like EC2 and Lambda.
- How to search and filter logs efficiently.
- Configuring retention policies and creating metric filters from logs.
Next, we'll explore CloudTrail for event-driven monitoring and auditing.
자주 묻는 질문
“CloudWatch 로그와 로그 그룹” 강의는 무료인가요?
네 — “CloudWatch 로그와 로그 그룹” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 AWS for Backend Developers (EC2, S3, RDS, Lambda) 강의 전체를 잠금 해제할 수 있습니다. AWS for Backend Developers (EC2, S3, RDS, Lambda) 강의에는 총 4개의 강의가 포함되어 있습니다.
“CloudWatch 로그와 로그 그룹”에서 뭘 배우나요?
문제 해결과 감사에 활용하도록 다양한 AWS 서비스 및 사용자 지정 애플리케이션의 로그를 수집하고 모니터링하며 저장합니다. 브라우저에서 직접 실행하는 실습 코드로 AWS for Backend Developers (EC2, S3, RDS, Lambda)을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
AWS for Backend Developers (EC2, S3, RDS, Lambda)을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 AWS for Backend Developers (EC2, S3, RDS, Lambda)은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 2번째 강의입니다.
“CloudWatch 로그와 로그 그룹” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 AWS for Backend Developers (EC2, S3, RDS, Lambda) 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 AWS for Backend Developers (EC2, S3, RDS, Lambda) 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- CloudWatch 지표와 경보
- CloudWatch 로그와 로그 그룹
- CloudTrail을 활용한 이벤트 기반 모니터링
- CloudWatch 대시보드 구축