-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the text, code sample, and screenshots for runtime v2 Address #371
- Loading branch information
Showing
67 changed files
with
377 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
xcuserdata/ | ||
DerivedData/ | ||
.swiftpm/configuration/registries.json | ||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata | ||
.netrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// swift-tools-version: 6.0 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
import struct Foundation.URL | ||
|
||
let package = Package( | ||
name: "Palindrome", | ||
platforms: [.macOS(.v15)], | ||
dependencies: [ | ||
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main") | ||
], | ||
targets: [ | ||
// Targets are the basic building blocks of a package, defining a module or a test suite. | ||
// Targets can depend on other targets in this package and products from dependencies. | ||
.executableTarget( | ||
name: "Palindrome", | ||
dependencies: [ | ||
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime") | ||
] | ||
) | ||
] | ||
) | ||
|
||
if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], | ||
localDepsPath != "", | ||
let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), | ||
v.isDirectory == true | ||
{ | ||
// when we use the local runtime as deps, let's remove the dependency added above | ||
let indexToRemove = package.dependencies.firstIndex { dependency in | ||
if case .sourceControl( | ||
name: _, | ||
location: "https://github.com/swift-server/swift-aws-lambda-runtime.git", | ||
requirement: _ | ||
) = dependency.kind { | ||
return true | ||
} | ||
return false | ||
} | ||
if let indexToRemove { | ||
package.dependencies.remove(at: indexToRemove) | ||
} | ||
|
||
// then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..) | ||
print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)") | ||
package.dependencies += [ | ||
.package(name: "swift-aws-lambda-runtime", path: localDepsPath) | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the SwiftAWSLambdaRuntime open source project | ||
// | ||
// Copyright (c) 2025 Apple Inc. and the SwiftAWSLambdaRuntime project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import AWSLambdaRuntime | ||
|
||
// the data structure to represent the input parameter | ||
struct Request: Decodable { | ||
let text: String | ||
} | ||
|
||
// the data structure to represent the response parameter | ||
struct Response: Encodable { | ||
let text: String | ||
let isPalindrome: Bool | ||
let message: String | ||
} | ||
|
||
// the business function | ||
func isPalindrome(_ text: String) -> Bool { | ||
let cleanedText = text.lowercased().filter { $0.isLetter } | ||
return cleanedText == String(cleanedText.reversed()) | ||
} | ||
|
||
// the lambda handler function | ||
let runtime = LambdaRuntime { | ||
(event: Request, context: LambdaContext) -> Response in | ||
|
||
let result = isPalindrome(event.text) | ||
return Response( | ||
text: event.text, | ||
isPalindrome: result, | ||
message: "Your text is \(result ? "a" : "not a") palindrome" | ||
) | ||
} | ||
|
||
// start the runtime | ||
try await runtime.run() |
1 change: 1 addition & 0 deletions
1
Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/.shellcheckrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
disable=all |
3 changes: 1 addition & 2 deletions
3
Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-01-01-package-init.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
# shellcheck disable=all | ||
# Create a project directory | ||
mkdir SquareNumber && cd SquareNumber | ||
mkdir Palindrome && cd Palindrome |
6 changes: 3 additions & 3 deletions
6
Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-01-02-package-init.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# shellcheck disable=all | ||
# Create a project directory | ||
mkdir SquareNumber && cd SquareNumber | ||
mkdir Palindrome && cd Palindrome | ||
|
||
# create a skeleton project | ||
swift package init --type executable | ||
swift package init --type executable |
7 changes: 4 additions & 3 deletions
7
Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-01-03-package-init.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
# shellcheck disable=all | ||
# Create a project directory | ||
mkdir SquareNumber && cd SquareNumber | ||
mkdir Palindrome && cd Palindrome | ||
|
||
# create a skeleton project | ||
swift package init --type executable | ||
|
||
# open Xcode in the current directory | ||
xed . | ||
xed . |
6 changes: 4 additions & 2 deletions
6
Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-01-04-package-init.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
# shellcheck disable=all | ||
# Create a project directory | ||
mkdir SquareNumber && cd SquareNumber | ||
mkdir Palindrome && cd Palindrome | ||
|
||
# create a skeleton project | ||
swift package init --type executable | ||
|
||
# open Xcode in the current directory | ||
xed . | ||
|
||
# alternatively, you may open VSCode | ||
code . |
4 changes: 2 additions & 2 deletions
4
Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-01-package.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
// swift-tools-version:5.8 | ||
// swift-tools-version:6.0 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "SquareNumberLambda" | ||
name: "Palindrome" | ||
) |
6 changes: 3 additions & 3 deletions
6
Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-02-package.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
// swift-tools-version:5.8 | ||
// swift-tools-version:6.0 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "SquareNumberLambda", | ||
name: "Palindrome", | ||
platforms: [ | ||
.macOS(.v12) | ||
.macOS(.v15) | ||
] | ||
) |
8 changes: 4 additions & 4 deletions
8
Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-03-package.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
// swift-tools-version:5.8 | ||
// swift-tools-version:6.0 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "SquareNumberLambda", | ||
name: "Palindrome", | ||
platforms: [ | ||
.macOS(.v12) | ||
.macOS(.v15) | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0-alpha") | ||
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main") | ||
] | ||
) |
10 changes: 5 additions & 5 deletions
10
Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-04-package.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
// swift-tools-version:5.8 | ||
// swift-tools-version:6.0 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "SquareNumberLambda", | ||
name: "Palindrome", | ||
platforms: [ | ||
.macOS(.v12) | ||
.macOS(.v15) | ||
], | ||
products: [ | ||
.executable(name: "SquareNumberLambda", targets: ["SquareNumberLambda"]) | ||
.executable(name: "PalindromeLambda", targets: ["PalindromeLambda"]) | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0-alpha") | ||
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main") | ||
] | ||
) |
12 changes: 6 additions & 6 deletions
12
Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-05-package.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-01-main.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
@main | ||
struct SquareNumberHandler: SimpleLambdaHandler {} | ||
// the data structure to represent the input parameter | ||
struct Request: Decodable { | ||
let text: String | ||
} |
13 changes: 10 additions & 3 deletions
13
Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-02-main.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
import AWSLambdaRuntime | ||
// the data structure to represent the input parameter | ||
struct Request: Decodable { | ||
let text: String | ||
} | ||
|
||
@main | ||
struct SquareNumberHandler: SimpleLambdaHandler {} | ||
// the data structure to represent the response parameter | ||
struct Response: Encodable { | ||
let text: String | ||
let isPalindrome: Bool | ||
let message: String | ||
} |
19 changes: 15 additions & 4 deletions
19
Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-03-main.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
import AWSLambdaRuntime | ||
// the data structure to represent the input parameter | ||
struct Request: Decodable { | ||
let text: String | ||
} | ||
|
||
// the data structure to represent the response parameter | ||
struct Response: Encodable { | ||
let text: String | ||
let isPalindrome: Bool | ||
let message: String | ||
} | ||
|
||
@main | ||
struct SquareNumberHandler: SimpleLambdaHandler { | ||
func handle(_ event: Event, context: LambdaContext) async throws -> Output {} | ||
// the business function | ||
func isPalindrome(_ text: String) -> Bool { | ||
let cleanedText = text.lowercased().filter { $0.isLetter } | ||
return cleanedText == String(cleanedText.reversed()) | ||
} |
19 changes: 12 additions & 7 deletions
19
Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-04-main.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
import AWSLambdaRuntime | ||
|
||
struct Input: Codable { | ||
let number: Double | ||
// the data structure to represent the input parameter | ||
struct Request: Decodable { | ||
let text: String | ||
} | ||
|
||
struct Number: Codable { | ||
let result: Double | ||
// the data structure to represent the response parameter | ||
struct Response: Encodable { | ||
let text: String | ||
let isPalindrome: Bool | ||
let message: String | ||
} | ||
|
||
@main | ||
struct SquareNumberHandler: SimpleLambdaHandler { | ||
func handle(_ event: Event, context: LambdaContext) async throws -> Output {} | ||
// the business function | ||
func isPalindrome(_ text: String) -> Bool { | ||
let cleanedText = text.lowercased().filter { $0.isLetter } | ||
return cleanedText == String(cleanedText.reversed()) | ||
} |
26 changes: 17 additions & 9 deletions
26
Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-05-main.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,25 @@ | ||
import AWSLambdaRuntime | ||
|
||
struct Input: Codable { | ||
let number: Double | ||
// the data structure to represent the input parameter | ||
struct Request: Decodable { | ||
let text: String | ||
} | ||
|
||
struct Number: Codable { | ||
let result: Double | ||
// the data structure to represent the response parameter | ||
struct Response: Encodable { | ||
let text: String | ||
let isPalindrome: Bool | ||
let message: String | ||
} | ||
|
||
@main | ||
struct SquareNumberHandler: SimpleLambdaHandler { | ||
typealias Event = Input | ||
typealias Output = Number | ||
// the business function | ||
func isPalindrome(_ text: String) -> Bool { | ||
let cleanedText = text.lowercased().filter { $0.isLetter } | ||
return cleanedText == String(cleanedText.reversed()) | ||
} | ||
|
||
// the lambda handler function | ||
let runtime = LambdaRuntime { | ||
(event: Request, context: LambdaContext) -> Response in | ||
|
||
func handle(_ event: Event, context: LambdaContext) async throws -> Output {} | ||
} |
Oops, something went wrong.