120 Commits

Author SHA1 Message Date
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 Buratti 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
Sébastien Stormacq 872183bbe9 allow compilation with the static linux sdk (musl) (#331) 2024-06-26 10:09:25 +02:00
jsonfry 17a993e3b1 Local lambda invocation endpoint env var (#321)
add #321
2024-05-22 14:37:53 +02:00
Sébastien Stormacq 221978224c Add tracing of request events + mention LOG_LEVEL in README (#315)
* add tracing of request events + mention LOG_LEVEL in README

* fix typo

Co-authored-by: Mahdi Bahrami <github@mahdibm.com>

* clarify the use of env variable and the swift cli

Co-authored-by: Mahdi Bahrami <github@mahdibm.com>

* clarify language about HTTP server

Co-authored-by: Mahdi Bahrami <github@mahdibm.com>

* formatting

Co-authored-by: Mahdi Bahrami <github@mahdibm.com>

* factor in additional suggestions from @mahdibm

* combine two logger statement into one and print only for Kb of payload

---------

Co-authored-by: Mahdi Bahrami <github@mahdibm.com>
2024-05-15 09:56:35 +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 42eaaf4fb1 remove redundant pre-concurrency flag (#314)
motivation: address warnings

changes:
* remove pre-concurrency flag when not longer needed
2023-12-18 11:49:03 -08:00
tachyonics 0fbd8448af Don't log work fetching failure at error. (#313) 2023-12-08 12:49:03 -08:00
Sébastien Stormacq c85c875593 [doc] Getting Started documentation and tutorial (#300)
improved getting started documentation, with DocC
2023-09-11 10:43:06 -07:00
tomer doron e221dd8362 remove swift-backtrace in swift >= 5.9 (#305)
motivation: swift 5.9 ships with builtin backtrace support \o/

changes:
* remove the dependency on swift-backtrace when using swift 5.9 or above
* conditionalize the call to Backtrace.install to relevant versions only
2023-09-07 18:39:11 -07: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
tomer doron 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
Yim Lee 98a23b64bb DocC setup (#270) 2022-08-21 20:29:08 -07: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 d35e827121 Remove extension for JSONEncoder and JSONDecoder (#257)
motivation: we should not publicly extend types we do not own

change: remove extensions which are largely API sugar that is not directly related to Lambda
2022-04-15 13:05:49 +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
Fabian Fett bc78f60e32 Add LambdaRequestID (#243)
If we want to minimize allocations for every invocation, we need to look at types that currently allocate. Currently we use a String to hold the request id. However since the request id is a uuid, that string is 36 characters long. This is way above the 15 character string allocation threshold. The go to type in this case would be `UUID`. However `UUID` is in Foundation and we want to keep the lambda runtime Foundation free.

This pr introduces a LambdaRequestID to represent a uuid. One nice side effect of having our own uuid case is: We can make writing the uuid-string to a ByteBuffer allocation free (since no intermediate translation to a string is needed first).
2021-12-11 13:05:48 +01:00
Fabian Fett b8d89ca208 Add ControlPlaneRequest, ControlPlaneResponse (#238)
### Motivation:

In the coming weeks, we want to restructure the LambdaRuntime internals in such a way, that we allocate a lot less resources per invocation. To accomplish this, we want to encode and decode the ControlPlaneAPI requests directly from their semantic value. For this reason, we need a specialized ControlPlaneRequest and ControlPlaneResponse type that we can encode from and decode into.

### Modifications:

- Add `ControlPlaneRequest`, `ControlPlaneResponse`
- Move `Invocation` and `ErrorResponse` into same file as `ControlPlaneRequest`
- Remove `Lambda` namespace around `Invocation`
2021-12-06 21:17:38 +01:00
YR Chen 4317c5334f Adopt concurrency adoption guidelines (#230)
Adopt Swift Concurrency adoption guidelines for Swift Server Libraries (swift-server/guides#70).

- Use #if compiler(>=5.5) && canImport(_Concurrency) to judge if Concurrency is available
- Some clean up
2021-12-06 20:52:35 +01:00
Fabian Fett 011e8ddc4b Rename Lambda.Context to LambdaContext (#233) 2021-09-30 01:56:58 +02:00
Fabian Fett afab5102a1 Rename Lambda.Lifecycle to LambdaRuntime (#232) 2021-09-29 09:10:30 +02:00
tomer doron b757de0241 Update and add examples to new APIs (#228)
* take advantage of @main where possible
* move the top level Sample code to the examples subdirectory
* extract a few examples form the "LambdaFunctions" directory (which is really a deployment demo) and move them to the top level Examples directory
*  rename "LambdaFunctions" examples as "Deployments" to make their intent clearer
* add a sample that demonstrates how to test a lambda now that SwiftPM can test executables directly
* update the test-sample docker setup to build & test th new samples
* fix a few typos and In/Out typealias left overs
* remove LinuxMain since its no longer required
2021-09-25 10:30:04 +02:00
Fabian Fett 7c1dea035d Remove dependency on _NIOConcurrency (#229) 2021-09-23 19:44:08 +02:00
Fabian Fett e5aa488a26 [RFC] Drop event label from handle methods in LambdaHandlers (#225)
* Drop event label from handle method in LambdaHandlers
* Rename `In` to `Event` and `Out` to `Output` in `EventLoopLambdaHandler`
2021-09-22 16:59:07 +02:00
Fabian Fett dbd675df6f Reorder Event and Context. (#224)
motivation: follow API design guidelines

changes: Reorder `event` and `context` n public APIs
2021-08-24 15:26:39 -07:00
Fabian Fett 454fe2e037 Drop sync and closure APIs (#222)
motivation: with async/await, no need in closure based APIs

changes:
* Drop closure APIs
* Rename AsyncLambdaHandler -> LambdaHandler
* Removed unnecassary public acls from tests
2021-08-24 14:20:13 -07:00
Fabian Fett 782c0f38ac InitializationContext should be a value not reference type (#219) 2021-08-19 15:57:23 +02:00
Fabian Fett f01a9b607b Use explicit NIO imports (#220)
- Use explicit NIO modules `NIOCore`, `NIOPosix` and `NIOEmbedded` introduced with SwiftNIO 2.32.0
2021-08-19 09:42:23 +02:00
tomer doron 8525b6334e split events into spearate package (#216)
motivation:
the runtime library has a stable API while the events are still moving target. In order to provide a 1.0 stable version we separate them out

changes:
* remove Events module
* update readme
* update Samples
* remove gateway example

Co-authored-by: Fabian Fett <fabianfett@apple.com>
2021-08-19 09:36:01 +02:00
Joel Saltzman 245674cd6b Renamed completeWithAsync to completeWithTask (#221)
* Renamed EventLoopPromise's `completeWithAsync` to `completeWithTask` (based on the SwiftNIO renaming)
* Updated swift-nio dependency to 2.32.0
2021-08-19 09:23:53 +02:00
Cory Benfield 48dc507d26 Clean up dependency graph and imports (#218)
- Correctly express the dependency on NIO in Package.swift
- Correctly import _NIOConcurrency in files where it's used
2021-08-13 10:50:18 +02:00
Juan A. Reyes 774bbf1ae7 Change Lambda.Context from class to struct (#217)
Motivation: Lambda.Context is currently a class that only holds values. For this reason it should be a value type itself.

Changes: Lambda.Context is now a struct, that is backed by a CoW storage class, to ensure performance remains high.
2021-08-11 08:59:51 +02:00
Fabian Fett a9e15b13b3 Fix platform requirements (#214)
- Replace the placeholder platform requirements with `@available(macOS 12, iOS 15, tvOS 15, watchOS 8, *)` 
- Bump required dependency versions: `swift-nio`, `swift-log` and `swift-backtrace`
2021-07-21 20:47:35 +02:00
DwayneCoussement 9a7d9d0941 SNS MessageAttributes are optional (#208)
motivation: Notice that if you check the contents of the SQS records, some kind of transform happened on the original SNS message. MessageAttributes in the above example, these will not be set, so this is the initial fix.

changes: make MessageAttributes are optional
2021-06-11 10:14:48 -07:00
Fabian Fett 19fc295aa0 async/await support (#186)
- Add an `AsyncLambdaHandler`. Will be renamed to `LambdaHandler` as soon as we drop the current callback based `LambdaHandler`.
- The default way to use an `AsyncLambdaHandler` is to use `@main` to execute it. Don't use `Lambda.run` for it. We wan't to remove `Lambda.run` for 1.0.

Co-authored-by: tomer doron <tomerd@apple.com>
2021-04-27 22:47:11 +02:00
ML edbfa795b6 Updated S3.Event (#195)
motivation: support s3:ObjectRemoved:* event

changes:
* Changed the S3.Event object size field to an optional due to the missing field on a s3:ObjectRemoved:* event
* Added one additional test to check propper json decoding
2021-04-15 10:35:08 -07:00
Fabian Fett 19a9f92538 Inline default LambdaHandler implementations (#201)
Add `@inlinable` to default LambdaHandler implementations. This ensures that those implementations can be inlined into user code and can be specialized for their input and output types.
2021-04-14 22:59:42 +02:00
Fabian Fett ab13e51984 Performance Improvements (#199)
Modifications:
- Replace `HTTPHandler` with `NIOHTTPClientResponseAggregator`, to fix a CoW issue. This increases performance.
- Ensure that we only use one `EventLoop` in tests.
- Use `syncOperations` to setup the `HTTPClient`.
2021-04-14 00:21:38 +02:00
Fabian Fett a49a87341a Update swiftformat (#196)
changes: 
* Update swiftformat from 0.44 to 0.47
* Adjust rules
2021-03-26 10:34:34 -07:00
DwayneCoussement e33e4afbf0 Add support for AppSync events. (#187)
motivation: Support AWS AppSync events
changes: add Codable models for AppSync events
2021-03-02 13:05:50 -08:00
Ralph Küpper ee2a6e0cb3 Fix the queryStringParameters in ALB.TargetGroupRequest. (#182) 2021-01-06 09:16:51 +01:00
Johannes Bosecker f51eeb6c84 Fixed the visibility of the JWT in an API Gateway V2 Request. (#178)
Co-authored-by: Johannes Bosecker <johannes@Johanness-MacBook-Air.local>
2020-12-07 16:54:03 +09:00
Fabian Fett edef0363b6 updates to APIGateway V2 payloads
* Properties of HTTPResponses are now var (#176)
* remove redundant multiValueHeaders
2020-10-13 15:02:45 -07:00
Filipp Fediakov 0afbf42226 Fix typo in LambdaRunner.swift documentation (#171) 2020-09-25 18:12:09 +02:00
tomer doron 8986809d8e simplify date formatting (#159)
motivation: use consistent date formatting across platforms

changes: use manually configured DateFormatter instead of ISO8601DateFormatter
2020-08-14 14:24:29 -07:00