Skip to content

Commit 8aaf872

Browse files
committed
Merge branch 'main' into sebsto/new-plugin-proposal
2 parents d029b18 + 3ce0a87 commit 8aaf872

File tree

148 files changed

+1998
-1295
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+1998
-1295
lines changed

.github/workflows/integration_tests.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ on:
1919
type: boolean
2020
description: "Boolean to enable the compilation of examples. Defaults to true."
2121
default: true
22+
archive_plugin_examples:
23+
type: string
24+
description: "The list of examples to run through the archive plugin test. Pass a String with a valid JSON array such as \"[ 'HelloWorld', 'APIGateway' ]\""
25+
required: true
26+
default: ""
2227
archive_plugin_enabled:
2328
type: boolean
2429
description: "Boolean to enable the test of the archive plugin. Defaults to true."
@@ -33,8 +38,8 @@ on:
3338
required: true
3439
matrix_linux_swift_container_image:
3540
type: string
36-
description: "Container image for the matrix job. Defaults to matching latest Swift Ubuntu image."
37-
default: "swift:amazonlinux2"
41+
description: "Container image for the matrix job. Defaults to matching latest Swift 6.1 Amazon Linux 2 image."
42+
default: "swiftlang/swift:nightly-6.1-amazonlinux2"
3843

3944
## We are cancelling previously triggered workflow runs
4045
concurrency:
@@ -54,7 +59,6 @@ jobs:
5459
# We are using only one Swift version
5560
swift:
5661
- image: ${{ inputs.matrix_linux_swift_container_image }}
57-
swift_version: "6.0.1-amazonlinux2"
5862
container:
5963
image: ${{ matrix.swift.image }}
6064
steps:
@@ -88,7 +92,6 @@ jobs:
8892
- name: Run matrix job
8993
working-directory: ${{ github.event.repository.name }} # until we can use action/checkout@v4
9094
env:
91-
SWIFT_VERSION: ${{ matrix.swift.swift_version }}
9295
COMMAND: ${{ inputs.matrix_linux_command }}
9396
EXAMPLE: ${{ matrix.examples }}
9497
run: |
@@ -98,6 +101,10 @@ jobs:
98101
name: Test archive plugin
99102
if: ${{ inputs.archive_plugin_enabled }}
100103
runs-on: ubuntu-latest
104+
strategy:
105+
fail-fast: false
106+
matrix:
107+
examples: ${{ fromJson(inputs.archive_plugin_examples) }}
101108
steps:
102109
- name: Checkout repository
103110
uses: actions/checkout@v4
@@ -107,8 +114,10 @@ jobs:
107114
# https://github.com/actions/checkout/issues/766
108115
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
109116
- name: Test the archive plugin
117+
env:
118+
EXAMPLE: ${{ matrix.examples }}
110119
run: |
111-
.github/workflows/scripts/check-archive-plugin.sh
120+
.github/workflows/scripts/check-archive-plugin.sh
112121
113122
check-foundation:
114123
name: No dependencies on Foundation

.github/workflows/pull_request.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ jobs:
1212
license_header_check_project_name: "SwiftAWSLambdaRuntime"
1313
shell_check_enabled: true
1414
python_lint_check_enabled: true
15-
api_breakage_check_container_image: "swift:6.0-noble"
15+
api_breakage_check_container_image: "swiftlang/swift:nightly-6.1-jammy"
1616
docs_check_container_image: "swift:6.0-noble"
17-
format_check_container_image: "swiftlang/swift:nightly-6.0-jammy"
17+
format_check_container_image: "swiftlang/swift:nightly-6.1-jammy"
1818
yamllint_check_enabled: true
1919

2020
unit-tests:
@@ -36,8 +36,8 @@ jobs:
3636
# We pass the list of examples here, but we can't pass an array as argument
3737
# Instead, we pass a String with a valid JSON array.
3838
# The workaround is mentioned here https://github.com/orgs/community/discussions/11692
39-
examples: "[ 'APIGateway', 'APIGateway+LambdaAuthorizer', 'BackgroundTasks', 'HelloJSON', 'HelloWorld', 'S3_AWSSDK', 'S3_Soto', 'Streaming', 'Testing', 'Tutorial' ]"
40-
39+
examples: "[ 'APIGateway', 'APIGateway+LambdaAuthorizer', 'BackgroundTasks', 'HelloJSON', 'HelloWorld', 'ResourcesPackaging', 'S3EventNotifier', 'S3_AWSSDK', 'S3_Soto', 'Streaming', 'Testing', 'Tutorial' ]"
40+
archive_plugin_examples: "[ 'HelloWorld', 'ResourcesPackaging' ]"
4141
archive_plugin_enabled: true
4242

4343
swift-6-language-mode:

.github/workflows/scripts/check-archive-plugin.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@
1313
##
1414
##===----------------------------------------------------------------------===##
1515

16-
EXAMPLE=HelloWorld
16+
log() { printf -- "** %s\n" "$*" >&2; }
17+
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
18+
fatal() { error "$@"; exit 1; }
19+
20+
test -n "${EXAMPLE:-}" || fatal "EXAMPLE unset"
21+
1722
OUTPUT_DIR=.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager
1823
OUTPUT_FILE=${OUTPUT_DIR}/MyLambda/bootstrap
1924
ZIP_FILE=${OUTPUT_DIR}/MyLambda/MyLambda.zip
2025

21-
pushd Examples/${EXAMPLE} || exit 1
26+
pushd "Examples/${EXAMPLE}" || exit 1
2227

2328
# package the example (docker and swift toolchain are installed on the GH runner)
2429
LAMBDA_USE_LOCAL_DEPS=../.. swift package archive --allow-network-connections docker || exit 1
@@ -33,5 +38,10 @@ file "${OUTPUT_FILE}" | grep --silent ELF
3338
# does the ZIP file contain the bootstrap?
3439
unzip -l "${ZIP_FILE}" | grep --silent bootstrap
3540

36-
echo "✅ The archive plugin is OK"
41+
# if EXAMPLE is ResourcesPackaging, check if the ZIP file contains hello.txt
42+
if [ "$EXAMPLE" == "ResourcesPackaging" ]; then
43+
unzip -l "${ZIP_FILE}" | grep --silent hello.txt
44+
fi
45+
46+
echo "✅ The archive plugin is OK with example ${EXAMPLE}"
3747
popd || exit 1

.github/workflows/scripts/integration_tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ log() { printf -- "** %s\n" "$*" >&2; }
1919
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
2020
fatal() { error "$@"; exit 1; }
2121

22+
SWIFT_VERSION=$(swift --version)
2223
test -n "${SWIFT_VERSION:-}" || fatal "SWIFT_VERSION unset"
2324
test -n "${COMMAND:-}" || fatal "COMMAND unset"
2425
test -n "${EXAMPLE:-}" || fatal "EXAMPLE unset"

.licenseignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ Package.resolved
3333
*.yaml
3434
*.yml
3535
**/.npmignore
36-
**/*.json
36+
**/*.json
37+
**/*.txt

.spi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
version: 1
22
builder:
33
configs:
4-
- documentation_targets: [AWSLambdaRuntimeCore, AWSLambdaRuntime]
4+
- documentation_targets: [AWSLambdaRuntime]

Examples/APIGateway+LambdaAuthorizer/Package.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ import PackageDescription
55
// needed for CI to test the local version of the library
66
import struct Foundation.URL
77

8-
#if os(macOS)
9-
let platforms: [PackageDescription.SupportedPlatform]? = [.macOS(.v15)]
10-
#else
11-
let platforms: [PackageDescription.SupportedPlatform]? = nil
12-
#endif
13-
148
let package = Package(
159
name: "swift-aws-lambda-runtime-example",
1610
platforms: [.macOS(.v15)],
@@ -21,7 +15,7 @@ let package = Package(
2115
dependencies: [
2216
// during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below
2317
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main"),
24-
.package(url: "https://github.com/swift-server/swift-aws-lambda-events.git", branch: "main"),
18+
.package(url: "https://github.com/swift-server/swift-aws-lambda-events.git", from: "1.0.0"),
2519
],
2620
targets: [
2721
.executableTarget(

Examples/APIGateway/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let package = Package(
1414
dependencies: [
1515
// during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below
1616
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main"),
17-
.package(url: "https://github.com/swift-server/swift-aws-lambda-events.git", branch: "main"),
17+
.package(url: "https://github.com/swift-server/swift-aws-lambda-events.git", from: "1.0.0"),
1818
],
1919
targets: [
2020
.executableTarget(

Examples/CDK/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let package = Package(
1414
dependencies: [
1515
// during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below
1616
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main"),
17-
.package(url: "https://github.com/swift-server/swift-aws-lambda-events.git", branch: "main"),
17+
.package(url: "https://github.com/swift-server/swift-aws-lambda-events.git", from: "1.0.0"),
1818
],
1919
targets: [
2020
.executableTarget(

Examples/CDK/infra/package-lock.json

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Examples/HelloJSON/Package.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
// swift-tools-version:6.0
1+
// swift-tools-version:6.1
22

33
import PackageDescription
44

55
// needed for CI to test the local version of the library
66
import struct Foundation.URL
77

8-
#if os(macOS)
9-
let platforms: [PackageDescription.SupportedPlatform]? = [.macOS(.v15)]
10-
#else
11-
let platforms: [PackageDescription.SupportedPlatform]? = nil
12-
#endif
13-
148
let package = Package(
159
name: "swift-aws-lambda-runtime-example",
16-
platforms: platforms,
10+
platforms: [.macOS(.v15)],
1711
products: [
1812
.executable(name: "HelloJSON", targets: ["HelloJSON"])
1913
],
2014
dependencies: [
2115
// during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below
22-
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main")
16+
.package(
17+
url: "https://github.com/swift-server/swift-aws-lambda-runtime.git",
18+
branch: "ff-package-traits",
19+
traits: [
20+
.trait(name: "FoundationJSONSupport")
21+
]
22+
)
2323
],
2424
targets: [
2525
.executableTarget(

Examples/HelloWorld/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,35 @@ The handler is `(event: String, context: LambdaContext)`. The function takes two
1212

1313
The function return value will be encoded as your Lambda function response.
1414

15+
## Test locally
16+
17+
You can test your function locally before deploying it to AWS Lambda.
18+
19+
To start the local function, type the following commands:
20+
21+
```bash
22+
swift run
23+
```
24+
25+
It will compile your code and start the local server. You know the local server is ready to accept connections when you see this message.
26+
27+
```txt
28+
Building for debugging...
29+
[1/1] Write swift-version--644A47CB88185983.txt
30+
Build of product 'MyLambda' complete! (0.31s)
31+
2025-01-29T12:44:48+0100 info LocalServer : host="127.0.0.1" port=7000 [AWSLambdaRuntime] Server started and listening
32+
```
33+
34+
Then, from another Terminal, send your payload with `curl`. Note that the payload must be a valid JSON string. In the case of this function that accepts a simple String, it means the String must be wrapped in between double quotes.
35+
36+
```bash
37+
curl -d '"seb"' http://127.0.0.1:7000/invoke
38+
"Hello seb"
39+
```
40+
41+
> [!IMPORTANT]
42+
> The local server is only available in `DEBUG` mode. It will not start with `swift -c release run`.
43+
1544
## Build & Package
1645

1746
To build & archive the package, type the following commands.

Examples/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ This directory contains example code for Lambda functions.
2828

2929
- **[HelloWorld](HelloWorld/README.md)**: a simple Lambda function (requires [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)).
3030

31+
- **[S3EventNotifier](S3EventNotifier/README.md)**: a Lambda function that receives object-upload notifications from an [Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) bucket.
32+
3133
- **[S3_AWSSDK](S3_AWSSDK/README.md)**: a Lambda function that uses the [AWS SDK for Swift](https://docs.aws.amazon.com/sdk-for-swift/latest/developer-guide/getting-started.html) to invoke an [Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) API (requires [AWS SAM](https://aws.amazon.com/serverless/sam/)).
3234

3335
- **[S3_Soto](S3_Soto/README.md)**: a Lambda function that uses [Soto](https://github.com/soto-project/soto) to invoke an [Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) API (requires [AWS SAM](https://aws.amazon.com/serverless/sam/)).
@@ -64,4 +66,4 @@ To obtain these keys, you need an AWS account:
6466

6567
4. **(Optional) Generate Temporary Security Credentials**: If you’re using temporary credentials (which are more secure for short-term access), use AWS Security Token Service (STS). You can call the `GetSessionToken` or `AssumeRole` API to generate temporary credentials, including a session token.
6668

67-
With these in hand, you can use AWS SigV4 to securely sign your requests and interact with AWS services from your Swift app.
69+
With these in hand, you can use AWS SigV4 to securely sign your requests and interact with AWS services from your Swift app.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
xcuserdata/
5+
DerivedData/
6+
.swiftpm/configuration/registries.json
7+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
8+
.netrc
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// swift-tools-version: 6.0
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
// needed for CI to test the local version of the library
7+
import struct Foundation.URL
8+
9+
let package = Package(
10+
name: "ResourcesPackaging",
11+
platforms: [.macOS(.v15)],
12+
products: [
13+
.executable(name: "MyLambda", targets: ["MyLambda"])
14+
],
15+
dependencies: [
16+
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main")
17+
],
18+
targets: [
19+
.executableTarget(
20+
name: "MyLambda",
21+
dependencies: [
22+
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime")
23+
],
24+
path: ".",
25+
resources: [
26+
.process("hello.txt")
27+
]
28+
)
29+
]
30+
)
31+
32+
if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"],
33+
localDepsPath != "",
34+
let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]),
35+
v.isDirectory == true
36+
{
37+
// when we use the local runtime as deps, let's remove the dependency added above
38+
let indexToRemove = package.dependencies.firstIndex { dependency in
39+
if case .sourceControl(
40+
name: _,
41+
location: "https://github.com/swift-server/swift-aws-lambda-runtime.git",
42+
requirement: _
43+
) = dependency.kind {
44+
return true
45+
}
46+
return false
47+
}
48+
if let indexToRemove {
49+
package.dependencies.remove(at: indexToRemove)
50+
}
51+
52+
// then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..)
53+
print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)")
54+
package.dependencies += [
55+
.package(name: "swift-aws-lambda-runtime", path: localDepsPath)
56+
]
57+
}

0 commit comments

Comments
 (0)