Supervisión y depuración de funciones Lambda
Aprenda a observar, registrar, rastrear y solucionar problemas de funciones AWS Lambda en producción mediante CloudWatch, X-Ray y registros estructurados.
Supervisión y depuración de funciones Lambda es una lección gratuita de AWS for Backend Developers (EC2, S3, RDS, Lambda) en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de AWS for Backend Developers (EC2, S3, RDS, Lambda), y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de AWS for Backend Developers (EC2, S3, RDS, Lambda) incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
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.
Preguntas frecuentes
¿La lección «Supervisión y depuración de funciones Lambda» es gratis?
Sí — el texto completo de «Supervisión y depuración de funciones Lambda» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de AWS for Backend Developers (EC2, S3, RDS, Lambda), actualiza a CoddyKit PRO. El curso de AWS for Backend Developers (EC2, S3, RDS, Lambda) incluye 4 lecciones en total.
¿Qué aprenderé en «Supervisión y depuración de funciones Lambda»?
Aprenda a observar, registrar, rastrear y solucionar problemas de funciones AWS Lambda en producción mediante CloudWatch, X-Ray y registros estructurados. Practicas AWS for Backend Developers (EC2, S3, RDS, Lambda) con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar AWS for Backend Developers (EC2, S3, RDS, Lambda)?
No se requiere experiencia previa. AWS for Backend Developers (EC2, S3, RDS, Lambda) en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.
¿Cuánto tiempo toma la lección «Supervisión y depuración de funciones Lambda»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de AWS for Backend Developers (EC2, S3, RDS, Lambda)?
Sí. Cada lección de AWS for Backend Developers (EC2, S3, RDS, Lambda) incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- ¿Qué es AWS Lambda?
- Creación de su primera función Lambda
- Triggers e integraciones de Lambda
- Supervisión y depuración de funciones Lambda