StudyToCert

All certifications / Developer Associate / Lessons

AWS Certified Developer – Associate DVA-C02 · Domain 1: Development with AWS Services

Lambda coding practices: initializing SDK clients and connections outside the handler, reading events, returning API Gateway proxy responses

▶ Watch the overview video

Last reviewed October 6, 2026 · Leer en español

Explain it simpler

A Lambda handler is the one function AWS calls each time your code runs. It receives two things: the event, which is the input such as a web request, and the context, which is information like how much time is left. Lambda keeps the same copy of your program warm for a while and reuses it, so anything you set up outside the handler, like a database connection, is created once and reused, like leaving the coffee machine on between customers. But do not leave one customer's order sitting on the counter for the next. When API Gateway, the front door for web requests, calls your function, your reply must follow a set format with a status code and a text body.

The Thursday release at Glasswing Travel went out smoothly, until the mobile team reported that every booking lookup now returns 502 Bad Gateway. The Lambda logs show no errors at all; the function finds the booking and returns it. At the same time, the database team is paging you because connection counts tripled overnight, and a user filed a ticket saying she briefly saw another customer's name in her itinerary. Your teammate Jun pulls up the refactored handler code. Somewhere in about thirty lines are three mistakes: one in the response shape, one in where a connection is created, and one in where a variable lives. Can you spot them?

A Lambda function is built around a handler: a function that Lambda calls once per invocation with two arguments. The first is the event, the input data, whose shape depends on what invoked the function. The second is the context object, which carries runtime information such as the request ID, the function name, the memory limit and the remaining execution time. Writing the handler well has a direct effect on speed, cost and correctness, and the AWS Certified Developer – Associate (DVA-C02) exam tests a few specific habits.

Free account

Keep reading for free

Create a free StudyToCert account to read the rest of this lesson: 8 more sections, 6 key terms, a real-world example, an exam tip and self-check questions. Every lesson, lab and practice test is free with an account.

Sign up free Log in

Study Developer Associate for free
A week-by-week plan with every lesson, quizzes, checkpoint tests, a practice exam and hands-on labs.
Open the Developer Associate study plan