64 Commits
Author SHA1 Message Date
tomer doronandGitHub 2bac89639f add syncShutdown to LambdaHandler (#132)
motivation: make shutdown easier to use

changes:
* override shutdown to use the offloadQueue to perform syncShutdown
* add empty syncShutdown that can be implmented by the concrete Lambda function
2020-06-18 12:48:13 -07:00
Adam FowlerandGitHub d2f5c1c324 Added SES Event type (#130)
motivation: support event triggers from SES

changes: Added SES Event type
2020-06-17 09:53:53 -07:00
Fabian FettandGitHub 437a60d7a0 Added shutdown() -> EventLoopFuture<Void> to the ByteBufferLambdaHandler (#122)
* Added `syncShutdown() throws` to the `ByteBufferLambdaHandler`

* Updated to use a `ShutdownContext`

* Review comments addressed.
2020-06-17 07:34:01 -07:00
Ro-MandGitHub 77280662e3 Added header when reporting failing invocations or initializations #116 (#128)
* allow the users of client to provide headers
* add initialization error header
* add error header to failed invocations
* fix external setting of ip and port via config
* add tests
2020-06-17 06:55:05 -07:00
tomer doronandGitHub d1a927650a add initialization context (#126)
motivation: in more complex initialization scearios you may want access to a logger or other utilities

changes:
* introduce new InitializationContext type that could be extended in the future without breaking the API in semantic-major way
* instead of passing in EventLoop to the handler factory, pass in a context that includes a Logger, an EventLoop and a ByteBufferAllocator
* fix a bug where we dont hop back to the event loop when coming back from the handler
* adjust tests to the new signature
2020-06-16 11:08:00 -07:00
Fabian FettandGitHub 0008e59bab Rename payload to event (#115) 2020-06-07 07:47:05 -07:00
tomer doronandGitHub 3b29513652 handle lambda errors correctly in mock server (#104)
motivation: better mock server

changes:
* add handler for :requestID/error
* return .accepted to lambda
* return .internalServerError to client + error json
* small refactoring of response code in mock server to make it DRYer
2020-06-01 13:15:30 -07:00
tomer doronandGitHub e2ac820289 add an option to start the local debugging server based on an env variable (#87)
motivation: make using the local debugging server easier to turn off/on without the need to change code when oyu are preparing to deploy

changes:
* add code to lambda so that in debug mode only, if the LOCAL_LAMBDA_SERVER_ENABLED env variable is set the local debugging server is started
* make withLocalServer internal
* update example code
2020-06-01 12:38:06 -07:00
Bryan MoffattandGitHub eaa6fb6338 Add a User-Agent when using the Lambda Runtime API (#98)
* Add a User-Agent when using the Lambda Runtime API
2020-05-30 10:39:34 -07:00
tomer doronandGitHub 8c24cffd97 fix context members to follow swift APi guidelines (#88)
motivation: nicer API

changes:
* requestID -> requestID
* traceId -> traceID
* invokedFunctionArn -> invokedFunctionARN
* adjust examples
2020-05-27 11:46:31 -07:00
Fabian FettandGitHub fe60959b99 fix race condition when shutting down server
motivation: fix a race condition that can lead to crash and failing tests

changes: close channel when canceling
2020-05-21 09:11:29 -07:00
53930fef38 add debug functionality to test with mock server (#73)
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>
2020-05-15 16:56:17 -07:00
ab3ce640aa Use NIO in Single Threaded Mode (#68)
motivation: better performance 

changes:  employ SwiftNIO's new Single Threaded Mode

Co-authored-by: tomer doron <tomerd@apple.com>
2020-05-12 13:41:10 -07:00
Fabian FettandGitHub b7462b8081 Make Lambda.env() -> String? public (#61) 2020-05-08 12:35:55 -07:00
Fabian FettandGitHub 1d9637279a Moved Foundation to AWSLambdaRuntime; AWSLambdaRuntime renamed to AWSLambdaRuntimeCore (#41)
motivation: enable non-foundation module for performance sensitive use cases

changes: 
* rename AWSLambdaRuntime to AWSLambdaRuntimeCore 
* create AWSLambdaRuntime for Foundation dependent functionality 
* have (new) AWSLambdaRuntime export AWSLambdaRuntimeCore
* adjust tests
2020-05-07 09:37:28 -07:00
Fabian FettandGitHub 29d631709f Added DynamoDB Event (#65)
motivation: support DynamoDB triggers

changes: added DynamoDB Event abstractions and encoders/decoders
2020-05-07 09:05:11 -07:00
Fabian FettandGitHub 9df8a1a468 Rename RequestWork to GetNextInvocation (#74) 2020-05-07 08:37:07 -07:00
tomer doronandGitHub 593f0395d6 better links to events docs (#67)
motivation: link to developer guide instead of golang impl

changes: add/change event doc links to https://docs.aws.amazon.com/lambda/latest/dg/lambda-services.html
2020-05-06 07:23:54 -07:00
tomer doronandGitHub 2324074c33 improve type aliases and API docs (#64)
motivation: better documentation, happier users

changes: 
* add more information on public APIs
* move and simplify type aliases
2020-04-28 14:31:43 -07:00
Fabian FettandGitHub 8509674ed0 Add apigateway and alb (#52)
motivation: support ALB and APIGateway Events

changes: add Codable abstractions for ALB and APIGateway v1+v2  Events
2020-04-27 10:49:44 -07:00
Fabian FettandGitHub 2297929bfd LambdaCodableEncoder should be less Foundation biased (#66) 2020-04-27 10:32:17 -07:00
tomer doronandGitHub bfad18623d hide testing harness in release builds (#63)
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
2020-04-27 10:23:56 -07:00
Fabian FettandGitHub 920302a4c3 Improve testing utils (#60)
motivation: make testing lambda easy

changes:
* add a AWSLambdaTesting module
* add helper methods for testing different types of Lambda handlers / closures
2020-04-23 00:11:05 -07:00
Fabian FettandGitHub 378adf844d Allow integration with API Frameworks: Public Lifecycle (#58)
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
2020-04-22 16:10:38 -07:00
Fabian FettandGitHub 7a946064e7 Added SNS & SQS Events (#46)
* Added SNS & SQS Events
* Added Base64 util
2020-04-03 10:36:47 -07:00
Fabian FettandGitHub a810911e02 AWSRegion without enum (#54) 2020-04-03 10:34:23 -07:00
Fabian FettandGitHub 3fad2f5751 Added Cloudwatch Event (#48)
motivation: support cloud watch events

changes: 
* add aws region abstraction
* add generic cloud watch abstraction 
* add common / key cloud watch events
2020-03-30 14:07:18 -07:00
Fabian FettandGitHub 6f7103251a Reusable JSONCoders (#50)
motivation: beter performance

changes: 
* abstract JSONCoders and have a default static instance
* make encoding/decoding DRYer across String and Codable
2020-03-27 09:21:42 -07:00
Fabian FettandGitHub ac290985fa Reuse DispatchQueue for multiple Invocations (#49)
should fix #39
2020-03-26 13:58:28 -07:00
Fabian FettandGitHub 87121ec394 Capitalized HttpClient to HTTPClient filename (#47) 2020-03-25 10:52:22 -07:00
Fabian FettandGitHub 643dd91375 Added S3 Event (#45)
motivation: support S3 Events

changes:
- Created `AWSLambdaEvents` target
- Added S3 Event as first event
- Use propertyWrapper for customers Encoding/Decoding
2020-03-24 16:01:40 -07:00
Fabian FettandGitHub 2cd6bce4d3 Remove use of JSONEncoder for Error Reporting (#42)
motivation: better performance for error response encoding 

changes: use string builder instead of Codable -> String with JSONEncoder
2020-03-18 20:23:53 -07:00
tomer doronandGitHub b61aab012e rename project to SwiftAWSLambdaRuntime (#38)
motivation: unique, accurate name

changes:
* rename project to SwiftAWSLambdaRuntime
* rename main module to AWSLambdaRuntime
* rename / simplify sample module names
* adjust readme and scripts
2020-03-13 14:48:25 -07:00
tomer doronandGitHub 88f3b504f4 swift 5.2 (#37)
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
2020-03-13 12:54:12 -07:00
tom doron e4104135e4 simpler/faster mock
motivation: faster mock server for perf testing

changes: no logger, always keep-alive
2020-03-13 12:50:24 -07:00
tomer doronandGitHub 7d1b309035 refactor api 1 (#33)
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
2020-03-13 11:44:22 -07:00
tomer doronandGitHub 2e04511741 move config, lifecycle, context to separate files (#32)
motivation: easier code navigation

changes: move config, lifecycle, context to separate source files
2020-03-11 12:01:18 -07:00
tomer doronandGitHub a05185185e refactor bootstrapping (#28)
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
2020-03-10 11:17:31 -07:00
d0466172b6 Add Deadline (#27)
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>
2020-03-10 10:30:12 -07:00
tomer doronandGitHub 6c27af249a remove dead code (#29)
motivation: less code

changes: remove string/codable redundant abstractions for run(handler) and resut type (pre swift 5 leftover)
2020-03-09 19:46:52 -07:00
Fabian FettandGitHub df4e247910 Removed “Connection” headers (#26) 2020-03-09 09:49:39 -07:00
Fabian FettandGitHub ddee38c367 LambdaRuntimeClient works with Invocation (#19)
### 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.
2020-03-08 15:10:03 -07:00
tomer doronandGitHub 08f75f51c7 refactor (#13)
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
2020-03-08 12:41:09 -07:00
tomer doronandGitHub b8a6466577 add docker support (#15)
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
2020-03-06 18:43:16 -08:00
Fabian FettandGitHub df6638d63b Don’t create an EventLoopFuture chain (#4)
motivation: prevent memory bloat

changes: 
* recurse instead of event loop chain
* fix flaky test
2020-03-06 12:27:52 -08:00
tomer doronandGitHub 0cb1f134db Replaced String(utf8String: value) with String(cString: value) (#2)
String(utf8String: UnsafePointer) is a Foundation API.
Replaced with Swift STL equivalent.
2020-03-05 13:50:59 -08:00
Tom DoronandGitHub Enterprise 209906d390 performance improvments (#17)
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
2020-03-04 13:54:55 -08:00
Tom DoronandGitHub Enterprise c3d4ad5a39 performance tests (#16)
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
2020-03-04 11:01:15 -08:00
Tom DoronandGitHub Enterprise 4803c61152 remove NIOAny wrapper (#15)
motivation: wrapper was a workarund for swift build issue on amazon linux

changes: remove wrapper, since root cause was fixed
2019-10-08 18:03:50 -07:00
Tom DoronandGitHub Enterprise fb6de922de more refactoring (#14)
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
2019-09-26 07:11:12 -07:00