Skip to content

feat(rds): support PostgreSQL aws_lambda extension (#800)#802

Merged
vieiralucas merged 6 commits intomainfrom
worktree-rds-aws-lambda-extension
Apr 27, 2026
Merged

feat(rds): support PostgreSQL aws_lambda extension (#800)#802
vieiralucas merged 6 commits intomainfrom
worktree-rds-aws-lambda-extension

Conversation

@vieiralucas
Copy link
Copy Markdown
Member

@vieiralucas vieiralucas commented Apr 27, 2026

Closes #800.

Summary

  • Lets SQL inside fakecloud-managed RDS PostgreSQL instances invoke fakecloud Lambda functions via the AWS RDS aws_lambda extension shape — same surface LocalStack documents, same return tuple (status_code, payload, executed_version, log_result).
  • New fakecloud-postgres:<major>-<hash> image is built lazily off postgres:<major> the first time a Postgres DB instance is created. The image bakes in plpython3u, aws_commons, and aws_lambda. Hashed tag invalidates cached images when fakecloud changes the embedded extension files.
  • New bridge endpoint POST /_fakecloud/rds/lambda-invoke is what plpython3u calls. It builds an account-scoped ARN and dispatches through the existing LambdaDelivery trait. invocation_type=Event returns 202 immediately and runs the Lambda async.
  • Postgres containers now get --add-host host.docker.internal:<bridge> plus FAKECLOUD_ENDPOINT / FAKECLOUD_ACCOUNT_ID / FAKECLOUD_REGION env vars so the python UDF can find fakecloud across macOS, Linux, and Windows hosts.

User-visible:

CREATE EXTENSION IF NOT EXISTS aws_lambda CASCADE;
SELECT aws_commons.create_lambda_function_arn('my_function');
SELECT * FROM aws_lambda.invoke('my_function', '{"body":"Hello!"}'::json);

Test plan

  • cargo build -p fakecloud clean
  • cargo clippy --workspace --all-targets -- -D warnings clean
  • cargo fmt --all
  • cargo test -p fakecloud-rds passes (119 tests)
  • cargo test -p fakecloud-e2e --test rds_aws_lambda -- --nocapture (CI — needs Docker; first run builds the postgres image which takes ~60s)
  • README, website RDS docs, website service grid synced

Summary by cubic

Adds PostgreSQL aws_lambda extension support in fakecloud RDS so SQL can invoke fakecloud Lambda functions. Ships a lazy-built fakecloud-postgres:<major>-<hash> image with plpython3u, aws_commons, and aws_lambda, plus a bridge endpoint to route calls.

  • New Features

    • Invoke Lambda from SQL via aws_lambda.invoke(...) and aws_commons.create_lambda_function_arn(function_name, region), returning (status_code, payload, executed_version, log_result).
    • Lazy-built fakecloud-postgres image per major version; content-hashed tag auto-invalidates the cache.
    • Bridge POST /_fakecloud/rds/lambda-invoke resolves account-scoped ARNs and routes through existing Lambda delivery; invocation_type=Event returns 202 and runs async.
    • Postgres containers add host.docker.internal and set FAKECLOUD_ENDPOINT/FAKECLOUD_ACCOUNT_ID/FAKECLOUD_REGION for cross-OS connectivity.
    • Docs updated; E2E test covers sync and async paths.
  • Bug Fixes

    • aws_commons.create_lambda_function_arn second parameter is region; composite field names aligned. Composite aws_lambda.invoke wrapper switched to LANGUAGE SQL and now honors the ARN’s region.
    • aws_lambda.invoke (plpython3u) preserves HTTP status codes when the bridge response lacks status_code.
    • E2E test binds json payloads as SQL literals due to tokio-postgres lacking the serde_json feature.
    • TypeScript RDS e2e timeout increased to 180s for the first-run Postgres image build; formatted with Prettier.

Written for commit 447b5de. Summary will update on new commits. Review in cubic

Lets SQL running inside fakecloud-managed RDS PostgreSQL instances
invoke fakecloud Lambda functions via the AWS RDS extension API:

  CREATE EXTENSION IF NOT EXISTS aws_lambda CASCADE;
  SELECT aws_commons.create_lambda_function_arn('my_function');
  SELECT * FROM aws_lambda.invoke('my_function', '{"body":"Hello!"}'::json);

- Bake plpython3u + aws_lambda + aws_commons into a fakecloud-postgres
  image (built lazily off postgres:<major> on first use, hashed tag
  caches per-asset content)
- aws_lambda.invoke (text + composite-typed overloads) calls back to
  fakecloud over host.docker.internal via the new
  POST /_fakecloud/rds/lambda-invoke bridge endpoint
- Bridge resolves account-scoped function ARNs and routes through the
  existing LambdaDelivery trait; Event invocation returns 202 immediately
- E2E test exercises the full path: Lambda + RDS + SQL extension
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 15 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="crates/fakecloud-rds/assets/postgres/aws_lambda--1.0.sql">

<violation number="1" location="crates/fakecloud-rds/assets/postgres/aws_lambda--1.0.sql:52">
P2: HTTP error responses can lose their real status code and return `0` when the error JSON omits `status_code`.</violation>
</file>

<file name="crates/fakecloud-rds/assets/postgres/aws_commons--1.0.sql">

<violation number="1" location="crates/fakecloud-rds/assets/postgres/aws_commons--1.0.sql:13">
P1: Use a `region` field here instead of `qualifier`; this helper is meant to carry the Lambda region, not a version/alias.</violation>
</file>

<file name="website/content/docs/services/rds.md">

<violation number="1" location="website/content/docs/services/rds.md:74">
P2: Don't claim AWS parity here; fakecloud only implements a subset of the RDS Lambda API and its helper signature differs from AWS.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread crates/fakecloud-rds/assets/postgres/aws_commons--1.0.sql Outdated
Comment thread crates/fakecloud-rds/assets/postgres/aws_lambda--1.0.sql
Comment thread website/content/docs/services/rds.md
- aws_commons.create_lambda_function_arn second arg is `region`, not
  `qualifier`, matching the AWS RDS helper. Composite type field
  renamed to match. Composite-typed `aws_lambda.invoke` overload now
  uses the carried region (callers can still override it).
- aws_lambda.invoke plpython3u path captures the HTTP status
  separately so error responses without a `status_code` field surface
  the real code instead of falling back to 0.
- Soften docs: don't claim full AWS parity, the extension is a subset.
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 27, 2026

Codecov Report

❌ Patch coverage is 0% with 220 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/fakecloud-rds/src/runtime.rs 0.00% 123 Missing ⚠️
crates/fakecloud-server/src/main.rs 0.00% 91 Missing ⚠️
crates/fakecloud-rds/src/service.rs 0.00% 6 Missing ⚠️

📢 Thoughts on this report? Let us know!

tokio-postgres in this workspace doesn't enable the with-serde_json-1
feature, so it can't ToSql a Rust &str into a postgres json parameter
(WrongType { postgres: Json, rust: "&str" }). Switch the e2e test to
embed payloads as SQL literals — test fixtures, no injection concern —
and parse the returned payload via ::text + serde_json::from_str.
…E SQL

PL/pgSQL rejected the function with "parameter name 'payload' used more
than once" because both an input arg and a RETURNS TABLE column shared
the name. LANGUAGE SQL doesn't enforce that uniqueness, so we keep the
AWS-compatible argument names and lose the wrapper boilerplate.
The first CreateDBInstance against postgres on a fresh runner now
builds the fakecloud-postgres image (plpython3u + aws_lambda extension
files) before starting the container, which can take ~30-60s. Default
30s vitest timeout was tripping. Bump to 180s; subsequent runs hit the
local cache and are fast.
@vieiralucas vieiralucas merged commit 3c8b97c into main Apr 27, 2026
59 of 61 checks passed
@vieiralucas vieiralucas deleted the worktree-rds-aws-lambda-extension branch April 27, 2026 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support the RDS PostgreSQL aws_lambda extension

1 participant