Commit Graph
338 Commits
Author SHA1 Message Date
Sébastien Stormacq 7edd4f8108 [core] Fix LocalServer failure to handle large body request (Issue #481) (#504)
Fix https://github.com/swift-server/swift-aws-lambda-runtime/issues/481
2025-06-01 18:31:02 +02:00
Konrad `ktoso` Malawski c7df9bcd8a Revert "[ci] : Remove deprecated options on unit-test action" (#513)
Reverts swift-server/swift-aws-lambda-runtime#510

I think the issue
https://github.com/swift-server/swift-aws-lambda-runtime/issues/509 that
caused this tests disabling has been resolved in Swift and would like to
confirm here as well.
2025-05-16 08:08:27 +02:00
Fabian Fett 5924fb6e75 Add inlinable where potentially usefull (#511)
Allow the compiler to specialize more code by applying `@inlinable` to
generic code.
2025-03-21 12:49:08 +01:00
Sébastien StormacqandFabian Fett 893909543b [ci] : Remove deprecated options on unit-test action (#510)
~~Attempt to fix CI~~

Remove usage of deprecated parameters on unit-test. 

- explicitly enable tests on nightly 6.0
- explicitly enable tests on nightly next
- explicitly enable tests on nightly main

At the time of this writing, this resolves to 

```
linux_6_0_container_image="swift:6.0-jammy"
linux_nightly_next_container_image="swiftlang/swift:nightly-6.1-jammy"
linux_nightly_main_container_image="swiftlang/swift:nightly-main-jammy"
```

---------

Co-authored-by: Fabian Fett <fabianfett@apple.com>
2025-03-20 19:57:21 +01:00
Sébastien Stormacq 7322a3694a [plugin] Fix #505 : resources are not included in the archive on Linux (#506)
Resources are not included in the archive on Linux
 https://github.com/swift-server/swift-aws-lambda-runtime/issues/505

In addition, the script that checks if the resources are correctly
included in an archive when building on Linux is not working.
It failed to detected missing resources.

This patch fix both the plugin and the  CI script
2025-03-17 11:24:07 +01:00
Sébastien Stormacq c3380a0025 [tutorial] fix light image 03-04-01 (#502)
The light mode of image 03-04-01 was not used in the tutorial,
defaulting to dark background all the time.
This is fixed now
2025-03-17 10:56:10 +01:00
Sébastien Stormacq 0267ab1497 [example] Update cdk dependencies (#503)
Update CDK dependencies to address
https://github.com/swift-server/swift-aws-lambda-runtime/security/dependabot/2
2025-03-17 10:55:16 +01:00
Fabian Fett eb634fa9ab Remove unnecessary handler constraints (#499) 2025-03-07 10:31:49 +01:00
Fabian Fett 3ce0a873e3 Attach requestID to logger (#497) 2025-03-07 07:34:05 +01:00
Sébastien Stormacq ae06d59539 cleanup unused code (#498) 2025-03-07 06:48:00 +01:00
Sébastien Stormacq 8f10a6bbdd Fix CI error on Amazon S3 examples (#496)
When we include Traits, we changed the CI container from Swift 6.0
Amazon Linux to Swift 6.1 Nightly on Ubuntu.
This broke the CI because AWS SDK used in the `Examples/S3_AWSSDK`
example depends on `libssl-devel` which is not installed by default on
Jammy images.

This PR reverts back the container used to test all examples to an
Amazon Linux 2, but this time the 6.1-nightly version to allow to
compile the package traits.

This should address
https://github.com/swift-server/swift-aws-lambda-runtime/issues/494
2025-03-06 18:58:50 +01:00
Sébastien Stormacq bba711bd18 remove mentions of LambdaRuntImeCore (#495)
Cleanup code from mentions of `LambdaRuntimeCore`
2025-03-06 18:50:32 +01:00
Sébastien Stormacq bf02bcec9a declare user agent string only once (#493)
The user-agent string was repeated at 5+ different places in the source
code.
I defined it as a constant in the `ControlPlaneRequest` struct where
other similar constant have been defined and make sure the rest of the
code only uses that constant.

This should address
https://github.com/swift-server/swift-aws-lambda-runtime/issues/492
2025-03-06 16:52:42 +01:00
Fabian Fett 0a75e0f9cc Use package traits when using Swift 6.1 (#490) 2025-03-06 09:52:23 +01:00
Fabian Fett 03876f6eed [TestServer] Fix 488 and add simple test lambda (#489)
Fixes: #488
2025-03-04 08:20:06 +01:00
61cd5d54da [core] Add cancellation handling for nextInvocation() (#459)
Allow `LambdaChannelHandler.nextInvocation` to be cancelled.

### Motivation:

If we want to use ServiceLifecycle with the lambda runtime the lambda
runtime needs to be cancellable either via a ServiceLifecycle graceful
shutdown or via Task cancellation. To avoid bringing in the
ServiceLifecycle dependency this PR adds cancellation via Task
cancellation handler.

### Modifications:

Add `withTaskCancellationHandler` to nextInvocation which calls close on
cancel.
In `LambdaChannelHandler.channelInactive` resume continuation if state
is `waitingForNextInvocation`
Added `LambdaRuntimeClientTests.testCancellation`

### Result:

You can now cancel the runtime while it is waiting for the next
invocation.

---------

Co-authored-by: Fabian Fett <fabianfett@apple.com>
Co-authored-by: Sébastien Stormacq <sebastien.stormacq@gmail.com>
2025-02-27 17:03:41 +01:00
Fabian Fett 5de00c96c8 Fixes for Local Lambda Server (#486) 2025-02-27 16:08:39 +01:00
mattcorey 64b417926d Instructions for customizing the output path are incorrect (#484)
Instructions for customizing the output path are incorrect

### Motivation:

`displayHelpMessage` was incorrect - it claimed that the output path was
customizable via a `--output-directory` flag, but the code actually
looks for `--output-path`

### Modifications:

Changing the help message here, instead of the code, in case existing
projects already depend on `--output-path`

### Result:

`displayHelpMessage` will show the correct instructions
2025-02-26 23:42:27 +01:00
Adam Fowler 230eeb505c Update swift-nio to 2.81.0 (#483)
Update swift-nio to 2.81.0 to fix Swift 6 errors
2025-02-21 15:54:53 +01:00
Fabian Fett d7780480f2 Enable Swift 6 mode! (#482) 2025-02-20 16:17:23 +01:00
Josh 40e2291532 Quick typo fix. (#478)
Fixed a glaring typo in the opening section.

_[One line description of your change]_

### Motivation:

First thing I noticed when I started reading.

### Modifications:

Swapped two letters around.

### Result:

Peace and love for all humankind.
2025-02-16 13:40:46 +01:00
Paul ToffoloniandSébastien Stormacq 0777c80172 Add S3EventNotifier example (#477)
Add `S3EventNotifier` example

### Motivation:

There is currently no example regarding an AWS event triggered lambda,
such as a lambda that gets invoked on an S3 object upload. I've had to
look for a while to figure out that the `AWSLambdaEvents` exists and
that it can be used for that (had to find out via a Java example! 😜) so
I think this could be useful and a somewhat common use case

### Modifications:

Added an example of a lambda that gets triggered when an object gets
uploaded to an S3 bucket.

I have not described how to set up the actual S3 event in AWS because I
figured if you needed such a lambda you'd know, but I can describe that
too in the README if needed

---------

Co-authored-by: Sébastien Stormacq <sebastien.stormacq@gmail.com>
2025-02-11 17:22:12 +01:00
Sébastien Stormacq bd0ec62646 Remove platform dance in some examples (#476)
Remove `#if os` on some examples
2025-01-31 16:03:29 +00:00
Sébastien Stormacq 4d7d23b9c1 [examples] Update to Swift Lambda Events 1.0.0 (#475)
Now that the swift Lambda event library has been tagged 1.0.0, update
all the examples to use `from: "1.0.0"` instead of `main` branch
2025-01-29 22:12:47 +00:00
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