Releases: awslabs/swift-aws-lambda-runtime
2.7.0
The archive plugin now supports Apple's container CLI as an alternative to Docker for building Lambda deployment packages.
Pass --container-cli container to use it instead of the default Docker path. The plugin translates commands accordingly, using container image pull and container run under the hood.
To use it:
swift package --disable-sandbox --allow-network-connections docker archive --container-cli containerNote that even when using Apple's container CLI, you still need to pass --allow-network-connections docker on the command line. This is a SwiftPM limitation, not something the plugin controls. In a future version, SPM will not prompt for specific authorization when --disable-sandbox is specified (see swiftlang/swift-package-manager#9763)
Docker remains the default. If you don't pass --container-cli, nothing changes.
What's Changed
SemVer Minor
- feat: Added support for apple container by @manojmahapatra in #647
Full Changelog: 2.6.3...2.7.0
2.6.3
We fixed a bug and improved the life for those of you building on Amazon Linux 2023.
-
[bug] the local HTTP server you use for testing your functions locally was not forwarding the HTTP headers you passed to the Lambda function. This prevented you local testing of function that expects some specific HTTP headers or to test Lambda Multi Tenant. @manojmahapatra fixed this and added a Multi Tenant example to show you how to pass test multi tenant functions locally, with
curl. This is Manoj's first contribution to the project. Welcome and thank you. -
[plugin] : the
archiveplugin now correctly recognises it runs on Amazon Linux 2023 and doesn't attempt to build with docker anymore. Thank you @0xTim for having reported that.
As usual, let us know your feedback, comments, or suggestions.
What's Changed
SemVer Patch
- Archive plugin supports Amazon Linux 2023 in addition to Amazon Linux 2 by @sebsto in #646
- Fix more crashes in archive by @sebsto in #642
- fix: Local Server should pass HTTP headers down to the Lambda Runtime by @manojmahapatra in #643
New Contributors
- @manojmahapatra made their first contribution in #643
Full Changelog: 2.6.2...2.6.3
2.6.2
This is a patch release that fixes two rare concurrency issues. One was when using the swift package archive plugin. And the second one was when the server (Lambda control plane) closes the HTTP connection, which practically never happens, except when using the local HTTP server during your tests.
I observed these problems mostly in our CI/CD pipeline.
Let us know if you also experimented crashes when the server closes the HTTP connection or with the archive plugin.
What's Changed
SemVer Patch
- Fix for swift test : _Concurrency/Executor.swift:357: Fatal error by @sebsto in #639
- Fix crash on Linux when testing the archive plugin by @sebsto in #641
Full Changelog: 2.6.1...2.6.2
2.6.0
Lambda Managed Instances Support
We're excited to announce support for AWS Lambda Managed Instances in the Swift AWS Lambda Runtime. This new deployment model enables you to run Lambda functions on your current-generation Amazon EC2 instances while maintaining serverless simplicity.
What are Lambda Managed Instances?
Lambda Managed Instances provide EC2 flexibility and cost optimization by running your functions on customer-owned EC2 instances. AWS handles all infrastructure management tasks including instance lifecycle, OS and runtime patching, routing, load balancing, and auto-scaling. The key difference from traditional Lambda is support for concurrent invocations within the same execution environment, allowing multiple requests to be processed simultaneously on the same host.
When to Use Lambda Managed Instances
Lambda Managed Instances are ideal for:
- Sustained workloads where cost optimization through EC2 pricing models is beneficial
- Specialized compute requirements needing specific EC2 instance types (Graviton4, network-optimized instances)
- High-throughput scenarios where concurrent execution improves performance
- Workloads requiring EC2 flexibility while maintaining serverless operational simplicity
Code Changes Required
Migrating to Lambda Managed Instances requires two simple changes:
1. Use LambdaManagedRuntime instead of LambdaRuntime
// Before (standard Lambda)
let runtime = LambdaRuntime {
(event: HelloRequest, context: LambdaContext) in
HelloResponse(greetings: "Hello \(event.name)!")
}
// After (Lambda Managed Instances)
let runtime = LambdaManagedRuntime {
(event: HelloRequest, context: LambdaContext) in
HelloResponse(greetings: "Hello \(event.name)!")
}
try await runtime.run()2. Ensure Handlers are Sendable
Because Lambda Managed Instances support concurrent invocations, your handler functions and structs must conform to Sendable:
struct MyHandler: LambdaWithBackgroundProcessingHandler, Sendable {
typealias Event = MyRequest
typealias Output = MyResponse
func handle(
_ event: Event,
outputWriter: some LambdaResponseWriter<Output>,
context: LambdaContext
) async throws {
try await outputWriter.write(MyResponse(message: "Processed"))
}
}
let adapter = LambdaCodableAdapter(handler: MyHandler())
let runtime = LambdaManagedRuntime(handler: adapter)
try await runtime.run()For simple data structures, the Swift compiler automatically infers Sendable conformance.
Implementation Details
- Thread-safe execution: The runtime detects the configured concurrency level (
AWS_LAMBDA_MAX_CONCURRENCY) and launches the appropriate number of Runtime Interface Clients (RICs) to handle concurrent requests - Backward compatibility: When
AWS_LAMBDA_MAX_CONCURRENCYis 1 or unset, the runtime maintains single-threaded behavior for optimal performance on traditional Lambda deployments - No breaking changes: The public API remains unchanged; existing Lambda functions continue to work without modification
This is a purely additive feature with no breaking changes—existing Lambda functions continue to work without modification. The managed instances support is implemented behind a Swift package trait (ManagedRuntimeSupport) that's enabled by default. If you're concerned about binary size and don't need managed instances support, you can disable this trait in your Package.swift:
dependencies: [
.package(
url: "https://github.com/awslabs/swift-aws-lambda-runtime.git",
from: "2.0.0",
traits: [
// Keep other default traits but exclude ManagedRuntimeSupport
"FoundationJSONSupport",
"ServiceLifecycleSupport",
"LocalServerSupport"
]
),
],
targets: [
.executableTarget(
name: "MyLambda",
dependencies: [
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
]
),
]Examples
The release includes three comprehensive examples in Examples/ManagedInstances/:
- HelloJSON: JSON input/output with structured data types
- Streaming: Response streaming capabilities with concurrent execution
- BackgroundTasks: Long-running background processing after response
See the ManagedInstances example README for deployment instructions using AWS SAM.
Prerequisites
Before deploying to Lambda Managed Instances:
- Create a Lambda Managed Instances capacity provider
- Configure your deployment to reference the capacity provider ARN
Additional Resources
- AWS Lambda Managed Instances Documentation
- Execution Environment Guide
- Swift AWS Lambda Runtime Documentation
What's Changed
SemVer Minor
- Add support for Lambda Managed Instances without changing the public API [CORE] by @sebsto in #629
- Add support for Lambda Managed Instances without changing the public API [Convenience + Example] by @sebsto in #623
Full Changelog: 2.5.3...2.6.0
2.5.3
This patch release fixes two critical race conditions that could cause crashes in production and test environments:
Bug Fixes
- Fixed race condition crash in
LambdaRuntimeClientchannel lifecycle (#632) - Fixed race condition in
Lambda+LocalServercausingNIOAsyncWriterfatal error (#636)
These fixes improve the stability and reliability of the Swift AWS Lambda Runtime, particularly in high-concurrency scenarios.
What's Changed
SemVer Patch
- Fix race condition crash in LambdaRuntimeClient channel lifecycle (Bug #624) by @sebsto in #632
- Fix race condition in Lambda+LocalServer causing NIOAsyncWriter fatal error (Bug #635) by @sebsto in #636
Full Changelog: 2.5.2...2.5.3
2.5.2
Local server test hangs: Fixed race conditions in Pool cancellation logic that caused test suite to hang ~10% of the time
- Individual task cancellations no longer incorrectly cancel all waiting tasks
- Server shutdown now properly cleans up waiting continuations
- Improves reliability of local testing and concurrent invocation handling
Impact: Test suite now runs consistently without hangs. Local server testing is more reliable.
What's Changed
SemVer Patch
Other Changes
- Rename lambda+JSON file by @sebsto in #626
- Refactor LambdaRuntime by @sebsto in #627
- Cleanup script and test example by @sebsto in #628
Full Changelog: 2.5.1...2.5.2
2.5.1
This patch sharpens the developer experience: the payload trace limit is lifted, so you get 6 Mb traces when inspecting Lambda events and responses. In practice, this means clearer insight into real-world payloads, faster root-cause analysis, and fewer blind spots when debugging.
What's Changed
SemVer Patch
Full Changelog: 2.5.0...2.5.1
2.5.0
This release relaxes Sendable constraint on StreamingClosureHandler.
Key changes:
- Removed &
Sendableconformance fromStreamingClosureHandlerstruct - Removed
@Sendableannotation from the closure type used in the handler
What's Changed
SemVer Minor
Other Changes
Full Changelog: 2.4.1...2.5.0
2.4.1
A dot release that mostly fixes the compilation error introduced by a breaking API change in swift Log.
Beside that, here are some newsworthy changes
- Some improvements in the test suite and the CI
- A new example for streaming functions + API Gateway
What's Changed
SemVer Minor
- Fix 565 : HelloWorld and Resource examples now uses Swift 6.2 by @sebsto in #611
- Simplify local dependency injection for examples by @sebsto in #612
- Use Swiftlang's GitHub workflow for testing with Static SDK by @sebsto in #613
- Use Swiftlang's github action for unit tests by @sebsto in #614
- Add Streaming Lambda Examples with API Gateway and Function URL by @sebsto in #615
- Fix after release of swift-log 1.8.0 by @adam-fowler in #619
Other Changes
- fix #609 : [plugin] Update the README and the doc to mention potential credentials error when using the plugin. by @sebsto in #610
- Update commented deps in examples to use runtime v2 by @sebsto in #616
- Fix dependency on HB example by @sebsto in #618
Full Changelog: 2.4.0...2.4.1
2.4.0
This release adds support for AWS Lambda tenant isolation mode.
https://aws.amazon.com/blogs/aws/streamlined-multi-tenant-application-development-with-tenant-isolation-mode-in-aws-lambda/
let runtime = LambdaRuntime {
(event: APIGatewayRequest, context: LambdaContext) -> APIGatewayResponse in
// Extract tenant ID from context
guard let tenantID = context.tenantID else {
return APIGatewayResponse(statusCode: .badRequest, body: "No Tenant ID provided")
}
...See Examples/MultiTenant for a full example.
What's Changed
SemVer Minor
Other Changes
- fix more links by @sebsto in #597
- Fix typo in readme by @sebsto in #599
- Fix broken links by @sebsto in #600
- Add Swift ServiceLifecycle section to the readme by @sebsto in #601
- Add scripts to measure cold start performance by @sebsto in #604
- Makes performance script run on macOS by @sebsto in #603
Full Changelog: 2.3.1...2.4.0