# Connecting from google cloud functions

**URL:** <https://discuss.aerospike.com/t/connecting-from-google-cloud-functions/7551>\
**Category:** General Discussion\
**Created:** [June 18, 2020, 4:41am UTC](https://discuss.aerospike.com/t/connecting-from-google-cloud-functions/7551 "2020-06-18T04:41:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ayyappa99](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/ayyappa99/32/1458_2.png) [@ayyappa99](https://discuss.aerospike.com/u/ayyappa99)\
**Post date:** [June 18, 2020, 4:41am UTC](https://discuss.aerospike.com/t/connecting-from-google-cloud-functions/7551/1 "2020-06-18T04:41:04Z")

</div>

Is it ideal to connect/disconnect to Aerospike instance too frequently? We have our rest api hosted on cloud functions (serverless - similar to AWS Lambda) and would like to connect to Aerospike db.

Is it possible to connect through your node client quickly and disconnect once the function instance goes down?

---

<div class="post-metadata">

**Author:** ![kporter](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/kporter/32/515_2.png) [@kporter](https://discuss.aerospike.com/u/kporter)\
**Post date:** [June 18, 2020, 5:58pm UTC](https://discuss.aerospike.com/t/connecting-from-google-cloud-functions/7551/2 "2020-06-18T17:58:16Z")

</div>

When you instantiate a client, it must first discover the cluster. This means polling the seed nodes you provided the application to discover other nodes in the cluster. This process of can take a significant amount of time when compared to a read or write operation.

The [Aerospike REST client](https://www.aerospike.com/docs/client/rest/) may be the way to go here. Basically you would have these clients running outside of the ‘lambda’ environment where they can maintain this bootstrap state and you applications would make requests to the REST client’s API.

---

<div class="post-metadata">

**Author:** ![ayyappa99](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/ayyappa99/32/1458_2.png) [@ayyappa99](https://discuss.aerospike.com/u/ayyappa99)\
**Post date:** [June 19, 2020, 7:43am UTC](https://discuss.aerospike.com/t/connecting-from-google-cloud-functions/7551/3 "2020-06-19T07:43:18Z")

</div>

Thanks for the details. I found out that there is a possibility to [connect to a vpc](https://cloud.google.com/functions/docs/networking/connecting-vpc). Do you see i can just connect to it with local ip and it works directly?

Thanks, Ayyappa

---

<div class="post-metadata">

**Author:** ![kporter](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/kporter/32/515_2.png) [@kporter](https://discuss.aerospike.com/u/kporter)\
**Post date:** [June 19, 2020, 6:27pm UTC](https://discuss.aerospike.com/t/connecting-from-google-cloud-functions/7551/4 "2020-06-19T18:27:45Z")

</div>

Since you are running in a lambda like environment, I assume these clients are to be instantiated once per request? The latency from the initial cluster bootstrap process could prohibitive (but you will need to measure). The REST client should perform betters in this environment (assuming I have my assumptions right).

---

<div class="post-metadata">

**Author:** ![ayyappa99](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/ayyappa99/32/1458_2.png) [@ayyappa99](https://discuss.aerospike.com/u/ayyappa99)\
**Post date:** [June 20, 2020, 1:12pm UTC](https://discuss.aerospike.com/t/connecting-from-google-cloud-functions/7551/5 "2020-06-20T13:12:13Z")

</div>

Thank you! I will try with REST then.
