diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index e7705a6c..48bf5364 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -36,7 +36,7 @@ jobs: # We pass the list of examples here, but we can't pass an array as argument # Instead, we pass a String with a valid JSON array. # The workaround is mentioned here https://github.com/orgs/community/discussions/11692 - examples: "[ 'APIGateway', 'BackgroundTasks', 'HelloJSON', 'HelloWorld', 'S3_AWSSDK', 'S3_Soto', 'Streaming', 'Testing' ]" + examples: "[ 'APIGateway', 'BackgroundTasks', 'HelloJSON', 'HelloWorld', 'S3_AWSSDK', 'S3_Soto', 'Streaming', 'Testing', 'Tutorial' ]" archive_plugin_enabled: true diff --git a/Examples/Tutorial/.gitignore b/Examples/Tutorial/.gitignore new file mode 100644 index 00000000..0023a534 --- /dev/null +++ b/Examples/Tutorial/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +/.build +/Packages +xcuserdata/ +DerivedData/ +.swiftpm/configuration/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc diff --git a/Examples/Tutorial/Package.swift b/Examples/Tutorial/Package.swift new file mode 100644 index 00000000..8fd031c1 --- /dev/null +++ b/Examples/Tutorial/Package.swift @@ -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) + ] +} diff --git a/Examples/Tutorial/Sources/main.swift b/Examples/Tutorial/Sources/main.swift new file mode 100644 index 00000000..db28931d --- /dev/null +++ b/Examples/Tutorial/Sources/main.swift @@ -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() diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/.shellcheckrc b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/.shellcheckrc new file mode 100644 index 00000000..95ac895f --- /dev/null +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/.shellcheckrc @@ -0,0 +1 @@ +disable=all \ No newline at end of file diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-01-01-package-init.sh b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-01-01-package-init.sh index be756692..600d8880 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-01-01-package-init.sh +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-01-01-package-init.sh @@ -1,3 +1,2 @@ -# shellcheck disable=all # Create a project directory -mkdir SquareNumber && cd SquareNumber \ No newline at end of file +mkdir Palindrome && cd Palindrome diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-01-02-package-init.sh b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-01-02-package-init.sh index c991cb0d..dfa52a08 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-01-02-package-init.sh +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-01-02-package-init.sh @@ -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 \ No newline at end of file +swift package init --type executable diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-01-03-package-init.sh b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-01-03-package-init.sh index 8afef332..54b1c96b 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-01-03-package-init.sh +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-01-03-package-init.sh @@ -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 . \ No newline at end of file +xed . diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-01-04-package-init.sh b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-01-04-package-init.sh index 89167eb5..a8fcbf5d 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-01-04-package-init.sh +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-01-04-package-init.sh @@ -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 . \ No newline at end of file diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-01-package.swift b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-01-package.swift index 9c5606b2..5f1d9b8d 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-01-package.swift +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-01-package.swift @@ -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" ) diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-02-package.swift b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-02-package.swift index e78f05ad..4fd09eba 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-02-package.swift +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-02-package.swift @@ -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) ] ) diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-03-package.swift b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-03-package.swift index d887ccc1..d1c46993 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-03-package.swift +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-03-package.swift @@ -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") ] ) diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-04-package.swift b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-04-package.swift index 3afdaae5..89a81437 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-04-package.swift +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-04-package.swift @@ -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") ] ) diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-05-package.swift b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-05-package.swift index 6e484fd6..35801e7c 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-05-package.swift +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-05-package.swift @@ -1,22 +1,22 @@ -// 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") ], targets: [ .executableTarget( - name: "SquareNumberLambda", + name: "PalindromeLambda", dependencies: [ .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime") ], diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-01-main.swift b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-01-main.swift index 58d19b38..72751f48 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-01-main.swift +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-01-main.swift @@ -1,2 +1,4 @@ -@main -struct SquareNumberHandler: SimpleLambdaHandler {} +// the data structure to represent the input parameter +struct Request: Decodable { + let text: String +} diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-02-main.swift b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-02-main.swift index b4b0b28d..5b0d8e2b 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-02-main.swift +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-02-main.swift @@ -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 +} diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-03-main.swift b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-03-main.swift index bf17f189..da6de3de 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-03-main.swift +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-03-main.swift @@ -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()) } diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-04-main.swift b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-04-main.swift index 6647aec0..4b14c43b 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-04-main.swift +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-04-main.swift @@ -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()) } diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-05-main.swift b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-05-main.swift index 805fb5ab..f308e04b 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-05-main.swift +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-05-main.swift @@ -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 {} } diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-06-main.swift b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-06-main.swift index a8257061..0a382bc1 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-06-main.swift +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-06-main.swift @@ -1,19 +1,32 @@ 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 { - Number(result: event.number * event.number) - } + // call the business function and return a response + let result = isPalindrome(event.text) + return Response( + text: event.text, + isPalindrome: result, + message: "Your text is \(result ? "a" : "not a") palindrome" + ) } diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-07-main.swift b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-07-main.swift new file mode 100644 index 00000000..c777c23b --- /dev/null +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-07-main.swift @@ -0,0 +1,35 @@ +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 + + // call the business function and return a response + 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() diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-02-console-output.sh b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-02-console-output.sh new file mode 100644 index 00000000..3d862f5d --- /dev/null +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-02-console-output.sh @@ -0,0 +1,2 @@ +2025-01-02T14:59:29+0100 info LocalLambdaServer : [AWSLambdaRuntimeCore] +LocalLambdaServer started and listening on 127.0.0.1:7000, receiving events on /invoke diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-03-console-output.sh b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-03-console-output.sh deleted file mode 100644 index 8e4a9630..00000000 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-03-console-output.sh +++ /dev/null @@ -1,7 +0,0 @@ -# shellcheck disable=all - -2023-04-14T11:42:21+0200 info LocalLambdaServer : [AWSLambdaRuntimeCore] LocalLambdaServer started and listening on 127.0.0.1:7000, receiving events on /invoke -2023-04-14T11:42:21+0200 info Lambda : [AWSLambdaRuntimeCore] lambda runtime starting with LambdaConfiguration - General(logLevel: info)) - Lifecycle(id: 104957691689708, maxTimes: 0, stopSignal: TERM) - RuntimeEngine(ip: 127.0.0.1, port: 7000, requestTimeout: nil diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-03-curl.sh b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-03-curl.sh new file mode 100644 index 00000000..c8f991a2 --- /dev/null +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-03-curl.sh @@ -0,0 +1,5 @@ +curl --header "Content-Type: application/json" \ + --request POST \ + --data '{"text": "Was it a car or a cat I saw?"}' \ + http://127.0.0.1:7000/invoke + diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-04-curl.sh b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-04-curl.sh index 31102f68..7928ac36 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-04-curl.sh +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-04-curl.sh @@ -1,7 +1,7 @@ -# shellcheck disable=all +curl --header "Content-Type: application/json" \ + --request POST \ + --data '{"text": "Was it a car or a cat I saw?"}' \ + http://127.0.0.1:7000/invoke -curl --header "Content-Type: application/json" \ - --request POST \ - --data '{"number": 3}' \ - http://localhost:7000/invoke +{"message":"Your text is a palindrome","isPalindrome":true,"text":"Was it a car or a cat I saw?"} diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-05-curl.sh b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-05-curl.sh deleted file mode 100644 index c5f90a8c..00000000 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-05-curl.sh +++ /dev/null @@ -1,8 +0,0 @@ -# shellcheck disable=all - -curl --header "Content-Type: application/json" \ - --request POST \ - --data '{"number": 3}' \ - http://localhost:7000/invoke - -{"result":9} diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-06-terminal.sh b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-06-terminal.sh index a6439f30..59fc671e 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-06-terminal.sh +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-06-terminal.sh @@ -1,3 +1 @@ -# shellcheck disable=all - -export LOCAL_LAMBDA_SERVER_ENABLED=true +swift run diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-07-terminal.sh b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-07-terminal.sh index 529df84f..6e4d6a3d 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-07-terminal.sh +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-07-terminal.sh @@ -1,4 +1,6 @@ -# shellcheck disable=all - -export LOCAL_LAMBDA_SERVER_ENABLED=true swift run + +Building for debugging... +[1/1] Write swift-version--58304C5D6DBC2206.txt +Build of product 'PalindromeLambda' complete! (0.11s) +2025-01-02T15:12:49+0100 info LocalLambdaServer : [AWSLambdaRuntimeCore] LocalLambdaServer started and listening on 127.0.0.1:7000, receiving events on /invoke diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-08-terminal.sh b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-08-terminal.sh deleted file mode 100644 index 38245018..00000000 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-08-terminal.sh +++ /dev/null @@ -1,12 +0,0 @@ -# shellcheck disable=all - -export LOCAL_LAMBDA_SERVER_ENABLED=true -swift run - -Building for debugging... -Build complete! (0.20s) -2023-04-14T10:52:25+0200 info LocalLambdaServer : [AWSLambdaRuntimeCore] LocalLambdaServer started and listening on 127.0.0.1:7000, receiving events on /invoke -2023-04-14T10:52:25+0200 info Lambda : [AWSLambdaRuntimeCore] lambda runtime starting with LambdaConfiguration - General(logLevel: info)) - Lifecycle(id: 102943961260250, maxTimes: 0, stopSignal: TERM) - RuntimeEngine(ip: 127.0.0.1, port: 7000, requestTimeout: nil diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-01-02-plugin-archive.sh b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-01-02-plugin-archive.sh index 097ba893..1f5ca9d8 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-01-02-plugin-archive.sh +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-01-02-plugin-archive.sh @@ -1,4 +1 @@ -# shellcheck disable=all - swift package archive --allow-network-connections docker - diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-01-03-plugin-archive.sh b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-01-03-plugin-archive.sh index b85f866b..c760c981 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-01-03-plugin-archive.sh +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-01-03-plugin-archive.sh @@ -1,21 +1,20 @@ -# shellcheck disable=all - swift package archive --allow-network-connections docker ------------------------------------------------------------------------- -building "squarenumberlambda" in docker +building "palindrome" in docker ------------------------------------------------------------------------- updating "swift:amazonlinux2" docker image amazonlinux2: Pulling from library/swift - Digest: sha256:5b0cbe56e35210fa90365ba3a4db9cd2b284a5b74d959fc1ee56a13e9c35b378 - Status: Image is up to date for swift:amazonlinux2 + Digest: sha256:df06a50f70e2e87f237bd904d2fc48195742ebda9f40b4a821c4d39766434009 +Status: Image is up to date for swift:amazonlinux2 docker.io/library/swift:amazonlinux2 -building "SquareNumberLambda" +building "PalindromeLambda" + [0/1] Planning build Building for production... -... + [0/2] Write swift-version-24593BA9C3E375BF.txt + Build of product 'PalindromeLambda' complete! (1.91s) ------------------------------------------------------------------------- -archiving "SquareNumberLambda" +archiving "PalindromeLambda" ------------------------------------------------------------------------- 1 archive created - * SquareNumberLambda at /Users/YourUserName/SquareNumberLambda/.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/SquareNumberLambda/SquareNumberLambda.zip - + * PalindromeLambda at /Users/sst/Palindrome/.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/PalindromeLambda/PalindromeLambda.zip diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-01-04-plugin-archive.sh b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-01-04-plugin-archive.sh index 93489314..c347694e 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-01-04-plugin-archive.sh +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-01-04-plugin-archive.sh @@ -1,23 +1,22 @@ -# shellcheck disable=all - swift package archive --allow-network-connections docker ------------------------------------------------------------------------- -building "squarenumberlambda" in docker +building "palindrome" in docker ------------------------------------------------------------------------- updating "swift:amazonlinux2" docker image amazonlinux2: Pulling from library/swift - Digest: sha256:5b0cbe56e35210fa90365ba3a4db9cd2b284a5b74d959fc1ee56a13e9c35b378 - Status: Image is up to date for swift:amazonlinux2 + Digest: sha256:df06a50f70e2e87f237bd904d2fc48195742ebda9f40b4a821c4d39766434009 +Status: Image is up to date for swift:amazonlinux2 docker.io/library/swift:amazonlinux2 -building "SquareNumberLambda" +building "PalindromeLambda" + [0/1] Planning build Building for production... -... + [0/2] Write swift-version-24593BA9C3E375BF.txt + Build of product 'PalindromeLambda' complete! (1.91s) ------------------------------------------------------------------------- -archiving "SquareNumberLambda" +archiving "PalindromeLambda" ------------------------------------------------------------------------- 1 archive created - * SquareNumberLambda at /Users/YourUserName/SquareNumberLambda/.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/SquareNumberLambda/SquareNumberLambda.zip - + * PalindromeLambda at /Users/sst/Palindrome/.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/PalindromeLambda/PalindromeLambda.zip -cp .build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/SquareNumberLambda/SquareNumberLambda.zip ~/Desktop +cp .build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/PalindromeLambda/PalindromeLambda.zip ~/Desktop diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-03-01-aws-cli.sh b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-03-01-aws-cli.sh index 8e10fd15..7a33b49d 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-03-01-aws-cli.sh +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-03-01-aws-cli.sh @@ -1,3 +1 @@ -# shellcheck disable=all - aws --version diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-03-02-lambda-invoke-hidden.sh b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-03-02-lambda-invoke-hidden.sh index ae79ebc6..6c9513cd 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-03-02-lambda-invoke-hidden.sh +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-03-02-lambda-invoke-hidden.sh @@ -1,9 +1,5 @@ -# shellcheck disable=all - -# # --region the AWS Region to send the command # --function-name the name of your function # --cli-binary-format tells the cli to use raw data as input (default is base64) # --payload the payload to pass to your function code # result.json the name of the file to store the response from the function - diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-03-02-lambda-invoke.sh b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-03-02-lambda-invoke.sh index ba3c2e53..00c96fcb 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-03-02-lambda-invoke.sh +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-03-02-lambda-invoke.sh @@ -1,6 +1,3 @@ -# shellcheck disable=all - -# # --region the AWS Region to send the command # --function-name the name of your function # --cli-binary-format tells the cli to use raw data as input (default is base64) @@ -9,8 +6,8 @@ aws lambda invoke \ --region us-west-2 \ - --function-name SquaredNumberLambda \ + --function-name PalindromeLambda \ --cli-binary-format raw-in-base64-out \ - --payload '{"number":3}' \ + --payload '{"text": "Was it a car or a cat I saw?"}' \ result.json diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-03-03-lambda-invoke.sh b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-03-03-lambda-invoke.sh index 78818b3b..032c722d 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-03-03-lambda-invoke.sh +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-03-03-lambda-invoke.sh @@ -1,6 +1,3 @@ -# shellcheck disable=all - -# # --region the AWS Region to send the command # --function-name the name of your function # --cli-binary-format tells the cli to use raw data as input (default is base64) @@ -9,9 +6,9 @@ aws lambda invoke \ --region us-west-2 \ - --function-name SquaredNumberLambda \ + --function-name PalindromeLambda \ --cli-binary-format raw-in-base64-out \ - --payload '{"number":3}' \ + --payload '{"text": "Was it a car or a cat I saw?"}' \ result.json { diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-03-04-lambda-invoke.sh b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-03-04-lambda-invoke.sh index 4cfb4ca8..52b17573 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-03-04-lambda-invoke.sh +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-03-04-lambda-invoke.sh @@ -1,6 +1,3 @@ -# shellcheck disable=all - -# # --region the AWS Region to send the command # --function-name the name of your function # --cli-binary-format tells the cli to use raw data as input (default is base64) @@ -9,9 +6,9 @@ aws lambda invoke \ --region us-west-2 \ - --function-name SquaredNumberLambda \ + --function-name PalindromeLambda \ --cli-binary-format raw-in-base64-out \ - --payload '{"number":3}' \ + --payload '{"text": "Was it a car or a cat I saw?"}' \ result.json { diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-03-05-lambda-invoke.sh b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-03-05-lambda-invoke.sh index fa8d6653..bb4889b6 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-03-05-lambda-invoke.sh +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/04-03-05-lambda-invoke.sh @@ -1,6 +1,3 @@ -# shellcheck disable=all - -# # --region the AWS Region to send the command # --function-name the name of your function # --cli-binary-format tells the cli to use raw data as input (default is base64) @@ -9,9 +6,9 @@ aws lambda invoke \ --region us-west-2 \ - --function-name SquaredNumberLambda \ + --function-name PalindromeLambda \ --cli-binary-format raw-in-base64-out \ - --payload '{"number":3}' \ + --payload '{"text": "Was it a car or a cat I saw?"}' \ result.json { @@ -20,5 +17,5 @@ aws lambda invoke \ } cat result.json -{"result":9} +{"text":"Was it a car or a cat I saw?","isPalindrome":true,"message":"Your text is a palindrome"} diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-01-terminal-package-init.png b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-01-terminal-package-init.png index 4e4a2f24..d12e5f9d 100644 Binary files a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-01-terminal-package-init.png and b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-01-terminal-package-init.png differ diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-01-xcode@2x.png b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-01-xcode@2x.png index 4aedcca1..96347ebf 100644 Binary files a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-01-xcode@2x.png and b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-01-xcode@2x.png differ diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-01-xcode~dark@2x.png b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-01-xcode~dark@2x.png index d22af823..bdb286e6 100644 Binary files a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-01-xcode~dark@2x.png and b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-01-xcode~dark@2x.png differ diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-03-01-rename-file@2x.png b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-03-01-rename-file@2x.png deleted file mode 100644 index 53d681a9..00000000 Binary files a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-03-01-rename-file@2x.png and /dev/null differ diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-03-01-rename-file~dark@2x.png b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-03-01-rename-file~dark@2x.png deleted file mode 100644 index 22e2814e..00000000 Binary files a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-03-01-rename-file~dark@2x.png and /dev/null differ diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-04-01-compile-run@2x.png.png b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-04-01-compile-run@2x.png.png new file mode 100644 index 00000000..7dfc7f64 Binary files /dev/null and b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-04-01-compile-run@2x.png.png differ diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-04-01-compile-run~dark@2x.png b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-04-01-compile-run~dark@2x.png new file mode 100644 index 00000000..3315a90c Binary files /dev/null and b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-04-01-compile-run~dark@2x.png differ diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-04-01-edit-scheme@2x.png b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-04-01-edit-scheme@2x.png deleted file mode 100644 index 7ad57885..00000000 Binary files a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-04-01-edit-scheme@2x.png and /dev/null differ diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-04-01-edit-scheme~dark@2x.png b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-04-01-edit-scheme~dark@2x.png deleted file mode 100644 index dc92b003..00000000 Binary files a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-04-01-edit-scheme~dark@2x.png and /dev/null differ diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-04-02-add-variable@2x.png b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-04-02-add-variable@2x.png deleted file mode 100644 index 3393f211..00000000 Binary files a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-04-02-add-variable@2x.png and /dev/null differ diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-04-02-add-variable~dark@2x.png b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-04-02-add-variable~dark@2x.png deleted file mode 100644 index 2b8e428d..00000000 Binary files a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/03-04-02-add-variable~dark@2x.png and /dev/null differ diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-03-select-region@2x.png b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-03-select-region@2x.png index 05fb1343..8460945b 100644 Binary files a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-03-select-region@2x.png and b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-03-select-region@2x.png differ diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-04-select-lambda@2x.png b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-04-select-lambda@2x.png index f6f13344..c79c495f 100644 Binary files a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-04-select-lambda@2x.png and b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-04-select-lambda@2x.png differ diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-04-select-lambda~dark@2x.png b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-04-select-lambda~dark@2x.png new file mode 100644 index 00000000..2abd5056 Binary files /dev/null and b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-04-select-lambda~dark@2x.png differ diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-05-create-function@2x.png b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-05-create-function@2x.png index d8c97d1e..1c123d5a 100644 Binary files a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-05-create-function@2x.png and b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-05-create-function@2x.png differ diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-05-create-function~dark@2x.png b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-05-create-function~dark@2x.png index 0715079c..c23355a9 100644 Binary files a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-05-create-function~dark@2x.png and b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-05-create-function~dark@2x.png differ diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-06-create-function@2x.png b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-06-create-function@2x.png index e3877acb..b8048d19 100644 Binary files a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-06-create-function@2x.png and b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-06-create-function@2x.png differ diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-06-create-function~dark@2x.png b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-06-create-function~dark@2x.png index 76795ecd..2fbdf277 100644 Binary files a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-06-create-function~dark@2x.png and b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-06-create-function~dark@2x.png differ diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-07-upload-zip@2x.png b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-07-upload-zip@2x.png index 23fd565a..0e4ba22c 100644 Binary files a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-07-upload-zip@2x.png and b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-07-upload-zip@2x.png differ diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-07-upload-zip~dark@2x.png b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-07-upload-zip~dark@2x.png index 4503837b..cf73d7f9 100644 Binary files a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-07-upload-zip~dark@2x.png and b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-07-upload-zip~dark@2x.png differ diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-08-upload-zip@2x.png b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-08-upload-zip@2x.png index b47ecf34..ef3d8160 100644 Binary files a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-08-upload-zip@2x.png and b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-08-upload-zip@2x.png differ diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-08-upload-zip~dark@2x.png b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-08-upload-zip~dark@2x.png index cc630173..4273f810 100644 Binary files a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-08-upload-zip~dark@2x.png and b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-08-upload-zip~dark@2x.png differ diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-09-test-lambda@2x.png b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-09-test-lambda@2x.png index 865d23b3..e9e7a309 100644 Binary files a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-09-test-lambda@2x.png and b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-09-test-lambda@2x.png differ diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-09-test-lambda~dark@2x.png b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-09-test-lambda~dark@2x.png index b197f191..61cf6147 100644 Binary files a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-09-test-lambda~dark@2x.png and b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-09-test-lambda~dark@2x.png differ diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-10-test-lambda-result@2x.png b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-10-test-lambda-result@2x.png index 174afb17..e962e7c2 100644 Binary files a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-10-test-lambda-result@2x.png and b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-10-test-lambda-result@2x.png differ diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-10-test-lambda-result~dark@2x.png b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-10-test-lambda-result~dark@2x.png index 61791e78..54ca5198 100644 Binary files a/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-10-test-lambda-result~dark@2x.png and b/Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/tutorials/04-02-10-test-lambda-result~dark@2x.png differ diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/tutorials/01-overview.tutorial b/Sources/AWSLambdaRuntimeCore/Documentation.docc/tutorials/01-overview.tutorial index f4a922b1..5ca896db 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/tutorials/01-overview.tutorial +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/tutorials/01-overview.tutorial @@ -14,5 +14,5 @@ It's a beginners' tutorial. The business logic of the function is very simple, i If you have any questions or recommendations, please [leave your feedback on GitHub](https://github.com/swift-server/swift-aws-lambda-runtime/issues) so that you can get your question answered and this tutorial can be improved. -*The following instructions were recorded on April 15, 2023 and the AWS Management Console may have changed since then. Feel free to raise an issue if you spot differences with our screenshots* +*The following instructions were recorded on January 2025 and the AWS Management Console may have changed since then. Feel free to raise an issue if you spot differences with our screenshots* } \ No newline at end of file diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/tutorials/03-write-function.tutorial b/Sources/AWSLambdaRuntimeCore/Documentation.docc/tutorials/03-write-function.tutorial index 428e3c71..d062e224 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/tutorials/03-write-function.tutorial +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/tutorials/03-write-function.tutorial @@ -1,6 +1,10 @@ @Tutorial(time: 15) { @Intro(title: "Write your first Lambda function") { - Learn how to create your project, add dependencies, and create and test your first Lambda function in Swift. + Learn how to create your project, add dependencies, and create and test your first Lambda function in Swift. + + In this example, we will create a Lambda function that receives a text and checks if this text is a palindrome or not. + + A palindrome is a word or phrase that reads the same forward and backward. } @Section(title: "Initialize a new project") { @@ -51,7 +55,7 @@ @Step { In the Xcode editor, replace the content of `Package.swift` with the file on the right side of the screen. - It defines a package for a project named `SquareNumberLambda`. The package name only matters when you build a library that is used by other Swift packages. + It defines a package for a project named `Palindrome`. The package name only matters when you build a library that is used by other Swift packages. > Comments are important here, do not skip them. They define the minimum version of Swift to use. @Code(name: "Package.swift", file: 03-02-01-package.swift) @@ -72,7 +76,7 @@ @Step { Add the `target` section. - In the `targets` section you specify your own targets. They are pretty comparable to targets you specify within an Xcode project (that's probably why they share the name 😎). In our example we only want to create an executable that is called `SquareNumberLambda`. An executable must have an entrypoint. This can be either a `main.swift` or an object that is marked with `@main`. For Lambda we will use the `@main` approach. + In the `targets` section you specify your own targets. They are pretty comparable to targets you specify within an Xcode project (that's probably why they share the name 😎). In our example we only want to create an executable that is called `PalindromeLambda`. An executable must have an entrypoint. This can be either a `main.swift` or an object that is marked with `@main`. For Lambda we will use the `@main` approach. @Code(name: "Package.swift", file: 03-02-04-package.swift) } @@ -94,58 +98,65 @@ } @Steps { + @Step { - Rename the file `main.swift` to something else. I typically use `Lambda.swift`. - - The `AWSLambdaRuntime` use the [`@main`](https://github.com/apple/swift-evolution/blob/main/proposals/0281-main-attribute.md) directive to designate the entry point in your code. - - >A `main.swift` file is always considered to be an entry point, even if it has no top-level code. Because of this, placing the @main-designated type in a `main.swift` file is an error. - - @Image(source: 03-03-01-rename-file, alt: "Rename the file in Xcode IDE") + Open the `main.swift` file, remove the code generated and write the code to represent the request sent to your Lambda function. + + Input parameters must conform to the `Decodable` protocol. This ensures that your Lambda function accepts any JSON input. + + > When your function is triggered by another AWS service, we modeled most of the input and output data format for you. You can add the dependency on [https://github.com/swift-server/swift-aws-lambda-events](https://github.com/swift-server/swift-aws-lambda-events) and import `AWSLambdaEvents` in your code. + + @Code(name: "main.swift", file: 03-03-01-main.swift) + } + + @Step { + Write the code to represent the response returned by your Lambda function. + + Output parameters must conform to the `Encodable` protocol. This ensures that your Lambda function returns a valid JSON output. Your function might also return `Void` if it does not return any value. + + > You can also write function that stream a response back to the caller. This is useful when you have a large amount of data to return. See the [Lambda Streaming example](https://github.com/swift-server/swift-aws-lambda-runtime/tree/main/Examples/Streaming) for more information. + + @Code(name: "main.swift", file: 03-03-02-main.swift) } - @Step { - Remove the code generated and create a `@main struct` that implements the protocol `SimpleLambdaHandler` + Write your business logic. - @Code(name: "Lambda.swift", file: 03-03-01-main.swift) + In real life project, this will be the most complex part of your code. It will live in spearate files or libraries. For this example, we will keep it simple and just return `true` if a `String` is a palindrome. + + @Code(name: "main.swift", file: 03-03-03-main.swift) } - + @Step { - Add an import statement to import the `AWSLambdaRuntime` library. - @Code(name: "Lambda.swift", file: 03-03-02-main.swift) + Add an `import` statement to import the `AWSLambdaRuntime` library. + + @Code(name: "main.swift", file: 03-03-04-main.swift) } - + @Step { - Write the `handle(_:context:) async throws -> Output` function as defined in `SimpleLambdaHandler` protocol. - - The `handle(_:context:)` function is the entry point of the Lambda function. - @Code(name: "Lambda.swift", file: 03-03-03-main.swift) + Create a `LambdaRuntime` struct and add a handler function that will be called by the Lambda runtime. + + This function is passed as a closure to the initializer of the `LambdaRuntime` struct. It accepts two parameters: the input event and the context. The input event is the JSON payload sent to your Lambda function. The context provides information about the function, such as the function name, memory limit, and log group name. The function returns the output event, which is the JSON payload returned by your Lambda function or Void if your function does not return any value. + + @Code(name: "main.swift", file: 03-03-05-main.swift) } @Step { - Add the definition of the input and output parameters. - - Input and Output parameters must conform to the `Codable` protocol. This ensures that your Lambda function accepts a JSON input and creates a JSON output. - Your function can use any `Codable`. When your function is triggered by another AWS service, we modeled most of the input and output data format for you. You can add the dependency on https://github.com/swift-server/swift-aws-lambda-events and import `AWSLambdaEvents` in your code. + Add the business logic to the handler function and return the response. + + In this example, we call the `isPalindrome(_:)` function to check if the input string is a palindrome. Then, we create a response with the result of the check. - @Code(name: "Lambda.swift", file: 03-03-04-main.swift) + @Code(name: "main.swift", file: 03-03-06-main.swift) } @Step { - Modify the `struct` and the `handle(_:context:)` function to use your input and output parameter types. - - @Code(name: "Lambda.swift", file: 03-03-05-main.swift) - } + Start the runtime by calling the `run()` function. - @Step { - Add your function-specific business logic. - - As mentioned earlier, this example is very simple, it just squares the number received as input. Your actual function can do whatever you want: call APIs, access a database, or any other task your business requires. + This function starts the Lambda runtime and listens for incoming requests. When a request is received, it calls the handler function with the input event and context. The handler function processes the request and returns the output event. The runtime sends the output event back to the caller. This function might `throw` an error if the runtime fails to process an event or if the handler function throws an error. This function is asynchronous and does not return until the runtime is stopped. - @Code(name: "Lambda.swift", file: 03-03-06-main.swift) + @Code(name: "main.swift", file: 03-03-07-main.swift) } - + } } @@ -160,61 +171,51 @@ @Steps { - The embedded web server starts only when an environment variable is defined. You will edit the Run step of the target scheme to include the environment variable. This will allow you to run your code from Xcode. + The embedded web server starts only when compiling in `DEBUG` mode and when the code is not run inside a Lambda function environment. You will start the test server directly from Xcode. @Step { - Select `Edit Scheme` under `SquareNumberLambda` target. + Compile and run your project. Click on the `Run` button (â–ļī¸) in Xcode. - @Image(source: 03-04-01-edit-scheme.png, alt: "Menu entry to edit schemes") + @Image(source: 03-04-01-compile-run.png, alt: "Compile and run the project") } - + @Step { - Add the `LOCAL_LAMBDA_SERVER_ENABLED` environment variable, with a value of `true` under `Run` settings. + Verify the server is correctlys started. You should see the following output in the console. - @Image(source: 03-04-02-add-variable.png, alt: "Add environment variable under Run settings") + @Code(name: "Console output", file: 03-04-02-console-output.sh) } @Step { - Compile and Run your project. You should see the following output in the console. + Now that the local server started, open a Terminal and use `curl` or any other HTTP client to POST your input payload to `127.0.0.1:7000`. - @Code(name: "Console output", file: 03-04-03-console-output.sh) + @Code(name: "curl command in a terminal", file: 03-04-03-curl.sh) } @Step { - Now that the local server started, open a Terminal and use `curl` or any other HTTP client to POST your input payload to `localhost:7000`. + When you pass `'{"text": "Was it a car or a cat I saw?"}'`, you should receive the response `{"message":"Your text is a palindrome","isPalindrome":true,"text":"Was it a car or a cat I saw?"}` + > Do not forget to stop the running scheme in Xcode (âšī¸) when you're done. + @Code(name: "curl command in a terminal", file: 03-04-04-curl.sh) } - - @Step { - When you pass `{"number":3}`, you should receive the response `{"result":9}` - - > Do not forget to stop the running scheme when you're done. - @Code(name: "curl command in a terminal", file: 03-04-05-curl.sh) - } Alternatively, you can use the command line from the Terminal. - @Step { - From a Terminal, set the `LOCAL_LAMBDA_SERVER_ENABLED` environment variable to `true` - @Code(name: "curl command in a terminal", file: 03-04-06-terminal.sh) - } - @Step { Use the command `swift run` to start the local embedded web server. - @Code(name: "curl command in a terminal", file: 03-04-07-terminal.sh) + @Code(name: "curl command in a terminal", file: 03-04-06-terminal.sh) } @Step { You should see the following output in the console. - @Code(name: "curl command in a terminal", file: 03-04-08-terminal.sh) + @Code(name: "curl command in a terminal", file: 03-04-07-terminal.sh) } @Step { - Now that the local server started, open a second tab in the Terminal and use `curl` or any other HTTP client to POST your input payload to `localhost:7000`. + Now that the local server started, open a second tab in the Terminal and use `curl` or any other HTTP client to POST your input payload to `127.0.0.1:7000`. > Do not forget to stop the local server with `CTRL-C` when you're done. - @Code(name: "curl command in a terminal", file: 03-04-04-curl.sh) + @Code(name: "curl command in a terminal", file: 03-04-03-curl.sh) } } diff --git a/Sources/AWSLambdaRuntimeCore/Documentation.docc/tutorials/04-deploy-function.tutorial b/Sources/AWSLambdaRuntimeCore/Documentation.docc/tutorials/04-deploy-function.tutorial index c2bc7552..70213532 100644 --- a/Sources/AWSLambdaRuntimeCore/Documentation.docc/tutorials/04-deploy-function.tutorial +++ b/Sources/AWSLambdaRuntimeCore/Documentation.docc/tutorials/04-deploy-function.tutorial @@ -65,7 +65,9 @@ } @Step { - On the top right side of the console, select the AWS Region where you want to deploy your Lambda function. You typically choose a Region close to your customers to minimize the network latency. For this demo, I selected **Oregon (us-west-2)** + On the top right side of the console, select the AWS Region where you want to deploy your Lambda function. + + You typically choose a Region close to your customers to minimize the network latency. For this demo, I selected **Oregon (us-west-2)** > AWS has multiple Regions across all continents. You can learn more about [AWS Global Infrastructure](https://aws.amazon.com/about-aws/global-infrastructure/regions_az/) here. @@ -79,17 +81,16 @@ } @Step { - On the top right side of the console, select **Create function**. + On the top right side of the Lambda page, select **Create function**. @Image(source: 04-02-05-create-function.png, alt: "Create function") } @Step { - Enter a **Function name**. I choose `SquaredNumberLambda`. Select `Provide your own bootstrap on Amazon Linux 2` as **Runtime**. And select `arm64` as **Architecture** when you build on a Mac with Apple Silicon. Leave all other parameter as default, and select **Create function** on the bottom right part. + Enter a **Function name**. I choose `PalindromeLambda`. Select `Provide your own bootstrap on Amazon Linux 2` as **Runtime**. And select `arm64` as **Architecture** when you build on a Mac with Apple Silicon. Leave all other parameter as default, and select **Create function** on the bottom right part. > The runtime architecture for Lambda (`arm64` or `x86_64`) must match the one of the machine where you compiled the code. When you compiled on an Intel-based Mac, use `x86_64`. When compiling on an Apple Silicon-based Mac select `arm64`. - @Image(source: 04-02-06-create-function.png, alt: "Create function details") } @@ -106,13 +107,13 @@ } @Step { - To verify everything works well, create a test event and invoke the function from the **Test** tab in the console. Enter `MyTestEvent` as **Event name**. Enter `{"number":3}` as **Event JSON**. Then, select **Test**. + To verify everything works well, create a test event and invoke the function from the **Test** tab in the console. Enter `MyTestEvent` as **Event name**. Enter `{"text": "Was it a car or a cat I saw?"}` as **Event JSON**. Then, select **Test**. @Image(source: 04-02-09-test-lambda.png, alt: "Create function") } @Step { - When the invocation succeeds, you can see the execution details and the result: `{ "result" : 9 }`. + When the invocation succeeds, you can see the execution details and the result: `{ "message": "Your text is a palindrome","isPalindrome": true, "text": "Was it a car or a cat I saw?"}`. > The execution result also shares the execution duration, the actual memory consumed and the logs generated by the function. These are important data to help you to fine-tune your function. Providing the function with more memory will also give it more compute power, resulting in lower execution time. @@ -164,7 +165,9 @@ } @Step { - When everything goes well, you will see `{ "result" : 9}`. Congratulation 🎉 ! + When everything goes well, you will see `{"text":"Was it a car or a cat I saw?","isPalindrome":true,"message":"Your text is a palindrome"}`. + + Congratulation 🎉 ! @Code(name: "Command to type in the Terminal", file: 04-03-05-lambda-invoke.sh)