99 Commits

Author SHA1 Message Date
Sébastien Stormacq f65ec32c4d [doc] add a deployment guide and update the readme (#432)
As discussed with @0xTim 
This PR 
- adds a minimal example of deployment using SAM in the README 
- adds a `Deployment.md` Swift Docc file to cover deployment with the
AWS console, CLI, SAM, and CDK. It mentions and contains a call to
contributions to further examples for third-party tools such as the
Serverless Framework, Terraform, or Pulumi.
2024-12-25 07:43:51 +01:00
Sébastien Stormacq cef85b9fe8 [examples] add an example project to show test strategies (#438)
This new example project show four testing strategies for Swift Lambda
function

- Unit testing the business logic (not specific to Swift Lambda) 
- Integration testing the handler method 
- Local invocation with the Swift Lambda Runtime 
- Local invocation with SAM 

**[IMPORTANT]**
To allow testing the handler, I had to change visibility of a method in
the Runtime project. This method is clearly marked for testing only, so
it should not be a problem. Happy to read feedback and discuss however.
2024-12-25 07:43:20 +01:00
Sébastien Stormacq e80fcf766e [examples] Update APIGateway example with the new APIGatewayResponse initializer (#437)
After the merge of
https://github.com/swift-server/swift-aws-lambda-events/pull/86
I updated the `APIGatewayV2Response` example to use the new initializer
2024-12-24 08:40:46 +01:00
Sébastien Stormacq e5404c95cb [examples] Fix path settings in the examples' Package.swift (#439)
All the `Package.swift` files from the examples use `path: "."` instead
of `path: "Sources"` which triggers error messages when users add a
`Tests` directory.
2024-12-22 07:36:32 +01:00
Sébastien Stormacq 18660fcdd1 [examples] Add CDK deployment example (#431)
added an example showing how to deploy with the CDK
This code is the basis for the upcoming CDK section in the deployment
guide
2024-12-21 10:39:13 +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
Sébastien Stormacq c22f5271a0 add HelloJSON example + README (#424)
* add HelloJSON example + README

* multiple corrections of typos and grammatical errors

Co-authored-by: Tim Condon <0xTim@users.noreply.github.com>
2024-11-13 13:53:19 +01:00
Sébastien Stormacq 54fd25bdad Add example and README for a streaming Lambda function (#415)
* add streaming example and doc

* add streaming example to CI

* fix soundness

* remove unused files

* correct usage of zsh env var

* typo

Co-authored-by: Tim Condon <0xTim@users.noreply.github.com>

* typo

Co-authored-by: Tim Condon <0xTim@users.noreply.github.com>

* add comments

Co-authored-by: Tim Condon <0xTim@users.noreply.github.com>

* typo

Co-authored-by: Tim Condon <0xTim@users.noreply.github.com>

* add an example README with common sections + link to each example

---------

Co-authored-by: Tim Condon <0xTim@users.noreply.github.com>
2024-11-07 14:55:37 +01:00
Sébastien Stormacq ca82709a9b Add an example and README for background tasks (#418)
* add an example for background tasks

* swift-format

* add CI

* add background task section in the main readme

* minor formatting changes
2024-11-07 11:33:34 +01:00
Sébastien Stormacq 4992ba5bd8 change flag name from --allow-network-access to --allow-network-connections as documented by SPM (#407) 2024-10-18 14:51:23 +02:00
Franz Busch 59dd68adab [CI] Adopt soundess workflow from swiftlang (#405) 2024-10-11 15:49:34 +02:00
Sébastien Stormacq b4673d264b Add AWS SDK and Soto examples (#396)
* add aws sdk example

* add soto example

* use amazonlinux docker image instead of ubuntu

* dynamically add runtime dependency based on env var

* remove import of Foundation.ProcessInfo

* workaround https://github.com/actions/checkout/issues/1487
2024-10-10 13:08:31 +02:00
Sébastien Stormacq f7584d1257 add docker fine grained permission to the plugin (#391)
* add docker fine grained permission to the plugin

* swift-format
2024-10-08 14:10:53 +02:00
Sébastien Stormacq db17a62e38 Restructure Examples folder (#387)
* Restructure Examples folder

* add README

* remove v1 examples

* swift format
2024-10-08 11:07:47 +02:00
Jack Rosen 426e658414 Add Support For Copying All Resources Into Final Executable (#386)
* Add Support For Copying All Resources Into Final Executable

* Run formatter

---------

Co-authored-by: Sébastien Stormacq <sebastien.stormacq@gmail.com>
2024-10-08 10:43:17 +02:00
Franz Busch 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
Camden Fullmer 35e0919ed2 Add support for resources when packaging using the SwiftPM plugin (#333)
* Add support for resources when packaging using the SwiftPM plugin.

* Copy the resources directory to the working directory instead of recreating the directroy structure.

* Add resource packaging example.

* Use the bundle's url function to locate the file url.

* Fix year for soundness check.

---------

Co-authored-by: Sébastien Stormacq <sebastien.stormacq@gmail.com>
2024-08-05 17:51:21 +02:00
tomer doron 3b72f6a6cf improve examples (#292)
motivation: examples can be confusing since they use relative path to the library for CI purposes

changes:
* update examples to use the library URL, expect when env variable is set for CI purposes
* rename docker compose job to test-examples since it is more accurate
2023-03-12 11:23:41 -07: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
Bill 20978cc462 Add special Deployment instructions for the Mac M1 (#263) 2022-05-09 10:19:30 -07: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
Fabian Fett d06d22c0e0 Lambda factory as a protocol requirement. (#244) 2022-01-13 19:10:20 +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
YR Chen 39b34a159b Modernize app example (#231)
Since we already required Swift 5.5 for Concurrency (Xcode 13), it's natural to update the demo app to reflect latest SwiftUI changes, which makes the code neater and more expressive.
2021-12-06 11:30:50 +01:00
Fabian Fett 011e8ddc4b Rename Lambda.Context to LambdaContext (#233) 2021-09-30 01:56:58 +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 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 3511a92241 Update examples for Swift 5.5 (#223)
- Lambda examples use async/await
- SwiftUI example uses async/await
- Handlers are marked with `@main`
- Executables are defined as `.executableTarget`
- Examples require Swift 5.5
2021-08-19 20:07:54 +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
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
tomer doron b8834b21c2 improve LocalDebugging readme (#137)
motivation: clearer guidelines for using the example

changes: fix a few typos, fix incorrect scheme name and add a bit more prose
2020-07-02 11:18:23 -07:00
tomer doron b9224e2fb6 examples deployment scripts refresh (#133)
motivation: make sure examples are up tp date

changes:
* use swift:5.2 images instead of nighlies
* compute dependencies to make zipfile as small as possible
* make scripts more consistent
2020-06-25 13:38:25 -07:00
Andrea Scuderi 0535cb72eb Fix SAM Examples after directory change (#124) 2020-06-17 13:37:51 -07:00
Andrea Scuderi c683b41545 Add example scripts and docs for Serverless Framework (#113)
* Add example scripts and docs for Serverless Framework
* Refactor Examples folder and scripts
- Add a common config.sh script
- Move SAM templates to scripts/SAM
- Add Serverless templates to scripts/serverless
- Update the scripts to work with new folder structure and config.sh
2020-06-12 12:14:37 -07:00
Fabian Fett 0008e59bab Rename payload to event (#115) 2020-06-07 07:47:05 -07:00
Eneko Alonso 71587eab10 Document configuration variables in deploy.sh (#97) 2020-06-06 18:21:35 -07:00
Brendan Kirchner 5e546a1a9e Added jq requirement to examples readme (#106)
* Added jq requirement to readme
2020-06-03 10:44:28 -07:00
tomer doron 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
pmarrufo f1ce84f70b Fix typo in ErrorHandling Example (#93)
* Fix typo
2020-05-29 13:42:44 -07:00
tomer doron 75d05ca954 docs cleanup (#91)
motivation: cleanup docs for oss

changes:
* add useful information in readme, with pointers to examples
* update ci setup and example to use latest tools
* update contributors list

Co-authored-by: Yim Lee <yim_lee@apple.com>
2020-05-28 12:19:19 -07:00
tomer doron 3cb9330832 fix example correctness (#90)
motivation: make example more correct

changes: update response in DispatchQueue.main
2020-05-28 09:59:56 -07:00
tomer doron 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
tomer doron d956b89dbc improve debugging example (#84)
motivation: clearer examples as we prepare to open source

changes:
* rename debugging example to make the name more accurate
* add more information in the local debugging example
* add a Shared module to show how to share code between client and server
* make example more useful - use JSON for registration like flow
* add docker-compose task to test examples

Co-authored-by: Yim Lee <yim_lee@apple.com>
2020-05-21 09:07:38 -07:00
Fabian Fett d3b75176dd Update APIGateway example to use AWSLambdaEvents (#76)
motivation: example of how to use the API Gateway model

changes: Update APIGateway example to use AWSLambdaEvents
2020-05-12 12:41:01 -07:00
tom doron b5f18dad4b move examples into a subdirectory
motivation: easier to find and reason about

changes: move exmaples from a seperate repo into a subdirectory
2020-05-07 08:56:31 -07:00
tom doron d5368bbe25 moving examples into a subdirectory 2020-05-06 12:19:03 -07:00