A developer has implemented an AWS Lambda function that inserts new customers into an Amazon RDS database. The function is expected to run hundreds of times each hour. The function and RDS database are in the same VPC. The function is configured to use 512 MB of RAM and is based on the following pseudo code: After successfully testing the function multiple times, the developer notices that the execution time is longer than expected. What should the developer do to improve performance?

Select an option, then click Submit answer.
Reference / correct answer:
Move the database connection and close statement out of the handler. Place the connection in the global space.
Most accepted answer: C. Move the database connection and close statement out of the handler. Place the connection in the global space.
Community votes: A=1, C=3
Selected Answer: C A - Concurrency helps scale, but doesn't reduce individual function execution time. B - Database scaling is not likely the primary fix for individual slow Lambda. No info on database sizing or other lambdas running slow so eliminated this as a solution. D - Changing the database type is an architectural shift, not a performance tune. C feels correct - Reusing connections globally prevents connection overhead on subsequent invocations. upvoted 1 times
Selected Answer: C connection to database as global variable outside the handler upvoted 1 times
Selected Answer: C The best answer is C: Move the database connection and close statement out of the handler. Place the connection in the global space. This solution would: Create the connection once when the Lambda container initializes Reuse that same connection across multiple invocations Significantly reduce the overhead of establishing new connections Improve execution time and resource usage Follow AWS best practices for Lambda-RDS connections upvoted 2 times
Selected Answer: A Reserved concurrency defines the maximum number of concurrent executions for a Lambda function. If the function is expected to run hundreds of times each hour, it could be hitting concurrency limits, causing delays due to Lambda being throttled, which would lead to longer execution times. upvoted 1 times