Skip to content

Conversation

@sebsto
Copy link
Collaborator

@sebsto sebsto commented Jan 4, 2026

This PR builds on #629 to add convenience structs (Handlers and Adapters) that are Sendable

Changes

  • Added Sendable adapter types: Implemented LambdaHandlerAdapterSendable, LambdaCodableAdapterSendable, and ClosureHandlerSendable - all thread-safe versions of existing adapters that enforce Sendable conformance for concurrent execution environments

  • Enhanced handler protocols for concurrency: Extended handler protocols to support Sendable constraints and concurrent response writing through LambdaResponseStreamWriter & Sendable, enabling safe multi-threaded invocation processing

  • Created comprehensive Lambda Managed Instances examples: Built three demonstration functions showcasing concurrent execution capabilities, streaming responses, and background processing patterns specific to the new managed instances deployment model

Context
Lambda Managed Instances support multi-concurrent invocations where multiple invocations execute simultaneously within the same execution environment. The runtime now detects the configured concurrency level and launches the appropriate number of RICs to handle concurrent requests efficiently.

When AWS_LAMBDA_MAX_CONCURRENCY is 1 or unset, the runtime maintains the existing single-threaded behaviour for optimal performance on traditional Lambda deployments.

@sebsto sebsto self-assigned this Jan 4, 2026
@sebsto sebsto added the 🆕 semver/minor Adds new public API. label Jan 4, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds support for Lambda Managed Instances, enabling Swift Lambda functions to handle multiple concurrent invocations within a single execution environment. The implementation introduces thread-safe runtime components with Sendable conformance while maintaining backward compatibility with the existing single-threaded Lambda runtime.

Key Changes:

  • Introduced LambdaManagedRuntime class with thread-safe handler execution supporting concurrent invocations based on the AWS_LAMBDA_MAX_CONCURRENCY environment variable
  • Created Sendable-conforming adapter types (LambdaHandlerAdapterSendable, LambdaCodableAdapterSendable, LambdaJSONEventDecoderSendable, LambdaJSONOutputEncoderSendable) to ensure safe concurrent execution
  • Refactored LambdaRuntime to extract reusable methods (startRuntimeInterfaceClient, startLocalServer) shared with LambdaManagedRuntime

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
scripts/extract_aws_credentials.sh Removed script (likely no longer needed)
Tests/AWSLambdaRuntimeTests/Utils.swift Added test helper for creating LambdaContext instances
Tests/AWSLambdaRuntimeTests/LambdaManagedRuntimeTests.swift Comprehensive tests for concurrent handler execution, Sendable constraints, and thread-safe adapters
Sources/AWSLambdaRuntime/Runtime/LambdaRuntime.swift Refactored to extract reusable methods and renamed atomic guard variable for clarity
Sources/AWSLambdaRuntime/Runtime/LambdaRuntime+Codable.swift Added Sendable conformance to VoidEncoder
Sources/AWSLambdaRuntime/ManagedRuntime/LambdaManagedRuntimeHandlers.swift Introduced ClosureHandlerSendable for thread-safe closure-based handlers
Sources/AWSLambdaRuntime/ManagedRuntime/LambdaManagedRuntime.swift Core implementation of managed runtime with concurrency detection and multiple RIC support
Sources/AWSLambdaRuntime/ManagedRuntime/LambdaManagedRuntime+ServiceLifecycle.swift ServiceLifecycle integration for managed runtime
Sources/AWSLambdaRuntime/ManagedRuntime/LambdaManagedRuntime+Codable.swift Thread-safe adapter implementations for managed runtime
Sources/AWSLambdaRuntime/FoundationSupport/LambdaRuntime+JSON.swift Convenience initializers for LambdaRuntime with JSON encoding/decoding
Sources/AWSLambdaRuntime/FoundationSupport/LambdaManagedRuntime+JSON.swift Sendable JSON encoder/decoder implementations and convenience initializers for managed runtime
Sources/AWSLambdaRuntime/FoundationSupport/LambdaHandler+JSON.swift Extracted common JSON handler support to separate file
[email protected] Added ManagedRuntimeSupport trait and updated dependency versions
Package.swift Added ManagedRuntimeSupport trait to default enabled traits and updated dependency versions
Examples/Streaming+Codable/Tests/LambdaStreamingCodableTests.swift Updated logger label for consistency
Examples/ManagedInstances/template.yaml SAM template for deploying managed instances examples
Examples/ManagedInstances/Sources/Streaming/main.swift Streaming response example for managed instances
Examples/ManagedInstances/Sources/HelloJSON/main.swift Simple JSON request/response example for managed instances
Examples/ManagedInstances/Sources/BackgroundTasks/main.swift Background processing example for managed instances
Examples/ManagedInstances/README.md Documentation for deploying and testing managed instances examples
Examples/ManagedInstances/Package.swift Package definition for managed instances examples
Examples/ManagedInstances/.gitignore Ignore patterns for managed instances examples
.github/workflows/pull_request.yml Added ManagedInstances to CI examples list
Comments suppressed due to low confidence (3)

Sources/AWSLambdaRuntime/FoundationSupport/LambdaManagedRuntime+JSON.swift:149

  • Inconsistent default logger label. This initializer uses "LambdaRuntime" as the default logger label, but the previous initializer on line 122 uses "LambdaManagedRuntime". For consistency, this should likely also use "LambdaManagedRuntime" since it's an extension on LambdaManagedRuntime.
    Sources/AWSLambdaRuntime/FoundationSupport/LambdaManagedRuntime+JSON.swift:207
  • Inconsistent default logger label. This initializer uses "LambdaRuntime" as the default logger label, but line 122 uses "LambdaManagedRuntime". For consistency across the LambdaManagedRuntime extension, this should likely also use "LambdaManagedRuntime".
    Sources/AWSLambdaRuntime/FoundationSupport/LambdaManagedRuntime+JSON.swift:176
  • Inconsistent default logger label. This initializer uses "LambdaRuntime" as the default logger label, but line 122 uses "LambdaManagedRuntime". For consistency across the LambdaManagedRuntime extension, this should likely also use "LambdaManagedRuntime".

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sebsto sebsto requested review from adam-fowler and removed request for fabianfett January 13, 2026 09:08
@sebsto sebsto marked this pull request as draft January 13, 2026 09:18
@sebsto sebsto removed the request for review from adam-fowler January 13, 2026 09:18
Sebastien Stormacq added 6 commits January 13, 2026 11:16
- Remove deleted Lambda+JSON.swift file
- Split JSON support into separate files:
  - LambdaRuntime+JSON.swift for regular runtime
  - LambdaManagedRuntime+JSON.swift for managed runtime
- Clean up ManagedInstances example directory
@sebsto sebsto changed the title Add support for Lambda Managed Instances without changing the public API Add support for Lambda Managed Instances without changing the public API [Convenience + Example] Jan 13, 2026
@sebsto sebsto marked this pull request as ready for review January 13, 2026 17:35
@sebsto sebsto requested a review from fabianfett January 13, 2026 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🆕 semver/minor Adds new public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant