Skip to content

Commit 87f42d7

Browse files
committed
move main package to repository root
1 parent 3c7f1c4 commit 87f42d7

File tree

17 files changed

+78
-53
lines changed

17 files changed

+78
-53
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.DS_Store
2-
.build_linux
2+
/.build
3+
/Packages
4+
/*.xcodeproj
35
lambda.zip
46
swift-shared-libs
57
swift-lambda-runtime.zip

ExampleLambda/Sources/ExampleLambda/main.swift

-38
This file was deleted.
File renamed without changes.
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"object": {
3+
"pins": [
4+
5+
]
6+
},
7+
"version": 1
8+
}

Examples/SquareNumber/Package.swift

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// swift-tools-version:4.2
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "SquareNumber",
7+
dependencies: [
8+
.package(path: "../../"),
9+
],
10+
targets: [
11+
.target(
12+
name: "SquareNumber",
13+
dependencies: ["AWSLambdaSwift"]),
14+
]
15+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import AWSLambdaSwift
2+
3+
struct Event: Codable {
4+
let number: Double
5+
}
6+
7+
struct Result: Codable {
8+
let result: Double
9+
}
10+
11+
func squareNumber(event: Event, context: Context) -> Result {
12+
let squaredNumber = event.number * event.number
13+
return Result(result: squaredNumber)
14+
}
15+
16+
let runtime = try Runtime()
17+
runtime.registerLambda("squareNumber", handlerFunction: squareNumber)
18+
try runtime.start()
File renamed without changes.
File renamed without changes.

ExampleLambda/Package.swift Examples/SyntaxHighlighter/Package.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
import PackageDescription
44

55
let package = Package(
6-
name: "ExampleLambda",
6+
name: "SyntaxHighlighter",
77
dependencies: [
8-
.package(path: "../AWSLambdaSwift"),
8+
.package(path: "../../"),
99
.package(url: "https://github.com/JohnSundell/Splash", from: "0.1.4")
1010
],
1111
targets: [
1212
.target(
13-
name: "ExampleLambda",
13+
name: "SyntaxHighlighter",
1414
dependencies: ["AWSLambdaSwift", "Splash"]),
1515
]
1616
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import AWSLambdaSwift
2+
import Splash
3+
4+
struct Event: Codable {
5+
let source: String
6+
}
7+
8+
struct Result: Codable {
9+
let html: String
10+
}
11+
12+
func highlightSyntax(event: Event, context: Context) -> Result {
13+
let highlighter = SyntaxHighlighter(format: HTMLOutputFormat())
14+
let html = highlighter.highlight(event.source)
15+
return Result(html: html)
16+
}
17+
18+
let runtime = try Runtime()
19+
runtime.registerLambda("highlightSyntax", handlerFunction: highlightSyntax)
20+
try runtime.start()

Makefile

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
EXECUTABLE=ExampleLambda
2-
PROJECT_PATH=ExampleLambda
3-
LAMBDA_BUNDLE_NAME=lambda
4-
LAMBDA_ZIP=$(LAMBDA_BUNDLE_NAME).zip
1+
EXAMPLE_LAMBDA=SquareNumber
2+
EXAMPLE_EXECUTABLE=SquareNumber
3+
EXAMPLE_PROJECT_PATH=Examples/SquareNumber
4+
# EXAMPLE_LAMBDA=SyntaxHighlighter
5+
# EXAMPLE_EXECUTABLE=SyntaxHighlighter
6+
# EXAMPLE_PROJECT_PATH=Examples/SyntaxHighlighter
7+
LAMBDA_ZIP=lambda.zip
58
SHARED_LIBS_FOLDER=swift-shared-libs
69
LAYER_ZIP=swift-lambda-runtime.zip
710

811
clean_lambda:
912
rm $(LAMBDA_ZIP) || true
10-
rm -rf $(PROJECT_PATH)/.build || true
13+
rm -rf $(EXAMPLE_PROJECT_PATH)/.build || true
1114

1215
build_lambda:
1316
docker run \
1417
--rm \
1518
--volume "$(shell pwd)/:/src" \
16-
--workdir "/src/$(PROJECT_PATH)" \
19+
--workdir "/src/$(EXAMPLE_PROJECT_PATH)" \
1720
swift \
1821
swift build
1922

2023
package_lambda: clean_lambda build_lambda
21-
zip -r -j $(LAMBDA_ZIP) $(PROJECT_PATH)/.build/debug/$(EXECUTABLE)
24+
zip -r -j $(LAMBDA_ZIP) $(EXAMPLE_PROJECT_PATH)/.build/debug/$(EXAMPLE_EXECUTABLE)
2225

2326
deploy_lambda: package_lambda
24-
aws lambda update-function-code --function-name SquareNumber --zip-file fileb://lambda.zip
25-
26-
invoke_lambda:
27-
aws lambda invoke --function-name SquareNumber --payload '{"number":9}' response.txt && cat response.txt && echo "" && (rm response.txt || true)
27+
aws lambda update-function-code --function-name $(EXAMPLE_LAMBDA) --zip-file fileb://lambda.zip
2828

2929
clean_layer:
3030
rm $(LAYER_ZIP) || true
File renamed without changes.

0 commit comments

Comments
 (0)