Monitoraggio e debugging delle funzioni Lambda
Impari a osservare, registrare, tracciare e risolvere i problemi delle funzioni AWS Lambda in produzione usando CloudWatch, X-Ray e il logging strutturato.
Monitoraggio e debugging delle funzioni Lambda è una lezione AWS for Backend Developers (EC2, S3, RDS, Lambda) gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento AWS for Backend Developers (EC2, S3, RDS, Lambda), e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso AWS for Backend Developers (EC2, S3, RDS, Lambda) include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
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.
Domande Frequenti
La lezione «Monitoraggio e debugging delle funzioni Lambda» è gratuita?
Sì — il testo completo di «Monitoraggio e debugging delle funzioni Lambda» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso AWS for Backend Developers (EC2, S3, RDS, Lambda), passa a CoddyKit PRO. Il corso AWS for Backend Developers (EC2, S3, RDS, Lambda) include 4 lezioni in totale.
Cosa imparerò in «Monitoraggio e debugging delle funzioni Lambda»?
Impari a osservare, registrare, tracciare e risolvere i problemi delle funzioni AWS Lambda in produzione usando CloudWatch, X-Ray e il logging strutturato. Eserciti AWS for Backend Developers (EC2, S3, RDS, Lambda) con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare AWS for Backend Developers (EC2, S3, RDS, Lambda)?
Non è richiesta alcuna esperienza precedente. AWS for Backend Developers (EC2, S3, RDS, Lambda) su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.
Quanto tempo richiede la lezione «Monitoraggio e debugging delle funzioni Lambda»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione AWS for Backend Developers (EC2, S3, RDS, Lambda)?
Sì. Ogni lezione AWS for Backend Developers (EC2, S3, RDS, Lambda) include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Che cos'è AWS Lambda?
- Creazione della prima funzione Lambda
- Trigger e integrazioni di Lambda
- Monitoraggio e debugging delle funzioni Lambda