motivation: allow end to end testing locally
changes:
* add a Lambda+LocalServer which exposes Lambda.withLocalServer available only in DEBUG mode
* local server can receive POST requests with payloads on a configurable endpoint and and send them to the Lambda
* move Lifecycle completely into EventLoop
* remove all locks since running in one EventLoop
* Use UUID for requestId
Co-authored-by: tom doron <tomer@apple.com>
motivation: testing harness should only be used for testing, and uses @testable import which doe not work in release builds
changes: hide code behind #if check
motivation: make testing lambda easy
changes:
* add a AWSLambdaTesting module
* add helper methods for testing different types of Lambda handlers / closures
motivation: easy integration of web frameworks frameworks like vapor and smoke
changes: expose `Lifecycle` as a public API to allow easy integration with higher level frameworks
motivation: beter performance
changes:
* abstract JSONCoders and have a default static instance
* make encoding/decoding DRYer across String and Codable
motivation: support S3 Events
changes:
- Created `AWSLambdaEvents` target
- Added S3 Event as first event
- Use propertyWrapper for customers Encoding/Decoding
motivation: unique, accurate name
changes:
* rename project to SwiftAWSLambdaRuntime
* rename main module to AWSLambdaRuntime
* rename / simplify sample module names
* adjust readme and scripts
motivation: amazon linux support will land in 5.2
changes:
* remove inline as its default in 5.2
* remove linux test and lean on --enable-test-discovery
* adjust package syntax
* format code to match 5.2
motivation: nicer apis, happier users
changes:
* use ByteBuffer + EventLoopFuture for core APIs instead of byte array and callbacks
* create three base protocols: ByteBufferLambdaHandler, EventLoopLambdaHandler and LambdaHandler
* abstract common encoding/decoding functionality into a EventLoopLambdaHandler, reducing most code from string/codable handlers
* only the highest level LambdaHandler is offloaded to a DispatchQueue, lower level is run on the same EventLoop as the core library
* refine encoding/decoding logic
* inline all the things
* adjust tests
* adjust api docs
* adjust readme
motivation: make initialization logic more robust, allowing setup at contructor time and also async bootstrap
changes:
* remove the initialize method and replace it with a factory pattern.
* update core API and logic to support new initialization flow.
* add tests to various initialization flows
Motivation:
- As a developer I want to be able to know how much time I have left to execute my lambda, before it times out
Changes:
- storing the deadline on Context and Invocation
- added getRemainingTime() to Context which returns a TimeAmount
- Renamed `Invocation.deadline` to `Invocation.deadlineInMillisSinceEpoch` to better reflect
- fixed MockLambdaServer to not return “keep-alive” anymore
Co-authored-by: tom doron <tomer@apple.com>
### Motivation:
- We want to store different entities that are needed when executing a handler within the LambdaContext (Logger, EventLoop, ByteBufferAllocator, …)
- Currently the LambdaRuntimeClient creates the LambdaContext. Having the LambdaContext with the Logger, EventLoop and ByteBufferAllocator be created from the LambdaRuntimeClient feels to me too much for me.
- Conceptionally the Lambda control plane api call is “get next Invocation” (API naming)
### Changes:
- LambdaRuntimeClient responds with an Invocation and does not use the LambdaContext at all anymore.
- LambdaRunner creates the LambdaContext with the Invocation, Logger and EventLoop.
- LambdaContext has been renamed to Lambda.Context
- Lambda.Context is a class now, since it is conceptionally not a value type and might be passed around a lot
- Lambda.Context properties `traceId`, `invokedFunctionArn`, `deadline` are not optional anymore since they will be always set when executing a lambda
- Creating an Invocation can fail with LambdaRuntimeClientError.invocationMissingHeader(String), if non optional headers are not present
- the test MockLambdaServer and the performance test MockServer always return headers for deadline, traceId and function arn (static for now – could be changed with Behaviour flag?!)
### Open ends:
- we will need to build some kind of Deadline into the context (See also #9 - probably for a different PR)
- we have a stupid mapping between ByteBuffer and [UInt8] in the LambdaRunner for now (marked with two TODOs). I don’t want to change this in this PR since it will lead to huge merge conflicts down the road with the potentiall API changes we have in mind.
motivation: simpler concurrency, better tests
changes:
* ensure http client is called in a single-threaded manner and remove locks
* refactor test
* make mock server more robust
motivation: enable CI
changes: add docker files support for ubuntu 16.04 and 18.04 and swift 5.0 and 5.1
note that eventyally this will need to move to AL2 docker images, but we dont have official ones yet
motivation: better performance
changes:
* simply url configuration to ip and port so we can reoslve the socket add ress faster
* skip happy eyeballs
* limit eventloop group to 1 thread
* remove use of UUID and URL
* fix backtrace url
motivation: benchmark for comparison of warm/cold runs
changes:
* refactor configuration
* add mock server that can be used by perf tests
* add simple perf test script
* change redundant classes to structs, make remaining classes final
* make offloading opt-in
* safer locking
* fix format
motivation: improve code quality, handle keep-alive
changes:
* refactor http client to keep warm connection to runtime engine when possible and handle request timeouts
* refactor configuration into the main lambda class to surface it more clearly
* refactor lifecycle code handle shutdown properly and easier to reason about
* add tests
motivation: make lambda execution sequence easier to reason about
changes:
* add `peekFailure` extension to `EventLoopFuture` to handle error without side effects
* update process chain to make use of `peekFailure`
motivation: make code simpler to reason about, better use of swift-nio
changes:
* remove main loop on global queue + wait, replace with recursion
* make better use of EvenLoopFuture, instead of result types to signal errors
* inject lifecycleId so we can share offloading queue
* improve logging
* adjust and improve tests
* update sanity and generate linux tests script to work better with dates and swiftformat
Motivation:
When initialization is expensive it's useful for it to be done upfront
instead of for each invocation of the lambda. Similarly, it's helpful
for errors thrown during initialization to be reported to the runtime.
Modifications:
- Add support for initialization in 'LambdaHandler'
- Report init errors to '/init/error'
Result:
Implementers of 'LambdaHandler' can run their own initialization and have
errors reported.
* update code to swift5 and nio2
motivation: support newer version of swift and underlying dependencies
changes:
* adjust code to swift 5
* use swift 5 result type and better error handling for json encoding/decoding
* adjust code to nio 2
* add dependency on swift-log for logging instead of print statements
* make logger as part of context
* improve error handling
* add dependecy on swift-backtrace to capture crashes
* improve lifecycle
* adjust tests
* add default formatting rules and fix formatting
* improve readme
motivation: nicer code
changes
* rename Result to ResultType since swift is getting formal Result soon
* use Handler instead of T for generics in CodableLambda which is more readable
* simpler bytes->String decoding
hide LambdaLifecycleResult from users
motivation: cleaner end-user API
changes:
* make LambdaLifecycleResult internal
* change run, _run method signatures to hide LambdaLifecycleResult from end-user API
* adjust tests
* shutdown handler, lambda api adjustment, latest swift-nio
motivation:
* shutdown: while not required, demonstrate better example for shutdown
* latest nio and api adjustments: fixes runtime issues observed when running for realz
changes:
* add signal based shutdown hook that terminates and cleans up resources
* pull latest swift-nio to get fix to thread renaming
* adjust aws lambda api prefix and headers
* reformat linux tests code