Monitorowanie i debugowanie funkcji Lambda
Dowiedz się, jak obserwować, rejestrować, śledzić i diagnozować funkcje AWS Lambda na produkcji za pomocą CloudWatch, X-Ray i ustrukturyzowanego logowania.
Monitorowanie i debugowanie funkcji Lambda to bezpłatna lekcja AWS for Backend Developers (EC2, S3, RDS, Lambda) na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej AWS for Backend Developers (EC2, S3, RDS, Lambda), a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs AWS for Backend Developers (EC2, S3, RDS, Lambda) zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
Why Observability Matters
Serverless functions are short-lived and invisible — you cannot SSH into them. Observability is how you understand what your Lambda is doing.
The three pillars are logs, metrics, and traces.
Logging with CloudWatch
Anything your function writes to stdout/stderr goes to CloudWatch Logs automatically. Each function gets its own log group.
exports.handler = async (event) => {
console.log('Received event:', JSON.stringify(event));
return { statusCode: 200, body: 'OK' };
};Structured Logging
Plain text logs are hard to query. Log JSON objects so you can filter on fields later.
- Include a requestId
- Include severity and context
console.log(JSON.stringify({
level: 'INFO',
requestId: context.awsRequestId,
message: 'Order processed',
orderId: 42
}));Built-in Lambda Metrics
Lambda publishes metrics to CloudWatch out of the box:
- Invocations — how often it ran
- Errors — failed executions
- Duration — execution time
- Throttles — rejected due to concurrency limits
Setting Alarms on Errors
Create a CloudWatch alarm so you get notified when error rates spike, instead of finding out from angry users.
aws cloudwatch put-metric-alarm \
--alarm-name lambda-errors \
--metric-name Errors \
--namespace AWS/Lambda \
--threshold 1 \
--comparison-operator GreaterThanThreshold \
--evaluation-periods 1Distributed Tracing with X-Ray
AWS X-Ray traces a request as it flows through Lambda, DynamoDB, S3, and other services. It reveals where time is spent and which downstream call is slow.
Enable Active tracing in the function configuration.
Cold Starts
A cold start happens when Lambda spins up a fresh execution environment. It adds latency to the first request.
Watch Init Duration in your logs to measure cold start impact.
Reducing Cold Starts
Ways to reduce cold start pain:
- Use Provisioned Concurrency to keep environments warm
- Keep deployment packages small
- Avoid heavy initialization at module load
Handling Errors Gracefully
Wrap risky code in try/catch and return meaningful errors. Unhandled exceptions count as Lambda errors and may trigger retries.
exports.handler = async (event) => {
try {
return await process(event);
} catch (err) {
console.error('Processing failed', err);
throw err;
}
};Dead Letter Queues
For asynchronous invocations that keep failing, configure a Dead Letter Queue (DLQ) using SQS or SNS. Failed events land there so you can inspect and reprocess them.
Putting It Together
A well-monitored Lambda has:
- Structured JSON logs
- CloudWatch alarms on Errors and Duration
- X-Ray tracing enabled
- A DLQ for failed async events
Quick Check
Test your debugging knowledge.
Recap
You learned to monitor and debug Lambda:
- CloudWatch Logs capture stdout/stderr
- Metrics and alarms alert on errors
- X-Ray traces distributed calls
- DLQs capture failed async events
Good observability turns invisible serverless failures into solvable problems.
Ucz się AWS for Backend Developers (EC2, S3, RDS, Lambda) dzięki korepetycjom AI — za darmo
Pisz i uruchamiaj kod w przeglądarce, otrzymuj natychmiastową pomoc od korepetytora AI dostępnego 24/7 i kontynuuj naukę w sieci lub w aplikacji.
- Kursy
- 12
- Lekcje
- 48
Często zadawane pytania
Czy lekcja „Monitorowanie i debugowanie funkcji Lambda” jest bezpłatna?
Tak — pełny tekst „Monitorowanie i debugowanie funkcji Lambda” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu AWS for Backend Developers (EC2, S3, RDS, Lambda), przejdź na CoddyKit PRO. Kurs AWS for Backend Developers (EC2, S3, RDS, Lambda) zawiera 4 lekcji w sumie.
Co nauczysz się w „Monitorowanie i debugowanie funkcji Lambda”?
Dowiedz się, jak obserwować, rejestrować, śledzić i diagnozować funkcje AWS Lambda na produkcji za pomocą CloudWatch, X-Ray i ustrukturyzowanego logowania. Ćwiczysz AWS for Backend Developers (EC2, S3, RDS, Lambda) z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć AWS for Backend Developers (EC2, S3, RDS, Lambda)?
Nie wymagamy żadnego doświadczenia. AWS for Backend Developers (EC2, S3, RDS, Lambda) w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.
Ile czasu zajmuje lekcja „Monitorowanie i debugowanie funkcji Lambda”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji AWS for Backend Developers (EC2, S3, RDS, Lambda)?
Tak. Każda lekcja AWS for Backend Developers (EC2, S3, RDS, Lambda) zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Czym jest AWS Lambda?
- Tworzenie pierwszej funkcji Lambda
- Wyzwalacze i integracje Lambda
- Monitorowanie i debugowanie funkcji Lambda