Commit Graph
314 Commits
Author SHA1 Message Date
Sébastien Stormacq dbc2f98b62 add local testing instructions to hello world example (#474)
The local testing instruction are missing from the hello world example.
The format of the payload is not intuitive or trivial to guess. We need
to make it explicit
2025-01-29 13:26:56 +01:00
Sébastien Stormacq 7aa746f07e [core] LocalServer - report the error to the continuation (#471)
fix https://github.com/swift-server/swift-aws-lambda-runtime/issues/470
2025-01-22 18:53:57 +01:00
Sébastien Stormacq 02821fe8f7 [test] Update mock server for Swift 6 compliance (#463)
Rewrite to MockServer (used only for performance testing and part of a
separate target) to comply with Swift 6 language mode and concurrency.

The new MockServer now uses `NIOAsyncChannel` and structured
concurrency.

Instead of adding support to
[MAX_REQUEST](https://github.com/swift-server/swift-aws-lambda-runtime/blob/11756b4e00ca75894826b41666bdae506b6eb496/Sources/AWSLambdaRuntimeCore/LambdaConfiguration.swift#L53)
environment variable like v1 did, we implemented support for
`MAX_REQUEST` environment variable in the MockServer itself. It closes
the connection and shutdown the server after servicing MAX_INVOCATIONS
Lambda requests). This allow to add the MAX_REQUEST penalty on the
MockServer and not on the LambdaRuntimeClient.

However, currently, the LambdaRuntimeClient does not shutdown when the
MockServer ends. I created
https://github.com/swift-server/swift-aws-lambda-runtime/issues/465 to
track this issue.

See https://github.com/swift-server/swift-aws-lambda-runtime/issues/377
2025-01-22 12:02:01 +00:00
Sébastien Stormacq ed84609bc4 [core] Update Local Server for Swift 6 compliance (#464)
This PR updates the 4 years old Lambda Local Server for Swift 6
concurrency.

This contributes to
https://github.com/swift-server/swift-aws-lambda-runtime/issues/462
2025-01-22 11:59:10 +00:00
Sébastien Stormacq cda7c768dc update CDK dependencies (#469)
Just a `npm update` to remove dependabots warnings
2025-01-21 08:58:31 +01:00
Sébastien Stormacq 71d49b049e [plugin] support for resources packaging on ubuntu (#467)
When including resources in the package and packaging on Ubuntu,
`FileManager` throws a FilePermission error. The docker daemon runs as
root and files to be copied are owned by `root` while the archiver runs
as the current user (`ubuntu` on EC2 Ubuntu). The `FileManager` manages
to copy the files but throws an error after the copy. We suspect the
`FileManager` to perform some kind of operation after the copy and it
fails because of the `root` permission of the files.

See
https://github.com/swift-server/swift-aws-lambda-runtime/issues/449#issuecomment-2595978246
for a description of the problem.

This PR contains code to reproduce the problem, a very simple
workaround, and an integration test.
The workaround consists of 
- trapping all errors
- verify if the error is the permission error (Code = 513)
- verify if the files have been copied or not 
- if the two above conditions are met, ignore the error, otherwise
re-throw it

I would rather prefer a solution that solves the root cause rather than
just ignoring the error.
We're still investigating the root cause (see [this
thread](https://forums.swift.org/t/filemanager-copyitem-on-linux-fails-after-copying-the-files/77282)
on the Swift Forum and this issue on Swift Foundation
https://github.com/swiftlang/swift-foundation/issues/1125
2025-01-21 08:06:51 +01:00
Sébastien Stormacq b4f016422e Update readme.md (#461)
Add a note about current status for Swift Service Lifecycle support and
a link to the issue
2025-01-12 17:40:17 +01:00
Sébastien Stormacq 752bd41792 move doc images under Resources directory (#460)
Standardize the place where doc resources are located
2025-01-12 17:21:33 +01:00
Sébastien Stormacq 3fa610d7f5 [examples] Simplify examples's Package.swift (#454)
remove the platform dance on all examples.
2025-01-08 14:31:34 +00:00
Sébastien Stormacq eebfd61ed1 add link to IAM create role function (#458)
Update readme to add a link to IAM create role function
2025-01-08 09:44:08 +01:00
Sébastien Stormacq 8dff649920 add links to new documentation (#457)
Update links in the readme to point to the new doc on SPI
2025-01-08 09:32:12 +01:00
Sébastien Stormacq 051029fc0f [examples] Add an example of an APIGateway Lambda Authorizer (#453)
Add an example of an APIGateway Lambda Authorizer

### Motivation:

Lambda Authorizers allow developers to write custom logic to validate
HTTP REST requests.
This example shows how to write a Lambda Authorizer in Swift and how to
configure an API Gateway to use a Lambda Authorizer.

This example use a SAM template to deploy the resources.

### Modifications:

- Add `Examples/APIGateway+LambdaAuthorizer` directory with the source
code, a `template.yaml`, and a `README` file.
- Add a reference to the new example in `Examples/README`
- Modify CI to build the new example 

### Result:

There is a new example showing how to develop a Lambda authorizer in
Swift and how to attach it to an APIGateway with SAM
2025-01-06 16:44:13 +01:00
Sébastien Stormacq 8f7788ffd4 [doc] update deployment guide (#455)
Add a note in the deployment guide to inform Linux user they must have
correct permissions to use docker on their system.

### Motivation:

Build instructions fail on a fresh Ubuntu installation. See this error
report.
https://github.com/swift-server/swift-aws-lambda-runtime/issues/449

### Modifications:

Add a note in the deployment guide that Linux user must add their user
in the `docker` group.

### Result:

Hopefully, Linux users will not experience error at first use of `swift
package archive`
2025-01-06 16:35:06 +01:00
Sébastien Stormacq 2669009d3b Update the tutorial for v2 (#450)
Update the text, code sample, and screenshots for runtime v2

Address
https://github.com/swift-server/swift-aws-lambda-runtime/issues/371
2025-01-04 10:54:37 +01:00
Sébastien Stormacq fe2cf5d391 Update .spi.yml (#452)
Move `AWSLambdaRuntimeCore` as first package because this is where all
the doc lives. This will make `AWSLambdaRuntimeCore` the default on
Swift Package Index
2025-01-04 10:53:27 +01:00
Sébastien Stormacq 430af04828 Update quick-setup.md (#451)
fix typos
2025-01-03 12:28:20 +01:00
Sébastien Stormacq eb9512d053 [doc] update quicksetup guide for v2 (#446)
Update the quick-setup.md docc file to reflect the Runtime v2 API
2025-01-01 21:29:17 +01:00
Sébastien Stormacq 64b1d31184 [doc] Update readme.md with link to SPI deployment doc (#447) 2025-01-01 21:28:40 +01:00
Sébastien Stormacq 38cc01a000 [example] Update testing doc for clarity and remove some typos (#445) 2024-12-25 20:41:00 +01:00
Sébastien Stormacq 38d9e43edb [CI] Add testing example in the list of integration tests (#444) 2024-12-25 08:12:42 +01:00
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 31a7edaf87 [CI] add test to check libFoundation.so & co are not linked to the bi… (#441)
This adds a test in the `integration_test.yml` workflow to verify that
`libFoundation.so`, `libFoundationInternationalization.so`, and
`lib_FoundationICU.so` and not linked the the function binary.

This is a follow up from the work make by @t089 to ensure that we don't
accidentally link Foundation again in the future.

Remove Foundation :
https://github.com/swift-server/swift-aws-lambda-runtime/pull/436
Add test in CI to ensure we don't link to foundation :
https://github.com/swift-server/swift-aws-lambda-runtime/issues/402
2024-12-25 07:42:54 +01:00
Sébastien Stormacq 8c1c1b6fc3 revert commit 04b01da9fe 2024-12-24 08:43:45 +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 04b01da9fe move integration test to .github (#443)
_[One line description of your change]_

### Motivation:

_[Explain here the context, and why you're making that change. What is
the problem you're trying to solve.]_

### Modifications:

_[Describe the modifications you've done.]_

### Result:

_[After your change, what will change.]_
2024-12-22 15:17:44 +01:00
Sébastien Stormacq b4d17fdf8d [CI] add CI scripts separate from the workflows (#442)
_[One line description of your change]_

### Motivation:

_[Explain here the context, and why you're making that change. What is
the problem you're trying to solve.]_

### Modifications:

_[Describe the modifications you've done.]_

### Result:

_[After your change, what will change.]_
2024-12-22 14:39:52 +01:00
Sébastien Stormacq 5ec9a90766 [doc] add 'path: Source' to the quick setup guide (#440)
Fix the `Package.Swift` in the quick setup doc file
This is a follow up and a miss from
https://github.com/swift-server/swift-aws-lambda-runtime/pull/439
2024-12-22 11:16:16 +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
Fabian FettandSébastien Stormacq b687a09b89 [core] Remove platform dance in Package.swift (#400)
Co-authored-by: Sébastien Stormacq <sebastien.stormacq@gmail.com>
2024-12-19 20:26:50 +01:00
Sébastien Stormacq 23da9bf1ad Ensure LOG_LEVEL is correctly picked up (#435)
Fix issue #434
2024-12-19 18:49:35 +01:00
Tobias 26488a7dcc Adds default devcontainer configuration (#433)
Adds default devcontainer configuration from SSWG:
https://github.com/swift-server/swift-devcontainer-template

### Motivation:

Developing for linux can be challenging on macOS because some APIs are
not available on linux. By using VSCode and devcontainer you can
essentially develop "on linux".

### Modifications:

Adds devcontainer config.

### Result:

When working in VSCode, you can now easily open the project inside a
devcontainer.
2024-12-19 18:43:20 +01:00
Franz Busch 2f96dab9af Update release.yml (#430)
Update the release.yml file with the latest label changes
2024-12-18 14:34:18 +01:00
Sébastien Stormacq 64a4d829f0 Fix CI (#429)
* disable yaml linter

* add semver label check

* re-enable soundness checks (shell, python, and yaml)

* disable checks on docc shell command

* fix errors
2024-11-26 18:32:24 +01:00
Sébastien Stormacq 21e224ea8d Update local server for Swift 6 compliance (#428)
* Update local server to Swift 6

* fix compilation error for local server in release mode

* [CI] fix error for integration plugin test
2024-11-16 10:22:01 +01:00
Sébastien Stormacq 8724c47211 re-enable HTTP server for local testing (#426) 2024-11-14 13:18:01 +01:00
Sébastien Stormacq c0df329d1f [CI] fix name for integration test 2024-11-14 08:05:57 +01:00
Sébastien StormacqandTim Condon 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 6b4e60df17 add .index-build and .devcontainer to .gitignore 2024-11-13 12:23:10 +01:00
Sébastien StormacqandTim Condon 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 9f8880b4f0 formatting (#421) 2024-11-07 10:10:36 +01:00
Sébastien StormacqandTim Condon 1f80164eb2 add summary + link to API design doc in the readme (#414)
* add summary + link to API design doc in the readme

* typo

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

* typo

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

---------

Co-authored-by: Tim Condon <0xTim@users.noreply.github.com>
2024-11-07 10:06:30 +01:00
Sébastien Stormacq 7016dfc0fd Set the log level to LOG_LEVEL env variable (#417)
* set the log level to LOG_LEVEL env variable

* remove need for `var logger`

* swift-format

* [ci] update static sdk to 6.0.2
2024-11-07 09:49:11 +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
Sébastien Stormacq 1edaedfb19 [CI] add testing on musl (#412)
* [CI] add testing on musl
2024-10-17 17:57:23 +02:00
Sébastien Stormacq 75d0404a05 [CI] drop Swift 5.8 (#411)
Align to the new version of the CI script is Swift NIO project
2024-10-17 11:09:21 +02:00
Sébastien Stormacq 2fad042186 [CI] add integration test for the archive plugin (#406)
* add integration test for the archive plugin
2024-10-14 21:37:52 +02:00