The Simplest Way to Make Cloud Functions and Sagemaker Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams pair cloud functions and sagemaker to run machine learning models from serverless events. A function takes incoming data, calls a remote model endpoint, and returns the prediction. This setup lets developers build fast apps without managing heavy servers. Google Cloud handles the web event, while AWS hosts the trained model. Getting the two clouds to talk safely takes careful planning. You must link identities, lock down network paths, and watch every data request. How cloud functions a

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 sagemaker to run machine learning models from serverless events. A function takes incoming data, calls a remote model endpoint, and returns the prediction.

This setup lets developers build fast apps without managing heavy servers. Google Cloud handles the web event, while AWS hosts the trained model. Getting the two clouds to talk safely takes careful planning. You must link identities, lock down network paths, and watch every data request.

How cloud functions and sagemaker share identity and data

Linking two clouds starts with how they trust each other. In the past, engineers put static AWS keys inside Google Cloud variables. That old habit creates big risks if a key leaks. A better path uses workload identity federation between the two cloud providers.

Your function runs with a specific Google service account. When the function starts, it asks Google for a signed identity token. Next, the function sends that token to the AWS security token service. AWS checks the token and gives back a short-term role session. Now the function can call the model endpoint with temporary permissions.

Data flows in a straight line once the function holds a valid session. The function reads the raw input from an event or a web request. It formats the payload into the structure the model expects. Then it sends an HTTPS request to the AWS model endpoint. The model runs the math and sends back the score. The function logs the result and finishes its run.

Common failure modes and how to scope roles

Cross-cloud setups often fail when teams take shortcuts with permissions. Many groups share one broad service account across dozens of functions. If one function has a bug, an attacker can reach every model. Shared roles also make it hard to see which app caused a spike in costs.

Static keys are another common trap in busy engineering teams. Developers paste long-lived keys into code to get a test working fast. Those keys rarely get rotated and often end up in code repos. Broad network rules also cause trouble when endpoints sit open on the public web.

Cloud Functions IAM + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

You can fix these issues by scoping every role to one job. Give each function its own service account in Google Cloud. Map that single account to one tight role in AWS. The AWS role should only allow calling one specific model endpoint. It should never have rights to train models or read storage buckets.

Good logging and data care are just as vital as tight roles. Unlogged calls leave you blind when a model gives bad answers. You also need to watch what data leaves your function. If payloads hold emails, phone numbers, or card numbers, mask those fields first. Data masking rewrites matched fields in results so sensitive strings do not spread.

Keeping network paths and payloads fast and safe

Calling a model across two clouds adds network travel time. If your function sits in Iowa and your model sits in Tokyo, calls lag. Pick regions that sit close together in the same geographic area. This simple step cuts wait times and lowers your cloud bill.

Serverless functions also have strict time limits for each run. If a model takes too long to answer, the function times out. Set clear timeout limits on your web client calls inside the function. When a slow model hangs, the function should fail fast and log the error.

Watch how your function handles memory and network sockets during traffic spikes. Opening a new web session on every single event wastes time and compute. Keep the client session alive in global memory across warm function runs. This habit reuses the secure link and speeds up every prediction call.

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 do I let a Google Cloud Function call an AWS model without static keys?

Use workload identity federation between Google Cloud and AWS. Your function trades its local Google token for a temporary AWS role session at runtime.

How can I reduce lag when calling a model across two clouds?

Place your function and your model endpoint in nearby geographic regions. You should also reuse web connections across warm function runs to skip repeat handshakes.

What permissions does my function need on the AWS side?

Grant the AWS role permission to invoke only the single target model endpoint. Remove all rights to list endpoints, read buckets, or change model settings.

The query runs. The emails stay hidden.