Skip to content

Commit c85c875

Browse files
authored
[doc] Getting Started documentation and tutorial (swift-server#300)
improved getting started documentation, with DocC
1 parent 5d300b2 commit c85c875

File tree

75 files changed

+975
-0
lines changed

Some content is hidden

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

75 files changed

+975
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
xcuserdata
99
Package.resolved
1010
.serverless
11+
.vscode
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Create a project directory
2+
mkdir SquareNumber && cd SquareNumber
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Create a project directory
2+
mkdir SquareNumber && cd SquareNumber
3+
# create a skeleton project
4+
swift package init --type executable
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Create a project directory
2+
mkdir SquareNumber && cd SquareNumber
3+
# create a skeleton project
4+
swift package init --type executable
5+
# open Xcode in the current directory
6+
xed .
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Create a project directory
2+
mkdir SquareNumber && cd SquareNumber
3+
# create a skeleton project
4+
swift package init --type executable
5+
# open Xcode in the current directory
6+
xed .
7+
# alternatively, you may open VSCode
8+
code .
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// swift-tools-version:5.8
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "SquareNumberLambda",
8+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// swift-tools-version:5.8
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "SquareNumberLambda",
8+
platforms: [
9+
.macOS(.v12),
10+
],
11+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// swift-tools-version:5.8
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "SquareNumberLambda",
8+
platforms: [
9+
.macOS(.v12),
10+
],
11+
dependencies: [
12+
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0-alpha"),
13+
],
14+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// swift-tools-version:5.8
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "SquareNumberLambda",
8+
platforms: [
9+
.macOS(.v12),
10+
],
11+
products: [
12+
.executable(name: "SquareNumberLambda", targets: ["SquareNumberLambda"]),
13+
],
14+
dependencies: [
15+
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0-alpha"),
16+
],
17+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// swift-tools-version:5.8
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "SquareNumberLambda",
8+
platforms: [
9+
.macOS(.v12),
10+
],
11+
products: [
12+
.executable(name: "SquareNumberLambda", targets: ["SquareNumberLambda"]),
13+
],
14+
dependencies: [
15+
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0-alpha"),
16+
],
17+
targets: [
18+
.executableTarget(
19+
name: "SquareNumberLambda",
20+
dependencies: [
21+
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
22+
],
23+
path: "."
24+
),
25+
]
26+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
@main
3+
struct SquareNumberHandler: SimpleLambdaHandler {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import AWSLambdaRuntime
2+
3+
@main
4+
struct SquareNumberHandler: SimpleLambdaHandler {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import AWSLambdaRuntime
2+
3+
@main
4+
struct SquareNumberHandler: SimpleLambdaHandler {
5+
func handle(_ event: Event, context: LambdaContext) async throws -> Output {}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import AWSLambdaRuntime
2+
3+
struct Input: Codable {
4+
let number: Double
5+
}
6+
7+
struct Number: Codable {
8+
let result: Double
9+
}
10+
11+
@main
12+
struct SquareNumberHandler: SimpleLambdaHandler {
13+
func handle(_ event: Event, context: LambdaContext) async throws -> Output {}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import AWSLambdaRuntime
2+
3+
struct Input: Codable {
4+
let number: Double
5+
}
6+
7+
struct Number: Codable {
8+
let result: Double
9+
}
10+
11+
@main
12+
struct SquareNumberHandler: SimpleLambdaHandler {
13+
typealias Event = Input
14+
typealias Output = Number
15+
16+
func handle(_ event: Event, context: LambdaContext) async throws -> Output {}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import AWSLambdaRuntime
2+
3+
struct Input: Codable {
4+
let number: Double
5+
}
6+
7+
struct Number: Codable {
8+
let result: Double
9+
}
10+
11+
@main
12+
struct SquareNumberHandler: SimpleLambdaHandler {
13+
typealias Event = Input
14+
typealias Output = Number
15+
16+
func handle(_ event: Event, context: LambdaContext) async throws -> Output {
17+
Number(result: event.number * event.number)
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2023-04-14T11:42:21+0200 info LocalLambdaServer : [AWSLambdaRuntimeCore] LocalLambdaServer started and listening on 127.0.0.1:7000, receiving events on /invoke
2+
2023-04-14T11:42:21+0200 info Lambda : [AWSLambdaRuntimeCore] lambda runtime starting with LambdaConfiguration
3+
General(logLevel: info))
4+
Lifecycle(id: 104957691689708, maxTimes: 0, stopSignal: TERM)
5+
RuntimeEngine(ip: 127.0.0.1, port: 7000, requestTimeout: nil
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
curl --header "Content-Type: application/json" \
2+
--request POST \
3+
--data '{"number": 3}' \
4+
http://localhost:7000/invoke
5+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
curl --header "Content-Type: application/json" \
2+
--request POST \
3+
--data '{"number": 3}' \
4+
http://localhost:7000/invoke
5+
6+
{"result":9}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export LOCAL_LAMBDA_SERVER_ENABLED=true
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export LOCAL_LAMBDA_SERVER_ENABLED=true
2+
swift run
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export LOCAL_LAMBDA_SERVER_ENABLED=true
2+
swift run
3+
4+
Building for debugging...
5+
Build complete! (0.20s)
6+
2023-04-14T10:52:25+0200 info LocalLambdaServer : [AWSLambdaRuntimeCore] LocalLambdaServer started and listening on 127.0.0.1:7000, receiving events on /invoke
7+
2023-04-14T10:52:25+0200 info Lambda : [AWSLambdaRuntimeCore] lambda runtime starting with LambdaConfiguration
8+
General(logLevel: info))
9+
Lifecycle(id: 102943961260250, maxTimes: 0, stopSignal: TERM)
10+
RuntimeEngine(ip: 127.0.0.1, port: 7000, requestTimeout: nil
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
swift package --disable-sandbox plugin archive
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
swift package --disable-sandbox plugin archive
2+
3+
-------------------------------------------------------------------------
4+
building "squarenumberlambda" in docker
5+
-------------------------------------------------------------------------
6+
updating "swift:amazonlinux2" docker image
7+
amazonlinux2: Pulling from library/swift
8+
Digest: sha256:5b0cbe56e35210fa90365ba3a4db9cd2b284a5b74d959fc1ee56a13e9c35b378
9+
Status: Image is up to date for swift:amazonlinux2
10+
docker.io/library/swift:amazonlinux2
11+
building "SquareNumberLambda"
12+
Building for production...
13+
...
14+
-------------------------------------------------------------------------
15+
archiving "SquareNumberLambda"
16+
-------------------------------------------------------------------------
17+
1 archive created
18+
* SquareNumberLambda at /Users/YourUserName/SquareNumberLambda/.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/SquareNumberLambda/SquareNumberLambda.zip
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
swift package --disable-sandbox plugin archive
2+
3+
-------------------------------------------------------------------------
4+
building "squarenumberlambda" in docker
5+
-------------------------------------------------------------------------
6+
updating "swift:amazonlinux2" docker image
7+
amazonlinux2: Pulling from library/swift
8+
Digest: sha256:5b0cbe56e35210fa90365ba3a4db9cd2b284a5b74d959fc1ee56a13e9c35b378
9+
Status: Image is up to date for swift:amazonlinux2
10+
docker.io/library/swift:amazonlinux2
11+
building "SquareNumberLambda"
12+
Building for production...
13+
...
14+
-------------------------------------------------------------------------
15+
archiving "SquareNumberLambda"
16+
-------------------------------------------------------------------------
17+
1 archive created
18+
* SquareNumberLambda at /Users/YourUserName/SquareNumberLambda/.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/SquareNumberLambda/SquareNumberLambda.zip
19+
20+
21+
cp .build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/SquareNumberLambda/SquareNumberLambda.zip ~/Desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
aws --version
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#
2+
# --region the AWS Region to send the command
3+
# --function-name the name of your function
4+
# --cli-binary-format tells the cli to use raw data as input (default is base64)
5+
# --payload the payload to pass to your function code
6+
# result.json the name of the file to store the response from the function
7+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#
2+
# --region the AWS Region to send the command
3+
# --function-name the name of your function
4+
# --cli-binary-format tells the cli to use raw data as input (default is base64)
5+
# --payload the payload to pass to your function code
6+
# result.json the name of the file to store the response from the function
7+
8+
aws lambda invoke \
9+
--region us-west-2 \
10+
--function-name SquaredNumberLambda \
11+
--cli-binary-format raw-in-base64-out \
12+
--payload '{"number":3}' \
13+
result.json
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# --region the AWS Region to send the command
3+
# --function-name the name of your function
4+
# --cli-binary-format tells the cli to use raw data as input (default is base64)
5+
# --payload the payload to pass to your function code
6+
# result.json the name of the file to store the response from the function
7+
8+
aws lambda invoke \
9+
--region us-west-2 \
10+
--function-name SquaredNumberLambda \
11+
--cli-binary-format raw-in-base64-out \
12+
--payload '{"number":3}' \
13+
result.json
14+
15+
{
16+
"StatusCode": 200,
17+
"ExecutedVersion": "$LATEST"
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# --region the AWS Region to send the command
3+
# --function-name the name of your function
4+
# --cli-binary-format tells the cli to use raw data as input (default is base64)
5+
# --payload the payload to pass to your function code
6+
# result.json the name of the file to store the response from the function
7+
8+
aws lambda invoke \
9+
--region us-west-2 \
10+
--function-name SquaredNumberLambda \
11+
--cli-binary-format raw-in-base64-out \
12+
--payload '{"number":3}' \
13+
result.json
14+
15+
{
16+
"StatusCode": 200,
17+
"ExecutedVersion": "$LATEST"
18+
}
19+
20+
cat result.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# --region the AWS Region to send the command
3+
# --function-name the name of your function
4+
# --cli-binary-format tells the cli to use raw data as input (default is base64)
5+
# --payload the payload to pass to your function code
6+
# result.json the name of the file to store the response from the function
7+
8+
aws lambda invoke \
9+
--region us-west-2 \
10+
--function-name SquaredNumberLambda \
11+
--cli-binary-format raw-in-base64-out \
12+
--payload '{"number":3}' \
13+
result.json
14+
15+
{
16+
"StatusCode": 200,
17+
"ExecutedVersion": "$LATEST"
18+
}
19+
20+
cat result.json
21+
{"result":9}
22+

0 commit comments

Comments
 (0)