Skip to content

support tenant id in AWS::Lambda::Context#203

Merged
shogo82148 merged 4 commits intomainfrom
support-tenant-id
Dec 11, 2025
Merged

support tenant id in AWS::Lambda::Context#203
shogo82148 merged 4 commits intomainfrom
support-tenant-id

Conversation

@shogo82148
Copy link
Copy Markdown
Owner

@shogo82148 shogo82148 commented Dec 11, 2025

ref. aws/aws-lambda-go#604
https://aws.amazon.com/blogs/compute/building-multi-tenant-saas-applications-with-aws-lambdas-new-tenant-isolation-mode/

Summary by CodeRabbit

  • New Features

    • Support for tenant ID in the AWS Lambda runtime context, exposing a tenant identifier to runtimes.
  • Bug Fixes

    • Fixed typo in the deadline_ms validation error message.
  • Documentation

    • Corrected several public documentation and usage text typos.
  • Tests

    • Added test coverage to verify the tenant ID is surfaced in the runtime context.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 11, 2025

Walkthrough

Propagates tenant ID from the Lambda runtime header lambda-runtime-aws-tenant-id into AWS::Lambda::Context (new tenant_id accessor), adds a test asserting the value, corrects a deadline_ms typo, and makes minor POD text fixes with a changelog entry.

Changes

Cohort / File(s) Summary
Changelog
CHANGELOG.md
Added NEXT entry: "Support tenant id in AWS::Lambda::Context" (#203).
Context & Bootstrap
lib/AWS/Lambda/Context.pm, lib/AWS/Lambda/Bootstrap.pm
Context accepts/stores tenant_id, exposes tenant_id() accessor, includes tenant_id in serialized client_context; Bootstrap reads lambda-runtime-aws-tenant-id / Lambda-Runtime-Aws-Tenant-Id header and passes it into Context; fixed deadine_msdeadline_ms typo.
Tests
t/10_lambda_next.t
Mocked Lambda-Runtime-Aws-Tenant-Id header added and assertion verifying context->tenant_id equals the header value.
Docs (minor)
lib/AWS/Lambda/PSGI.pm
Minor POD typo corrections (non-functional).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Focus review on lib/AWS/Lambda/Context.pm (constructor, accessor, serialization changes) and lib/AWS/Lambda/Bootstrap.pm (header extraction and parameter passing).
  • Verify test t/10_lambda_next.t correctly mirrors header naming and that client_context serialization remains compatible.

Poem

🐇 I sniffed a tenant ID upon the breeze,
I tucked it in Context between the leaves;
Tests thumped a paw, typos hopped aside,
A tiny patch — a rabbit's quiet pride. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'support tenant id in AWS::Lambda::Context' directly and clearly summarizes the main change: adding tenant_id support to the AWS::Lambda::Context module, which aligns with all modified files and the PR's primary objective.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch support-tenant-id

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1b98889 and e235914.

📒 Files selected for processing (4)
  • Changes (1 hunks)
  • lib/AWS/Lambda/Bootstrap.pm (1 hunks)
  • lib/AWS/Lambda/Context.pm (3 hunks)
  • t/10_lambda_next.t (2 hunks)
🔇 Additional comments (7)
Changes (1)

4-4: LGTM!

The changelog entry accurately documents the new tenant ID support feature.

lib/AWS/Lambda/Context.pm (4)

17-17: LGTM!

Good catch on the typo fix in the error message.


21-21: LGTM!

The tenant_id parameter handling is correct and follows the same pattern as other optional fields like trace_id.

Also applies to: 27-27


76-79: LGTM!

The tenant_id accessor method follows the established pattern and correctly exposes the tenant ID value.


115-117: LGTM!

The documentation appropriately includes the new tenant_id field in the usage example.

t/10_lambda_next.t (2)

23-28: LGTM!

The mock response correctly includes the tenant ID header, and the formatting improvements enhance readability.


50-50: LGTM!

The test assertion correctly verifies that the tenant ID is properly extracted from the Lambda runtime header and accessible via the context object.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 50c27eb and 67ec533.

📒 Files selected for processing (2)
  • Changes (1 hunks)
  • lib/AWS/Lambda/Bootstrap.pm (3 hunks)
🔇 Additional comments (2)
Changes (1)

4-4: LGTM!

The changelog entry is clear, follows the project's format, and correctly references PR #203.

lib/AWS/Lambda/Bootstrap.pm (1)

249-249: LGTM!

Good catch on the documentation typos. The corrections improve clarity without affecting functionality.

Also applies to: 264-264

aws_request_id => $h->{'lambda-runtime-aws-request-id'},
invoked_function_arn => $h->{'lambda-runtime-invoked-function-arn'},
trace_id => $h->{'lambda-runtime-trace-id'},
tenant_id => $h->{'lambda-runtime-aws-tenant-id'},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🌐 Web query:

AWS Lambda Runtime API next invocation lambda-runtime-aws-tenant-id header specification

💡 Result:

Short answer — when tenant isolation is enabled, Lambda includes the tenant identifier on invocation deliveries. The standard Invoke API uses X‑Amzn‑Tenant‑Id and the Runtime API returns tenant info on /runtime/invocation/next in a Lambda‑Runtime‑Aws‑Tenant‑Id response header (see the Runtime API and tenant‑isolation docs). [1][2]

Sources:

  • Lambda Runtime API (next invocation /runtime/invocation/next — response headers). [1]
  • Lambda tenant isolation / invoking functions with tenant isolation (X‑Amzn‑Tenant‑Id). [2]

🏁 Script executed:

#!/bin/bash
# Check upstream aws-lambda-go PR #604 for tenant header usage
# First try to get PR details via GitHub API
echo "=== Checking aws-lambda-go repository for tenant header usage ==="
curl -s https://api.github.com/repos/aws/aws-lambda-go/pulls/604 | jq -r '.title, .body' 2>/dev/null | head -20

echo -e "\n=== Searching for tenant in aws-lambda-go main branch ==="
# Check the main repository for how they extract tenant ID
curl -s https://raw.githubusercontent.com/aws/aws-lambda-go/main/lambdacontext/lambda_context.go 2>/dev/null | grep -i tenant -A 3 -B 3

Repository: shogo82148/p5-aws-lambda

Length of output: 596


The header name is correct but should match AWS documentation casing: use Lambda-Runtime-Aws-Tenant-Id instead of lambda-runtime-aws-tenant-id.

According to AWS Lambda Runtime API documentation, the /runtime/invocation/next endpoint returns tenant information in a response header named Lambda-Runtime-Aws-Tenant-Id (with PascalCase-with-hyphens casing). While HTTP header names are case-insensitive in transmission, the code currently uses all lowercase lambda-runtime-aws-tenant-id. This is inconsistent with AWS's official specification format and the standard naming convention used elsewhere in the codebase.

Note: The previous review confusion about X-Amzn-Tenant-Id refers to the standard Invoke API (used when calling Lambda), whereas this code correctly uses the Runtime API header for the runtime environment's /next endpoint response.

🤖 Prompt for AI Agents
In lib/AWS/Lambda/Bootstrap.pm around line 151, the header key is set to
all-lowercase 'lambda-runtime-aws-tenant-id'; update it to match AWS
documentation casing 'Lambda-Runtime-Aws-Tenant-Id' so the code uses the
documented header name while preserving case-insensitive lookup semantics and
keeping consistency with other code that uses PascalCase-with-hyphens for
runtime headers.

@shogo82148 shogo82148 merged commit b95fa43 into main Dec 11, 2025
37 checks passed
@shogo82148 shogo82148 deleted the support-tenant-id branch December 11, 2025 15:45
shogo82148 added a commit that referenced this pull request Dec 13, 2025
Changelog diff is:

diff --git a/Changes b/Changes
index 49a76a3..db60fb4 100644
--- a/Changes
+++ b/Changes
@@ -1,6 +1,8 @@
 Revision history for Perl extension aws-lambda
 
 {{$NEXT}}
+
+0.7.0 2025-12-13T04:33:18Z
     - Support tenant id in AWS::Lambda::Context #203
     - Add support for AWS_LAMBDA_MAX_CONCURRENCY #204
     - Mark Amazon Linux 2 (AL2) based layers as no longer maintained #206
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.

1 participant