Hi,
I've observed that Gen1 Cloud Functions can connect to Cloud SQL using the connection name format /cloudsql/<connection_name> (e.g., project:location:name). However, Gen2 functions seem unable to use this method and instead require a Serverless VPC Connector for connectivity.
Could you explain the differences in the underlying infrastructure between Gen1 and Gen2 that result in these connectivity capabilities? Additionally, is one method more secure than the other? Finally, is there any plan or possibility for Gen2 functions to support connection names for Cloud SQL in the future?
Thanks for your insights!
Hi @alex-goida,
Cloud Run Functions (2nd gen) should also be able to Connect to Cloud SQL using /cloudsql/INSTANCE_CONNECTION_NAME
via Unix sockets. This method only works on MySQL and PostgreSQL database engines. If you’re looking to connect to Cloud SQL using Cloud Run Functions, I’d recommend following this Quickstart Guide for an example with best practices.
For its infrastructure, Cloud Run Functions (2nd gen) run in a fully-managed serverless environment where Google handles infrastructure, operating systems, and runtime environments. Each function runs in its own isolated secure execution context, scales automatically, and has a lifecycle independent from other functions.
Cloud Run Functions (2nd gen) offer enhanced features compared to Cloud Run Functions (1st gen). Refer to the table below for more details:
In terms of connectivity and security, Google maintains all Cloud Run Functions runtime images, releasing security patches and maintenance updates after a period of stability testing to improve functionality. Cloud Run Functions also have:
If you have any more suggestions and questions, I highly recommend creating a Feature Request ticket for Cloud Run Functions or other Google Cloud products you may use. Although I don't have a specific date for the implementation of feature requests, Google Cloud waits for a request to have a handful of stars and, hopefully, comments from several users about how the feature would be useful.
Hope this helped!
Unfortunately, it doesn't work as expected. I have a PostgreSQL database in Cloud SQL and two types of functions: gen1 and gen2. No matter how I set up the VPC, gen1 can connect to Cloud SQL using the instance connection name, but gen2 can't. Gen2 functions can only connect using the private IP address.
I know there might be other settings affecting this connection that I haven't considered. Can you suggest what else I should look into?
Thanks,