Skip to content

Commit 410f0b8

Browse files
committed
Sections 1, 2, and 3
1 parent 855e237 commit 410f0b8

38 files changed

+193
-157
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
disable=all
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
# shellcheck disable=all
21
# Create a project directory
3-
mkdir SquareNumber && cd SquareNumber
2+
mkdir Palindrome && cd Palindrome
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# shellcheck disable=all
21
# Create a project directory
3-
mkdir SquareNumber && cd SquareNumber
2+
mkdir Palindrome && cd Palindrome
3+
44
# create a skeleton project
5-
swift package init --type executable
5+
swift package init --type executable
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
# shellcheck disable=all
21
# Create a project directory
3-
mkdir SquareNumber && cd SquareNumber
2+
mkdir Palindrome && cd Palindrome
3+
44
# create a skeleton project
55
swift package init --type executable
6+
67
# open Xcode in the current directory
7-
xed .
8+
xed .
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
# shellcheck disable=all
21
# Create a project directory
3-
mkdir SquareNumber && cd SquareNumber
2+
mkdir Palindrome && cd Palindrome
3+
44
# create a skeleton project
55
swift package init --type executable
6+
67
# open Xcode in the current directory
78
xed .
9+
810
# alternatively, you may open VSCode
911
code .

Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-01-package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
import PackageDescription
55

66
let package = Package(
7-
name: "SquareNumberLambda"
7+
name: "Palindrome"
88
)

Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-02-package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import PackageDescription
55

66
let package = Package(
7-
name: "SquareNumberLambda",
7+
name: "Palindrome",
88
platforms: [
99
.macOS(.v15)
1010
]

Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-03-package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
import PackageDescription
55

66
let package = Package(
7-
name: "SquareNumberLambda",
7+
name: "Palindrome",
88
platforms: [
99
.macOS(.v15)
1010
],
1111
dependencies: [
12-
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "main")
12+
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main")
1313
]
1414
)

Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-04-package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
import PackageDescription
55

66
let package = Package(
7-
name: "SquareNumberLambda",
7+
name: "Palindrome",
88
platforms: [
99
.macOS(.v15)
1010
],
1111
products: [
12-
.executable(name: "SquareNumberLambda", targets: ["SquareNumberLambda"])
12+
.executable(name: "PalindromeLambda", targets: ["PalindromeLambda"])
1313
],
1414
dependencies: [
15-
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "main")
15+
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main")
1616
]
1717
)

Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-02-05-package.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
import PackageDescription
55

66
let package = Package(
7-
name: "SquareNumberLambda",
7+
name: "Palindrome",
88
platforms: [
99
.macOS(.v15)
1010
],
1111
products: [
12-
.executable(name: "SquareNumberLambda", targets: ["SquareNumberLambda"])
12+
.executable(name: "PalindromeLambda", targets: ["PalindromeLambda"])
1313
],
1414
dependencies: [
15-
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "main")
15+
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main")
1616
],
1717
targets: [
1818
.executableTarget(
19-
name: "SquareNumberLambda",
19+
name: "PalindromeLambda",
2020
dependencies: [
2121
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime")
2222
],
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// the data structure to represent the input parameter
22
struct Request: Decodable {
3-
let number: Double
3+
let text: String
44
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// the data structure to represent the input parameter
22
struct Request: Decodable {
3-
let number: Double
3+
let text: String
44
}
55

6-
// the data structure to represent the output response
6+
// the data structure to represent the response parameter
77
struct Response: Encodable {
8-
let result: Double
8+
let text: String
9+
let isPalindrome: Bool
10+
let message: String
911
}
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
import AWSLambdaRuntime
2-
31
// the data structure to represent the input parameter
42
struct Request: Decodable {
5-
let number: Double
3+
let text: String
64
}
75

8-
// the data structure to represent the output response
6+
// the data structure to represent the response parameter
97
struct Response: Encodable {
10-
let result: Double
8+
let text: String
9+
let isPalindrome: Bool
10+
let message: String
1111
}
1212

13-
// the Lambda runtime
14-
let runtime = LambdaRuntime {
13+
// the business function
14+
func isPalindrome(_ text: String) -> Bool {
15+
let cleanedText = text.lowercased().filter { $0.isLetter }
16+
return cleanedText == String(cleanedText.reversed())
17+
}

Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-04-main.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ import AWSLambdaRuntime
22

33
// the data structure to represent the input parameter
44
struct Request: Decodable {
5-
let number: Double
5+
let text: String
66
}
77

8-
// the data structure to represent the output response
8+
// the data structure to represent the response parameter
99
struct Response: Encodable {
10-
let result: Double
10+
let text: String
11+
let isPalindrome: Bool
12+
let message: String
1113
}
1214

13-
// the Lambda runtime
14-
let runtime = LambdaRuntime {
15-
(event: Request, context: LambdaContext) in
16-
15+
// the business function
16+
func isPalindrome(_ text: String) -> Bool {
17+
let cleanedText = text.lowercased().filter { $0.isLetter }
18+
return cleanedText == String(cleanedText.reversed())
1719
}

Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-05-main.swift

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,24 @@ import AWSLambdaRuntime
22

33
// the data structure to represent the input parameter
44
struct Request: Decodable {
5-
let number: Double
5+
let text: String
66
}
77

8-
// the data structure to represent the output response
8+
// the data structure to represent the response parameter
99
struct Response: Encodable {
10-
let result: Double
10+
let text: String
11+
let isPalindrome: Bool
12+
let message: String
1113
}
1214

13-
// the Lambda runtime
14-
let runtime = LambdaRuntime {
15-
(event: Request, context: LambdaContext) in
15+
// the business function
16+
func isPalindrome(_ text: String) -> Bool {
17+
let cleanedText = text.lowercased().filter { $0.isLetter }
18+
return cleanedText == String(cleanedText.reversed())
19+
}
1620

17-
Response(result: event.number * event.number)
18-
}
21+
// the lambda handler function
22+
let runtime = LambdaRuntime {
23+
(event: Request, context: LambdaContext) -> Response in
24+
25+
}

Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-03-06-main.swift

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,27 @@ import AWSLambdaRuntime
22

33
// the data structure to represent the input parameter
44
struct Request: Decodable {
5-
let number: Double
5+
let text: String
66
}
77

8-
// the data structure to represent the output response
8+
// the data structure to represent the response parameter
99
struct Response: Encodable {
10-
let result: Double
10+
let text: String
11+
let isPalindrome: Bool
12+
let message: String
1113
}
1214

13-
// the Lambda runtime
14-
let runtime = LambdaRuntime {
15-
(event: Request, context: LambdaContext) in
16-
17-
Response(result: event.number * event.number)
15+
// the business function
16+
func isPalindrome(_ text: String) -> Bool {
17+
let cleanedText = text.lowercased().filter { $0.isLetter }
18+
return cleanedText == String(cleanedText.reversed())
1819
}
1920

20-
// start the loop
21-
try await runtime.run()
21+
// the lambda handler function
22+
let runtime = LambdaRuntime {
23+
(event: Request, context: LambdaContext) -> Response in
24+
25+
// call the business function and return a response
26+
let result = isPalindrome(event.text)
27+
return Response(text: event.text, isPalindrome: result, message: "Your text is \(result ? "a" : "not a") palindrome")
28+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import AWSLambdaRuntime
2+
3+
// the data structure to represent the input parameter
4+
struct Request: Decodable {
5+
let text: String
6+
}
7+
8+
// the data structure to represent the response parameter
9+
struct Response: Encodable {
10+
let text: String
11+
let isPalindrome: Bool
12+
let message: String
13+
}
14+
15+
// the business function
16+
func isPalindrome(_ text: String) -> Bool {
17+
let cleanedText = text.lowercased().filter { $0.isLetter }
18+
return cleanedText == String(cleanedText.reversed())
19+
}
20+
21+
// the lambda handler function
22+
let runtime = LambdaRuntime {
23+
(event: Request, context: LambdaContext) -> Response in
24+
25+
// call the business function and return a response
26+
let result = isPalindrome(event.text)
27+
return Response(text: event.text, isPalindrome: result, message: "Your text is \(result ? "a" : "not a") palindrome")
28+
}
29+
30+
// start the runtime
31+
try await runtime.run()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2025-01-02T14:59:29+0100 info LocalLambdaServer : [AWSLambdaRuntimeCore]
2+
LocalLambdaServer started and listening on 127.0.0.1:7000, receiving events on /invoke

Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-03-console-output.sh

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
curl --header "Content-Type: application/json" \
2+
--request POST \
3+
--data '{"text": "Was it a car or a cat I saw?"}' \
4+
http://127.0.0.1:7000/invoke
5+
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# shellcheck disable=all
1+
curl --header "Content-Type: application/json" \
2+
--request POST \
3+
--data '{"text": "Was it a car or a cat I saw?"}' \
4+
http://127.0.0.1:7000/invoke
25

3-
curl --header "Content-Type: application/json" \
4-
--request POST \
5-
--data '{"number": 3}' \
6-
http://localhost:7000/invoke
6+
{"message":"Your text is a palindrome","isPalindrome":true,"text":"Was it a car or a cat I saw?"}
77

Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-05-curl.sh

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
# shellcheck disable=all
2-
3-
export LOCAL_LAMBDA_SERVER_ENABLED=true
1+
swift run
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# shellcheck disable=all
2-
3-
export LOCAL_LAMBDA_SERVER_ENABLED=true
41
swift run
2+
3+
Building for debugging...
4+
[1/1] Write swift-version--58304C5D6DBC2206.txt
5+
Build of product 'PalindromeLambda' complete! (0.11s)
6+
2025-01-02T15:12:49+0100 info LocalLambdaServer : [AWSLambdaRuntimeCore] LocalLambdaServer started and listening on 127.0.0.1:7000, receiving events on /invoke

Sources/AWSLambdaRuntimeCore/Documentation.docc/Resources/code/03-04-08-terminal.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.
Loading
Loading
Loading
Loading

Sources/AWSLambdaRuntimeCore/Documentation.docc/tutorials/01-overview.tutorial

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ It's a beginners' tutorial. The business logic of the function is very simple, i
1414

1515
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.
1616

17-
*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*
17+
*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*
1818
}

0 commit comments

Comments
 (0)