The Simplest Way to Make Cloud SQL and Lambda Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Running cloud sql and lambda together lets serverless functions read and write managed database rows. This setup connects event-driven compute in AWS with relational storage in Google Cloud. Many teams build across two clouds when they buy new companies or split workloads. A function in AWS often needs to check order data or save user state. Google Cloud SQL holds that relational data in a managed PostgreSQL or MySQL engine. Getting the two platforms to talk takes clear network rules and tight

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

Running cloud sql and lambda together lets serverless functions read and write managed database rows. This setup connects event-driven compute in AWS with relational storage in Google Cloud.

Many teams build across two clouds when they buy new companies or split workloads. A function in AWS often needs to check order data or save user state. Google Cloud SQL holds that relational data in a managed PostgreSQL or MySQL engine. Getting the two platforms to talk takes clear network rules and tight user permissions.

How cloud sql and lambda share data and permissions

A function wakes up on an event, opens a database session, and runs a query. Because the function and the database live in different clouds, traffic crosses network boundaries. Teams set up private network links or encrypted public paths between AWS and Google Cloud. Both sides need strict firewall rules so only known source addresses can reach the database.

Inside Cloud SQL for PostgreSQL, you must plan user roles with care. It is a managed service, so customers cannot create users with true superuser attributes. Google reserves a system user named cloudsqladmin to hold full superuser privileges on the database. Customers cannot delete or change these built-in system roles or users.

Instead, admins use the default postgres user or create roles that belong to cloudsqlsuperuser. The default postgres user starts with no password, so you must set one before login. This user can create roles, create databases, and log in, and it belongs to cloudsqlsuperuser. The cloudsqlsuperuser role gives some high privileges, like creating extensions or setting up replication. Still, a serverless function should never run daily queries with those high admin rights.

Common failure modes and how to scope roles

The biggest mistake teams make is putting the default admin password into function settings. When every function uses the same broad database login, you lose clear audit trails. If one function gets breached, the attacker gains broad rights across the whole database. Long-lived passwords stored in function settings also create rotation pain for platform teams.

Another common issue is unlogged queries from both functions and human engineers. When an app breaks, developers often copy the function credentials to run manual fixes. Without query logs tied to real people, you cannot tell who changed production rows. Sensitive fields like emails, phone numbers, card numbers, and national IDs also face exposure.

Lambda Execution Roles + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

To fix this, create a narrow database role for each function workload. Grant that role only the exact table read or write rights it needs to run. Never give your serverless functions the cloudsqlsuperuser role or role creation rights. Keep admin tasks like extension setup separate from normal app traffic.

You should also Watch how many database sessions your functions open during traffic spikes. Serverless functions scale up fast and can exhaust open database slots in seconds. Set strict concurrency limits on the function side and keep queries short and fast. For human engineers who debug these databases, tie every query to an individual identity. Masking rules can also rewrite emails or card numbers in query results during debugging.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

Should my AWS function use the default postgres user in Cloud SQL?

No, the default postgres user belongs to cloudsqlsuperuser and can create roles and databases. Create a dedicated database user with only the specific table permissions your function needs.

Why do serverless functions run out of database slots so fast?

Each running function instance opens its own database session when traffic spikes. You must limit function concurrency and close idle sessions so the database stays stable.

How can teams protect sensitive columns when engineers debug database issues?

Teams should route human queries through a system that ties sessions to individual identities. Data masking can then rewrite matched fields like phone numbers or national IDs in results.

Short role checks help teams work fast. Simple rules make each review clear. Good logs keep every team safe. Scoped keys stop bad changes early.

The query runs. The emails stay hidden.