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.
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.
All the `Package.swift` files from the examples use `path: "."` instead
of `path: "Sources"` which triggers error messages when users add a
`Tests` directory.
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`.
* 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
* Add Support For Copying All Resources Into Final Executable
* Run formatter
---------
Co-authored-by: Sébastien Stormacq <sebastien.stormacq@gmail.com>
* 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>
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
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>
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
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.
* 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
motivation: with async/await, no need in closure based APIs
changes:
* Drop closure APIs
* Rename AsyncLambdaHandler -> LambdaHandler
* Removed unnecassary public acls from tests
- 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
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>
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
* 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
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
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>
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>