Skip to content

Commit a0984ef

Browse files
committed
add an example in the CI
1 parent 2c6c328 commit a0984ef

File tree

5 files changed

+93
-1
lines changed

5 files changed

+93
-1
lines changed

.github/workflows/pull_request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ 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', 'HummingbirdLambda', 'ResourcesPackaging', 'S3EventNotifier', 'S3_AWSSDK', 'S3_Soto', 'Streaming', 'Streaming+Codable', 'ServiceLifecycle+Postgres', 'Testing', 'Tutorial' ]"
39+
examples: "[ 'APIGateway', 'APIGateway+LambdaAuthorizer', 'BackgroundTasks', 'HelloJSON', 'HelloWorld', 'HelloWorldNoTraits', 'HummingbirdLambda', 'ResourcesPackaging', 'S3EventNotifier', 'S3_AWSSDK', 'S3_Soto', 'Streaming', 'Streaming+Codable', 'ServiceLifecycle+Postgres', 'Testing', 'Tutorial' ]"
4040
archive_plugin_examples: "[ 'HelloWorld', 'ResourcesPackaging' ]"
4141
archive_plugin_enabled: true
4242

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
response.json
2+
samconfig.toml
3+
template.yaml
4+
Makefile
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// swift-tools-version:6.1
2+
3+
import PackageDescription
4+
5+
// needed for CI to test the local version of the library
6+
import struct Foundation.URL
7+
8+
let package = Package(
9+
name: "swift-aws-lambda-runtime-example",
10+
platforms: [.macOS(.v15)],
11+
products: [
12+
.executable(name: "MyLambda", targets: ["MyLambda"])
13+
],
14+
dependencies: [
15+
// during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below
16+
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "2.0.0-beta.3", traits: [])
17+
],
18+
targets: [
19+
.executableTarget(
20+
name: "MyLambda",
21+
dependencies: [
22+
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime")
23+
],
24+
path: "Sources"
25+
)
26+
]
27+
)
28+
29+
if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"],
30+
localDepsPath != "",
31+
let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]),
32+
v.isDirectory == true
33+
{
34+
// when we use the local runtime as deps, let's remove the dependency added above
35+
let indexToRemove = package.dependencies.firstIndex { dependency in
36+
if case .sourceControl(
37+
name: _,
38+
location: "https://github.com/swift-server/swift-aws-lambda-runtime.git",
39+
requirement: _
40+
) = dependency.kind {
41+
return true
42+
}
43+
return false
44+
}
45+
if let indexToRemove {
46+
package.dependencies.remove(at: indexToRemove)
47+
}
48+
49+
// then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..)
50+
print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)")
51+
package.dependencies += [
52+
.package(name: "swift-aws-lambda-runtime", path: localDepsPath, traits: [])
53+
]
54+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Hello World, with no traits
2+
3+
This is a simple example of an AWS Lambda function that takes a `String` as input parameter and returns a `String` as response.
4+
5+
This function disables all the default traits: the support for JSON from Foundation, for Swift Service Lifecycle, and for the local server for testing.
6+
7+
The main reasons of the existence of this example are
8+
9+
1. to show you how to disable traits when using the Lambda Runtime Library
10+
2. to add an integration test to our continous integration pipeline to make sure the library compiles with no traits enabled.
11+
12+
For more details about this example, refer to the example in `Examples/HelloWorld`.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the SwiftAWSLambdaRuntime open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the SwiftAWSLambdaRuntime project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import AWSLambdaRuntime
16+
import NIOCore
17+
18+
let runtime = LambdaRuntime { event , response, context in
19+
try await response.writeAndFinish(ByteBuffer(string: "Hello World!"))
20+
}
21+
22+
try await runtime.run()

0 commit comments

Comments
 (0)