Skip to content

Releases: awslabs/swift-aws-lambda-runtime

2.7.0

23 Feb 16:10
6aa4387

Choose a tag to compare

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 container

Note 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

Full Changelog: 2.6.3...2.7.0

2.6.3

18 Feb 14:27
22dd701

Choose a tag to compare

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 archive plugin 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

Full Changelog: 2.6.2...2.6.3

2.6.2

16 Feb 11:23
4a917a7

Choose a tag to compare

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

12 Feb 08:38
190eb81

Choose a tag to compare

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_CONCURRENCY is 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:

  1. Create a Lambda Managed Instances capacity provider
  2. Configure your deployment to reference the capacity provider ARN

Additional Resources

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

27 Jan 10:20
4815273

Choose a tag to compare

This patch release fixes two critical race conditions that could cause crashes in production and test environments:

Bug Fixes

  • Fixed race condition crash in LambdaRuntimeClient channel lifecycle (#632)
  • Fixed race condition in Lambda+LocalServer causing NIOAsyncWriter fatal 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

15 Jan 20:08
34e89b4

Choose a tag to compare

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

Full Changelog: 2.5.1...2.5.2

2.5.1

11 Jan 15:00
634c36e

Choose a tag to compare

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

  • Lift up the trace limit on payload to make it actually useful when debugging by @sebsto in #625

Full Changelog: 2.5.0...2.5.1

2.5.0

01 Jan 16:36
4b4054d

Choose a tag to compare

This release relaxes Sendable constraint on StreamingClosureHandler.

Key changes:

  • Removed & Sendable conformance from StreamingClosureHandler struct
  • Removed @Sendable annotation from the closure type used in the handler

What's Changed

SemVer Minor

  • Remove unnecessary Sendable constraint by @sebsto in #622

Other Changes

Full Changelog: 2.4.1...2.5.0

2.4.1

14 Dec 08:53
1f0888e

Choose a tag to compare

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

21 Nov 20:19
2abe7eb

Choose a tag to compare

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

Full Changelog: 2.3.1...2.4.0