An AWS Lambda function runs within a container—an execution environment that is isolated from other functions. When you run a function for the first time, AWS Lambda creates a new container and begins executing the function's code.
A Lambda function has a handler that is executed once per invocation. The handler contains the main business logic for the function. For example, the Lambda function shown in Step 4: Create and Test a Lambda Function has a handler that can process records in a DynamoDB stream.
After the function executes, AWS Lambda may opt to reuse the container for subsequent invocations of the function. In this case, your function handler might be able to reuse the resources that you defined in your initialization code. (Note that you cannot control how long AWS Lambda will retain the container, or whether the container will be reused at all.)
For DynamoDB triggers using AWS Lambda, we recommend the following:
AWS service clients should be instantiated in the initialization code, not in the handler. This will allow AWS Lambda to reuse existing connections, for the duration of the container's lifetime.
In general, you do not need to explicitly manage connections or implement connection pooling because AWS Lambda manages this for you.
For more information, go to Best Practices for Working with AWS Lambda Functions in the AWS Lambda Developer Guide.