The Simplest Way to Make Cloud Functions and Dynamodb Work Like They Should
Teams pair cloud functions and dynamodb to run fast code across clouds with low latency. A Google Cloud function assumes a temporary AWS role to read or write table items. This setup lets your app process events in one cloud and store state in another. You do not need static keys when you link identity providers across both platforms. Instead, your function exchanges its local token for short-lived AWS credentials at runtime. This keeps secrets out of your code and reduces the risk of leaked ke
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.
Teams pair cloud functions and dynamodb to run fast code across clouds with low latency. A Google Cloud function assumes a temporary AWS role to read or write table items.
This setup lets your app process events in one cloud and store state in another. You do not need static keys when you link identity providers across both platforms. Instead, your function exchanges its local token for short-lived AWS credentials at runtime. This keeps secrets out of your code and reduces the risk of leaked keys.
How cloud functions and dynamodb handle identity and data flow
Every Google Cloud function runs with its own dedicated service account identity. When the function starts, it requests a signed identity token from Google Cloud. The function then sends this token to the AWS security token service. AWS checks the token signature against your configured Google identity provider rules.
Once AWS trusts the token, it returns a temporary session role to the function. That role holds specific permissions to read or write items in your DynamoDB tables. The function uses the official AWS software kit to send HTTPS requests with those credentials. Data flows over encrypted transport channels between the serverless runtime and the database API.
Because each request uses standard web protocols, the function does not maintain persistent database pools. This matches the stateless nature of serverless code and scales up or down with traffic. You still need to reuse the client object across warm function runs to save time. Reusing the client avoids repeating the identity token exchange on every single event.
Common failure modes and how to scope permissions
The biggest mistake teams make is putting static AWS keys inside function variables. Static keys never expire on their own and often get copied into local test files. Another common failure is sharing one broad service account across many different functions. If one function has a bug, it can corrupt data in every table.
Teams also run into trouble when they grant wildcard permissions on database tables. A function that only reads order status should never have permission to delete tables. Unlogged queries create another blind spot during security reviews or incident response. Without clear logs, you cannot tell which function changed a specific record.
Cloud Functions IAM + DynamoDB Fine-Grained Access: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
To fix these issues, create one unique service account for each function you deploy. Map each service account to a narrow AWS role with strict table permissions. Limit the role to specific actions on a single table resource name. Turn on data event logs in AWS so every table read or write gets recorded.
Protecting sensitive fields and keeping audit trails clean
Serverless apps often process user records that contain emails, phone numbers, or card numbers. Developers sometimes need to inspect table items or run support scripts against live data. If engineers share the same role as the function, audit logs become hard to read. You lose track of whether a human or an automated trigger changed a row.
Separate human workflows from automated function roles to keep your audit history accurate. When engineers query data for support, data masking rewrites matched fields in results. Masking replaces emails, phone numbers, and national IDs before the response reaches the screen. This reduces exposure of personal data while teams debug production issues.
Govern statements and responses across databases and APIs
Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.
First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.
Frequently asked questions
How should a Google Cloud function authenticate with DynamoDB?
Use workload identity federation so the function exchanges its Google token for temporary AWS credentials. This removes the need to store static AWS keys in your function settings.
Why is my function slow on the first DynamoDB request?
Cold starts require the function to fetch an identity token and assume an AWS role. Initialize your database client outside the main handler to reuse credentials on warm runs.
How do we restrict which tables a function can modify?
Give each function its own service account and map it to a dedicated AWS role. Scope that role Policy to allow only specific actions on one table resource.
Related guides
In this post