How to setup setup private IP using VPC peering for AWS Aerospike instance?

Code is deployed in AWS Lambda and it’s connecting to aerospike instance(t2 large) using public IP with python client but it is taking around 1.2012 seconds, sometimes more time to connect.

Please suggest the steps to set up the connection with private IP using VPC peering and also how I can reduce the connection time to aerospike instance.

Please correct me if I am wrong, but doesn’t lambda have to recreate the client for each invocation?

If so, the process of the client discovering the cluster is probably the source of the latency.

Yes, but if we write connection to Aerospike outside the lambda_handler function (entry to lambda function) then that connection remains and reused till the Lambda function is warm.

I want to use private IP using VPC peering currently, public IP is used to make a connection.

Lambda function code.

import json
import os

import aerospike

from aerospike import exception as ex

AEROSPIKE_HOST = os.environ['AEROSPIKE_HOST']


config = {
    'hosts': [(AEROSPIKE_HOST, 3000)]
}
try:
    client = aerospike.client(config).connect()
except ex.ClientError as e:
    print("failed to connect to the cluster with", config["hosts"], str(e))
print("Connected successfully.", config['hosts'])


def lambda_handler(event, context):
    """Entry point
    """
    # code here

    return {
        "status": 200,
        "body": json.dumps({
            "message": "Success",
        }),
    }


if __name__ == '__main__':
    payload = {}
    lambda_handler(payload, '')

How to setup private IP using VPC peering to decrease the latency?