113 Commits
Author SHA1 Message Date
Ben Rosen 9487a09e3a Lambda Handler errors now reports the root error in field errorType rather than "FunctionError" constant (#587)
### Motivation:

Fix for Issue
[#580](https://github.com/swift-server/swift-aws-lambda-runtime/issues/580),
by making it so that the `errorType` in failed requests will be the type
of the error entity, rather than a hardcoded string of `FunctionError`.
This allows orchestration within step functions that perform retry/catch
logic based on different error output types.

### Modifications:

At a high level, the issue is that swift-aws-lambda-runtime, when an
error is thrown, outputs the errorType as hardcoded to FunctionError.
You can see that
[here](https://github.com/swift-server/swift-aws-lambda-runtime/blob/main/Sources/AWSLambdaRuntime/LambdaRuntimeClient%2BChannelHandler.swift#L337):

```
let errorResponse = ErrorResponse(errorType: Consts.functionError, errorMessage: "\(error)")
```

This PR changes this for all cases to output the type of the error,
rather than the hardcoded string:
```
let errorResponse = ErrorResponse(errorType: "\(type(of: error))", errorMessage: "\(error)")
```
Now, I will show 2 examples with this solution:
```
let runtime = LambdaRuntime {
    (event: Input, context: LambdaContext) in

    enum MyTestErrorType: Error {
        case testError
    }
    
    throw MyTestErrorType.testError
}

// outputs {"errorType":"MyTestErrorType","errorMessage":"testError"}
```
```
let dynamoDB: DynamoDB = DynamoDB(client: .init())

let runtime = LambdaRuntime {
    (event: Input, context: LambdaContext) in

    let _ = try await dynamoDB.putItem(DynamoDB.PutItemInput(item: [:], tableName: ""))
    
    return Output()
}

// outputs {"errorType":"AWSClientError","errorMessage":"ValidationError: Length of PutItemInput.tableName (0) is less than minimum allowed value 1."}
```
2025-10-15 00:30:40 +02:00
Sébastien StormacqandSebastien Stormacq 22f9f6d5e7 Double time interval to allow test to succeed on slow machines (#583)
See https://github.com/swift-server/swift-aws-lambda-runtime/issues/582

Co-authored-by: Sebastien Stormacq <stormacq@amazon.lu>
2025-10-13 19:40:44 +02:00
Fabian Fett 191e27b0a0 Fix compile on macOS (#559)
We need to require ServiceLifecycle 2.8.0.
2025-09-04 15:24:15 +02:00
Sébastien Stormacq d8ee71fc09 add support for LOCAL_LAMBDA_PORT / HOST(#557)
Allows users to define on which port the Local server listens to, using
the `LOCAL_LAMBDA_PORT` environment variable.

While being at it, I also added `LOCAL_LAMBDA_HOST` if the user wants to
bind on a specific IP address.

I renamed `LOCAL_LAMBDA_SERVER_INVOCATION_ENDPOINT` to
`LOCAL_LAMBDA_INVOCATION_ENDPOINT` for consistency.

### Motivation:

Addresses
https://github.com/swift-server/swift-aws-lambda-runtime/issues/556

### Modifications:

- When run outside of the Lambda execution environment, check for the
value of `LOCAL_LAMBDA_PORT` and passes it down to the Lambda HTTP Local
Server and runtime client.

- Add a unit test 

### Result:

```
LAMBDA_USE_LOCAL_DEPS=../.. LOCAL_LAMBDA_PORT=8888 swift run                  

2025-09-01T21:55:22+0200 info LambdaRuntime: host="127.0.0.1" port=8888 [AWSLambdaRuntime] Server started and listening
```
2025-09-03 18:22:57 +02:00
Sébastien Stormacq d42ae6975e Refactor the Swift Settings in Package.swift (#558)
- Use the new Swift 6 `@available` macro to remove requirement on
`.platform` in Package.swift.
- DRY: define the swift settings once for all in `Package.swift`

### Motivation:

- Remove the requirement to build on macOS 15 in `Package.swift`. This
allows library builders and end users to be more flexible on their
dependency requirements.
- The code is optionally compiled on macOS 15 and Linux, but SPM don't
enforce it anymore.
- Avoid repeating ourself. Be sure the same settings are applied on all
targets.

### Modifications:

- Create a `var swiftSetting: [SwiftSettings]` and reuse it for all
targets.
- Use `AvailabilityMacro=LambdaSwift 2.0:macOS 15.0`
- Add this on top of the majority struct / classes
```swift
#if swift(>=6.1)
@available(LambdaSwift 2.0, *)
#endif
```
### Result:

When using Swift 6.1, there is no more SPM dependency on macOS 15
2025-09-03 18:00:24 +02:00
Sébastien Stormacq ec28c96696 Rename Tests' timeout() function (#555)
Fixes
https://github.com/swift-server/swift-aws-lambda-runtime/issues/553
2025-09-01 13:31:45 +02:00
Sébastien Stormacq efc4cd16bf Propagate Connection Closed Information up to top-level (fix #465) (#545)
This PR implements a mechanism to propagate connection loss information
from the Lambda runtime client to the runtime loop, enabling termination
without backtrace when the connection to the Lambda control plane (or a
Mock Server) is lost.

The changes are:

- When the connection is lost,
`ChannelHandlerDelegate.channelInnactive()` now correctly calls
`resume(throwing:)` on the ending continuation, for all states
(`.waitingForNextInvocation ` and `.sentResponse`). This eliminates the
hangs on connection lost..

- I added top-level error handling on `LambdaRuntime._run()` 

- Add a unit test to check that either
`LambdaruntimeError.connectionToControlPlaneLost`, a `ChannelError`, or
an `IOError` is thrown when the server closes the connection
2025-09-01 12:21:13 +02:00
Sébastien Stormacq 323b3f2ac2 fix: Fix deadline header with correct instant value (#551) (#552)
Instant's value now correctly prints as an EPOCH number

### Motivation:

A regression was introduced by
https://github.com/swift-server/swift-aws-lambda-runtime/pull/540. The
HTTP headers returned by `LocalServer` contained an invalid
representation of the Lamba Deadline.

See https://github.com/swift-server/swift-aws-lambda-runtime/issues/551

### Modifications:

- Add `CustomStringConvertible` to `LambdaClock.Instant` to just print
the `Int64` value
- add a unit test 

### Result:

The runtime works correctly with the new `LambdaClock`
2025-08-24 13:37:24 +02:00
Sébastien Stormacq 262c3b539a Revert streaming codable handler and provide it as an example, not an API (#549)
Revert streaming codable handler change and propose it as an example
instead of an handler API.

**Motivation:**
I made a mistake when submitting this PR 
https://github.com/swift-server/swift-aws-lambda-runtime/pull/532

It provides a Streaming+Codable handler that conveniently allows
developers to write handlers with `Codable` events for streaming
functions.

This is a mistake for three reasons:

- This is the only handler that assumes a Lamba Event structure as
input. I added a minimal `FunctionUrlRequest` and `FunctionURLResponse`
to avoid importing the AWS Lambda Events library. It is the first
handler to be event-specific. I don't think the runtime should introduce
event specific code.

- The handler only works when Lambda functions are exposed through
Function URLs. Streaming functions can also be invoke by API or CLI.

- The handler hides `FunctionURLRequest` details (HTTP headers, query
parameters, etc.) from developers

Developers were unaware they were trading flexibility for convenience

The lack of clear documentation about these limitations led to incorrect
usage patterns and frustrated developers who needed full request control
or were using other invocation methods.

**Modifications:**
- Removed the Streaming+Codable API from the library
- Moved the Streaming+Codable code to an example
- Added prominent warning section in the example README explaining the
limitations
- Clarified when to use Streaming+Codable vs ByteBuffer approaches
- Added decision rule framework to help developers choose the right
approach

**Result:**
The only API provided by the library to use Streaming Lambda functions
is exposing the raw `ByteBuffer` as input, there is no more `Codable`
handler for Streaming functions available in the API. I kept the
`Streaming+Codable` code an example.

After this change, developers have clear guidance on when to use each
streaming approach:

- Use streaming codable for Function URL + JSON payload + no request
details needed
- Use ByteBuffer StreamingLambdaHandler for full control, other
invocation methods, or request metadata access

This prevents misuse of the API and sets proper expectations about the
handler's capabilities and limitations, leading to better developer
experience and fewer integration issues.
2025-08-07 10:51:21 +02:00
Sébastien Stormacq 447c1e4db1 Remove dependency on DispatchWallTime (fix #384) (#540)
Fix
[#384](https://github.com/swift-server/swift-aws-lambda-runtime/issues/384)

Note: this PR introduces an API change that will break Lambda functions
using `LambdaContext`, we should integrate this change during the beta
otherwise it will require a major version bump.

### Motivation:

`DispatchWallTime` has no public API to extract the time in
milliseconds, making it a dead end.
Previous implementation used the internal representation of time inside
`DispatchWallTime` to extract the value, creating a risk if its
implementation will change in the future.
Moreover, the use of `DispatchWallTime` obliges users to import the
`Dispatch` library or `Foundation`.

Old Code:
```
extension DispatchWallTime {
    @usableFromInline
    init(millisSinceEpoch: Int64) {
        let nanoSinceEpoch = UInt64(millisSinceEpoch) * 1_000_000
        let seconds = UInt64(nanoSinceEpoch / 1_000_000_000)
        let nanoseconds = nanoSinceEpoch - (seconds * 1_000_000_000)
        self.init(timespec: timespec(tv_sec: Int(seconds), tv_nsec: Int(nanoseconds)))
    }

    var millisSinceEpoch: Int64 {
        Int64(bitPattern: self.rawValue) / -1_000_000
    }
}
```

Issue
[#384](https://github.com/swift-server/swift-aws-lambda-runtime/issues/384)
has a long discussion about possible replacements, including creating a
brand new `UTCClock`, which I think is an overkill for this project.

Instead, I propose this simple implementation, based on two assumptions:

- AWS always sends the time in milliseconds since Unix Epoch (1st Jan
1970) ([Lambda Runtime API
documentation](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html#runtimes-api-next))
- AWS always uses UTC time (not only for Lambda, this is a general rule
for all AWS APIs) ([TZ=UTC on
Lambda](https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html))

Therefore, this library just needs to store and make math on
milliseconds since epoch, without having to care about timezone.

I had two possibilities to implement the storage and the math on
milliseconds since Unix Epoch: either I could use an `UInt64` (as does
[the Rust
implementation](https://github.com/awslabs/aws-lambda-rust-runtime/blob/aff8d883c62997ef2615714dce9f7ddfd557147d/lambda-runtime/src/types.rs#L70))
or I could use a standard Swift type, such as `Duration`.

`Duration` is a good candidate for this because 1/ the time we receive
from the Lambda Service API is indeed a duration between 1/1/1970 and
the execution deadline for the Lambda function, expressed in
milliseconds, 2/ it gives a strong type that can be verified by the
compiler, and 3/ it is possible to do basic arithmetic operations and
compare two values.

As an additional benefit, it allows library users to not import
`Dispatch` or `Foundation`

### Modifications:

I made two changes:

1. I extend the `Duration` type to provide us with simple unix epoch
time manipulation functions and values.

```swift
extension Duration {
    /// Returns the time in milliseconds since the Unix epoch.
    @usableFromInline
    static var millisSinceEpoch: Duration {
        var ts = timespec()
        clock_gettime(CLOCK_REALTIME, &ts)
        return .milliseconds(Int64(ts.tv_sec) * 1000 + Int64(ts.tv_nsec) / 1_000_000)
    }

    /// Returns a Duration between Unix epoch and the distant future
    @usableFromInline
    static var distantFuture: Duration {
        // Use a very large value to represent the distant future
        millisSinceEpoch + Duration.seconds(.greatestFiniteMagnitude)
    }

    /// Returns the Duration in milliseconds
    @usableFromInline
    func milliseconds() -> Int64 {
        Int64(self / .milliseconds(1))
    }

    /// Create a Duration from milliseconds since Unix Epoch
    @usableFromInline
    init(millisSinceEpoch: Int64) {
        self = .milliseconds(millisSinceEpoch)
    }
}
```

3. I replaced all references to `DispatchWallTime` by `Duration` 

### Result:

No more `DispatchWallTime`
No dependencies on Foundation, as I use `clock_gettime()` to get the
epoch from the system clock.
2025-08-05 09:12:11 +02:00
Sébastien StormacqandKonrad `ktoso` Malawski bae9f27ccb Use a struct for ClientContext (fix #169) (#539)
Do not use a String for Lambdacontext.ClientContext, use a struct instead.
Fix for https://github.com/swift-server/swift-aws-lambda-runtime/issues/169

Note: this PR introduces an API change that will break function using
`LambdaContext`, we should integrate this change during the beta
otherwise it will require a major version bump.

### Motivation:

Let the compiler detect type errors for us

### Modifications:

- Create a struct for ClientContext and it's embedded ClientApplication
- add three unit test to validate the struct 

### Result:

No more String?

---------

Co-authored-by: Konrad `ktoso` Malawski <konrad.malawski@project13.pl>
2025-08-04 08:24:46 +02:00
Sébastien Stormacq 9287d56e60 [core] Implement Lambda streaming with custom HTTP headers (#521)
Fix https://github.com/swift-server/swift-aws-lambda-runtime/issues/520
2025-07-24 15:03:29 +04:00
Sébastien StormacqandTim Condon 412a345bdd [core] Add user-facing API for Streaming Lambda functions that receive JSON events (#532)
Add user-facing API for Streaming Lambda functions that receives JSON
events

### Motivation:

Streaming Lambda functions developed by developers had no choice but to
implement a handler that receives incoming data as a `ByteBuffer`. While
this is useful for low-level development, I assume most developers will
want to receive a JSON event to trigger their streaming Lambda function.

Going efficiently from a `ByteBuffer` to a Swift struct requires some
code implemented in the `JSON+ByteBuffer.swift` file of the librray. We
propose to further help developers by providing them with a new
`handler()` function that directly receives their `Decodable` type.

### Modifications:

This PR adds a public facing API (+ unit test + updated README) allowing
developers to write a handler method accepting any `Decodable` struct as
input.

```swift
import AWSLambdaRuntime
import NIOCore

// Define your input event structure
struct StreamingRequest: Decodable {
    let count: Int
    let message: String
    let delayMs: Int?
}

// Use the new streaming handler with JSON decoding
let runtime = LambdaRuntime { (event: StreamingRequest, responseWriter, context: LambdaContext) in
    context.logger.info("Received request to send \(event.count) messages")
    
    // Stream the messages
    for i in 1...event.count {
        let response = "Message \(i)/\(event.count): \(event.message)\n"
        try await responseWriter.write(ByteBuffer(string: response))
        
        // Optional delay between messages
        if let delay = event.delayMs, delay > 0 {
            try await Task.sleep(for: .milliseconds(delay))
        }
    }
    
    // Finish the stream
    try await responseWriter.finish()
    
    // Optional: Execute background work after response is sent
    context.logger.info("Background work: processing completed")
}

try await runtime.run()
```

This interface provides:
- **Type-safe JSON input**: Automatic decoding of JSON events into Swift
structs
- **Streaming responses**: Full control over when and how to stream data
back to clients
- **Background work support**: Ability to execute code after the
response stream is finished
- **Familiar API**: Uses the same closure-based pattern as regular
Lambda handlers

Because streaming Lambda functions can be invoked either directly
through the API or through Lambda Function URL, this PR adds the
decoding logic to support both types, shielding developers from working
with Function URL requests and base64 encoding.

We understand these choice will have an impact on the raw performance
for event handling. Those advanced users that want to get the maximum
might use the existing `handler(_ event: ByteBuffer, writer:
LambaStreamingWriter)` function to implement their own custom decoding
logic.

This PR provides a balance between ease of use for 80% of the users vs
ultimate performance, without closing the door for the 20% who need it.

### Result:

Lambda function developers can now use arbitrary `Decodable` Swift
struct or Lambda events to trigger their streaming functions. 🎉

---------

Co-authored-by: Tim Condon <0xTim@users.noreply.github.com>
2025-07-23 19:03:25 +04:00
Sébastien Stormacq db7e7897eb [test] Add a test for cancellable (#529)
- Add a test on `LambdaRuntime` for cancellable.
- Move the service life cycle test to its own file
2025-07-21 15:15:55 +02:00
Sébastien Stormacq dede067fa1 [tests] minor changes, mostly syntaxic (#530)
tiny syntax changes in the test suite
2025-07-12 11:30:04 +02:00
344d30b401 [core] Only one LambdaRuntime.run() can be called at a time (fix #507) (#508)
This is a proposal to fix issue #507 

**changes**
- `LambdaRuntime.init()` uses a `Mutex<Bool>` to make sure only one
instance is created
- `LambdaRuntime.init()` can now throw an error in case an instance
already exists (I did not use `fatalError()` to make it easier to test)
- All `convenience init()` methods catch possible errors instead of
re-throwing it to a void breaking the user-facing API
- Renamed existing `LambdaRuntimeError` to `LambdaRuntimeClientError`
- Introduced a new type `LambdaRuntimeError` to represent the double
initialization error

---------

Co-authored-by: Fabian Fett <fabianfett@apple.com>
Co-authored-by: Adam Fowler <adamfowler71@gmail.com>
2025-07-04 13:55:58 +00:00
Adam Fowler b2811a5e1a Add support for local server graceful shutdown (#519)
- Add ServiceLifecycle version of `LambdaRuntime.run` that wraps
internal `_run` call in `cancelOnGracefulShutdown`
- Add cancellation handlers for shutting down existing connections in
Local lambda
- Added test for lambda graceful shutdown

### Motivation:

Ensure local lambda supports graceful shutdown
2025-06-29 09:05:15 +02:00
Sébastien Stormacq a616996722 [test] add a unit test for the LambdaHTTPServer Pool (#500) 2025-06-28 14:11:28 +02:00
Sébastien StormacqandCopilot 935ea0fe91 Remove dependency on XCTest (#516)
Remove dependency on XCTest

### Motivation:

As 6.1 does not include XCTest anymore, finish the migration to Swift
testing

### Modifications:

Replace XCTest by Swift Testing in two files

### Result:

`swift test` works on 6.1.2

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-06-28 13:09:44 +02:00
Fabian Fett 3ce0a873e3 Attach requestID to logger (#497) 2025-03-07 07:34:05 +01:00
Sébastien Stormacq ae06d59539 cleanup unused code (#498) 2025-03-07 06:48:00 +01:00
Sébastien Stormacq bba711bd18 remove mentions of LambdaRuntImeCore (#495)
Cleanup code from mentions of `LambdaRuntimeCore`
2025-03-06 18:50:32 +01:00
Sébastien Stormacq bf02bcec9a declare user agent string only once (#493)
The user-agent string was repeated at 5+ different places in the source
code.
I defined it as a constant in the `ControlPlaneRequest` struct where
other similar constant have been defined and make sure the rest of the
code only uses that constant.

This should address
https://github.com/swift-server/swift-aws-lambda-runtime/issues/492
2025-03-06 16:52:42 +01:00
Fabian Fett 0a75e0f9cc Use package traits when using Swift 6.1 (#490) 2025-03-06 09:52:23 +01:00
61cd5d54da [core] Add cancellation handling for nextInvocation() (#459)
Allow `LambdaChannelHandler.nextInvocation` to be cancelled.

### Motivation:

If we want to use ServiceLifecycle with the lambda runtime the lambda
runtime needs to be cancellable either via a ServiceLifecycle graceful
shutdown or via Task cancellation. To avoid bringing in the
ServiceLifecycle dependency this PR adds cancellation via Task
cancellation handler.

### Modifications:

Add `withTaskCancellationHandler` to nextInvocation which calls close on
cancel.
In `LambdaChannelHandler.channelInactive` resume continuation if state
is `waitingForNextInvocation`
Added `LambdaRuntimeClientTests.testCancellation`

### Result:

You can now cancel the runtime while it is waiting for the next
invocation.

---------

Co-authored-by: Fabian Fett <fabianfett@apple.com>
Co-authored-by: Sébastien Stormacq <sebastien.stormacq@gmail.com>
2025-02-27 17:03:41 +01:00
Tobias 25eb6e16de Explicitly only use FoundationEssentials where possible (#436)
We want that the runtime only depends on `FoundationEssentials` where
available (ie. on linux) to ensure small binary size.

### Motivation:

Smaller binary size is good for lambda deployment and cold-start times.
The runtime should only depend on `FoundationEssentials`.

### Modifications:

- replace `import Foundation` with `import FoundationEssentials` if
`FoundationEssentials` is available.
- I also applied the same treatment to tests to ensure that catch error
where tests run on linux and we use API that is only available in
`Foundation` which easily happens when you develop on macOS (where
always full `Foundation` is available).

### Result:

This should allow builds without linking full `Foundation`.
2024-12-20 15:21:33 +01:00
Fabian Fett 4295e51bbb Opt into Swift 6 language mode for most targets (#356)
* Opt into Swift 6 language mode for most targets

* fix parameter order to allow trailing closure syntax
2024-10-08 19:40:12 +02:00
Fabian Fett 0dcb143557 Use Swift Testing for InvocationTests (#362) 2024-09-06 12:38:54 +02:00
Fabian Fett 757815bc6b Use Swift Testing in LambdaRequestIDTests (#360) 2024-09-06 12:30:50 +02:00
aryan-25 2abd9b5d33 Remove "New" prefix from v2 additions (#357) 2024-09-05 16:00:19 +02:00
Fabian Fett ddb703946c Remove old API (#355) 2024-09-04 18:28:53 +02:00
Fabian Fett 7a8c0f22c0 New async runtime client (#348) 2024-09-04 15:57:58 +02:00
Fabian Fett dd059f19ac Add new withMockServer test resource method (#352) 2024-09-04 15:20:58 +02:00
aryan-25 4b45451dc1 Add new handler protocols + Codable support (#351) 2024-09-04 13:46:00 +02:00
aryan-25andFabian Fett b2da91df46 Add runLoop function (#347)
Co-authored-by: Fabian Fett <fabianfett@apple.com>
2024-09-02 13:53:45 +02:00
Fabian Fett 223c3bab89 Don't use hardcoded port for MockServer (#350) 2024-08-30 19:35:05 +02:00
aryan-25 0f68ed5c0c Introduce LambdaRuntimeClientProtocol (#344) 2024-08-28 14:53:02 +02:00
ab8166a39d [CI] Add GHA CI and release flow (#340)
Co-authored-by: Fabian Fett <fabianfett@apple.com>
Co-authored-by: Sébastien Stormacq <sebastien.stormacq@gmail.com>
Co-authored-by: Mahdi Bahrami <github@mahdibm.com>
2024-08-26 16:36:07 +02:00
Sébastien Stormacq 8676c8933a apply swiftformat (#342)
* apply swiftformat

* update dep on Swift Docc to v1.3.0

* force usage of swift docc plugin 1.3.0
2024-08-26 12:25:41 +02:00
Alessio BurattiandSébastien Stormacq 79fa2c2bee [Draft] Detached tasks (#334)
* First prototype

* Fix build

* Removes task cancellation

https://github.com/swift-server/swift-aws-lambda-runtime/pull/334#discussion_r1666713889

* Force user to handle errors

https://github.com/swift-server/swift-aws-lambda-runtime/pull/334#discussion_r1666712903

* Remove EventLoop API

https://github.com/swift-server/swift-aws-lambda-runtime/pull/334#discussion_r1666712244

* Make DetachedTaskContainer internal

https://github.com/swift-server/swift-aws-lambda-runtime/pull/334#discussion_r1666710596
https://github.com/swift-server/swift-aws-lambda-runtime/pull/334#discussion_r1666706576

* Removes @unchecked Sendable

https://github.com/swift-server/swift-aws-lambda-runtime/pull/334#discussion_r1666707646

* Invoke awaitAll() from async context

* Fix ambiguous expression type for swift 5.7

* Fix visibility of detachedBackgroundTask

* Add swift-doc

* Add example usage to readme

* Add tests

---------

Co-authored-by: Sébastien Stormacq <sebastien.stormacq@gmail.com>
2024-08-23 18:50:22 +02:00
tomer doron 8d9f44b783 allow custom initialization of the HandlerType of the LambdaRuntime (#310)
Motivation:

Provide the flexibility for custom initialization of the HandlerType as this will often be required by higher level frameworks.

Modifications:
* Modify the LambdaRuntime type to accept a closure to provide the handler rather than requiring that it is provided by a static method on the Handler type
* Update downstream code to use HandlerProvider
* Update upstream code to support passing Handler Type of Handler Provider
* Add and update tests

Originally suggested and coded by @tachyonics in https://github.com/swift-server/swift-aws-lambda-runtime/pull/308
2024-01-18 13:48:10 -08:00
tomer doron a5fb165f65 fix concurrency api usage (#282)
motivation: cleanup incorrect concurent code in test

changes: use .get instead of .wait
2023-01-10 16:24:11 -08:00
c915322eca API Refactoring (#273)
motivation: define stable API in preperation 1.0 release

changes:
* require swift 5.7, remove redundant backwards compatibility code
* make LambdaHandler, EventLoopLambdaHandler, and ByteBufferLambdaHandler disjointed protocols to reduce API surface area
* create coding wrappers for LambdaHandler and EventLoopLambdaHandler to provide bridge to ByteBufferLambdaHandler
* reuse output ByteBuffer to reduce allocations
* add new SimpleLambdaHandler with no-op initializer for simple lambda use cases
* update callsites and tests
* update examples

Co-authored-by: Yim Lee <yim_lee@apple.com>
Co-authored-by: Fabian Fett <fabianfett@apple.com>
2022-11-09 10:08:36 -08:00
Fabian Fett ac52960abd Initialize LambdaRuntime with concrete HandlerType + Docu fixes (#260) 2022-04-20 22:14:03 +02:00
tomer doron e5b44962bd Prefix data structures with Lambda instead of namespacing them (#256)
motivation: consisten naming convention

changes:
* Lambda.InitializationContext -> LambdaInitializationContext
* Lambda.Runner -> LambdaRunner
* Lambda.Configuration -> LambdaConfiguration
* Lambda.RuntimeError -> LambdaRuntimeError
* adjust call sites, tests, and examples
2022-04-15 13:33:54 +02:00
tomer doron 3c3529b4dc adoption of sendable (#252)
motivation: adopt to sendable requirments in swift 5.6

changes:
* define sendable shims for protocols and structs that may be used in async context
* adjust tests
* add a test to make sure no warning are emitted
2022-04-14 09:39:00 -07:00
tomer doron 4d0bba4617 termination handler (#251)
motivation: make it simpler to register shutdown hooks

changes:
* introduce Terminator helper that allow registering and de-registaring shutdown handlers
* expose the new terminator hanler on the InitializationContext and deprecate ShutdownContext
* deprecate the Handler::shutdown protocol requirment
* update the runtime code to use the new terminator instead of calling shutdown on the handler
* add and adjust tests
2022-04-13 12:16:26 -07:00
Stefan Nienhuis c1f694f35a Add default value for traceID header (#246)
* Add default value for traceID header
* Implement Invocation traceID test
2022-02-19 14:16:51 -08:00
Fabian Fett d06d22c0e0 Lambda factory as a protocol requirement. (#244) 2022-01-13 19:10:20 +01:00
Fabian Fett 5d235c0a3b Add ControlPlaneRequestEncoder (#239)
Add a new `ControlPlaneRequestEncoder` that encodes all control plane requests into an existing, reused buffer.
2021-12-11 13:35:57 +01:00