Skip to content

Commit bd39461

Browse files
committed
flatten examples
1 parent e861641 commit bd39461

39 files changed

+145
-110
lines changed

Examples/Simple/String/Package.swift renamed to Examples/Benchmark/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let package = Package(
1414
// this is the dependency on the swift-aws-lambda-runtime library
1515
// in real-world projects this would say
1616
// .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0")
17-
.package(name: "swift-aws-lambda-runtime", path: "../../.."),
17+
.package(name: "swift-aws-lambda-runtime", path: "../.."),
1818
],
1919
targets: [
2020
.executableTarget(

Examples/Benchmark/main.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the SwiftAWSLambdaRuntime open source project
4+
//
5+
// Copyright (c) 2020 Apple Inc. and the SwiftAWSLambdaRuntime project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
import AWSLambdaRuntimeCore
16+
import NIOCore
17+
18+
// If you would like to benchmark Swift's Lambda Runtime,
19+
// use this example which is more performant.
20+
// `EventLoopLambdaHandler` does not offload the Lambda processing to a separate thread
21+
// while the closure-based handlers do.
22+
23+
struct MyLambda: EventLoopLambdaHandler {
24+
typealias Event = String
25+
typealias Output = String
26+
27+
func handle(_ event: String, context: Lambda.Context) -> EventLoopFuture<String> {
28+
context.eventLoop.makeSucceededFuture("hello, world!")
29+
}
30+
}
31+
32+
Lambda.run { $0.eventLoop.makeSucceededFuture(MyLambda()) }

Examples/Deployment/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM swift:5.5-amazonlinux2
2+
3+
RUN yum -y install zip

Examples/LambdaFunctions/Package.swift renamed to Examples/Deployment/Package.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ let package = Package(
1313
// good for benchmarking
1414
.executable(name: "Benchmark", targets: ["Benchmark"]),
1515
// demonstrate different types of error handling
16-
.executable(name: "ErrorHandling", targets: ["ErrorHandling"]),
17-
// fully featured example with domain specific business logic
18-
.executable(name: "CurrencyExchange", targets: ["CurrencyExchange"]),
1916
],
2017
dependencies: [
2118
// this is the dependency on the swift-aws-lambda-runtime library
@@ -30,11 +27,5 @@ let package = Package(
3027
.executableTarget(name: "HelloWorld", dependencies: [
3128
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
3229
]),
33-
.executableTarget(name: "ErrorHandling", dependencies: [
34-
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
35-
]),
36-
.executableTarget(name: "CurrencyExchange", dependencies: [
37-
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
38-
]),
3930
]
4031
)

Examples/LambdaFunctions/README.md renamed to Examples/Deployment/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# Lambda Functions Examples
1+
# Deployment Examples
22

33
This sample project is a collection of Lambda functions that demonstrates
44
how to write a simple Lambda function in Swift, and how to package and deploy it
55
to the AWS Lambda platform.
66

7-
The scripts are prepared to work from the `LambdaFunctions` folder.
7+
The scripts are prepared to work from the `Deployment` folder.
88

99
```
1010
git clone https://github.com/swift-server/swift-aws-lambda-runtime.git
11-
cd swift-aws-lambda-runtime/Examples/LambdaFunctions
11+
cd swift-aws-lambda-runtime/Examples/Deployment
1212
```
1313

1414
Note: The example scripts assume you have [jq](https://stedolan.github.io/jq/download/) command line tool installed.
@@ -27,7 +27,7 @@ Steps to deploy this sample to AWS Lambda using the AWS CLI:
2727
./scripts/deploy.sh
2828
```
2929

30-
Notes:
30+
Notes:
3131
- This script assumes you have AWS CLI installed and credentials setup in `~/.aws/credentials`.
3232
- The default lambda function name is `SwiftSample`. You can specify a different one updating `lambda_name` in `deploy.sh`
3333
- Update `s3_bucket=swift-lambda-test` in `deploy.sh` before running (AWS S3 buckets require a unique global name)
@@ -129,7 +129,7 @@ The `serverless-deploy.sh` script passes through any parameters to the Serverles
129129

130130
For the APIGateway sample:
131131

132-
The Serverless template will provide an endpoint which you can use to test the Lambda.
132+
The Serverless template will provide an endpoint which you can use to test the Lambda.
133133

134134
Outuput example:
135135

@@ -174,4 +174,4 @@ For all other samples use the AWS Lambda console.
174174
./scripts/serverless-remove.sh
175175
```
176176

177-
The script will ask you which sample Lambda you wish to remove from the previous depolyment.
177+
The script will ask you which sample Lambda you wish to remove from the previous deployment.

Examples/LambdaFunctions/scripts/build-and-package.sh renamed to Examples/Deployment/scripts/build-and-package.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ echo "done"
2727
echo "-------------------------------------------------------------------------"
2828
echo "building \"$executable\" lambda"
2929
echo "-------------------------------------------------------------------------"
30-
docker run --rm -v "$workspace":/workspace -w /workspace/Examples/LambdaFunctions builder \
30+
docker run --rm -v "$workspace":/workspace -w /workspace/Examples/Deployment builder \
3131
bash -cl "swift build --product $executable -c release"
3232
echo "done"
3333

3434
echo "-------------------------------------------------------------------------"
3535
echo "packaging \"$executable\" lambda"
3636
echo "-------------------------------------------------------------------------"
37-
docker run --rm -v "$workspace":/workspace -w /workspace/Examples/LambdaFunctions builder \
37+
docker run --rm -v "$workspace":/workspace -w /workspace/Examples/Deployment builder \
3838
bash -cl "./scripts/package.sh $executable"
3939
echo "done"

Examples/Simple/String/Lambda.swift renamed to Examples/Echo/Lambda.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
import AWSLambdaRuntimeCore
15+
import AWSLambdaRuntime
1616

1717
// in this example we are receiving and responding with strings
1818

@@ -25,8 +25,8 @@ struct MyLambda: LambdaHandler {
2525
// setup your resources that you want to reuse for every invocation here.
2626
}
2727

28-
func handle(_ event: String, context: Lambda.Context) async throws -> String {
29-
// as an example, respond with the event's reversed body
30-
String(event.reversed())
28+
func handle(_ input: String, context: Lambda.Context) async throws -> String {
29+
// as an example, respond with the input's reversed
30+
String(input.reversed())
3131
}
3232
}

Examples/Simple/Codable/Package.swift renamed to Examples/Echo/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let package = Package(
1414
// this is the dependency on the swift-aws-lambda-runtime library
1515
// in real-world projects this would say
1616
// .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0")
17-
.package(name: "swift-aws-lambda-runtime", path: "../../.."),
17+
.package(name: "swift-aws-lambda-runtime", path: "../.."),
1818
],
1919
targets: [
2020
.executableTarget(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import AWSLambdaRuntime
1717
// MARK: - Run Lambda
1818

1919
@main
20-
struct ErrorsHappenHandler: LambdaHandler {
20+
struct MyLambda: LambdaHandler {
2121
typealias Event = Request
2222
typealias Output = Response
2323

Examples/ErrorHandling/Package.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// swift-tools-version:5.5
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "swift-aws-lambda-runtime-example",
7+
platforms: [
8+
.macOS(.v12),
9+
],
10+
products: [
11+
.executable(name: "MyLambda", targets: ["MyLambda"]),
12+
],
13+
dependencies: [
14+
// this is the dependency on the swift-aws-lambda-runtime library
15+
// in real-world projects this would say
16+
// .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0")
17+
.package(name: "swift-aws-lambda-runtime", path: "../.."),
18+
],
19+
targets: [
20+
.executableTarget(
21+
name: "MyLambda",
22+
dependencies: [
23+
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
24+
],
25+
path: "."
26+
),
27+
]
28+
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import Logging
2424
// MARK: - Run Lambda
2525

2626
@main
27-
struct CurrencyExchangeHandler: LambdaHandler {
27+
struct MyLambda: LambdaHandler {
2828
typealias Event = Request
2929
typealias Output = [Exchange]
3030

Examples/Foundation/Package.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// swift-tools-version:5.5
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "swift-aws-lambda-runtime-example",
7+
platforms: [
8+
.macOS(.v12),
9+
],
10+
products: [
11+
.executable(name: "MyLambda", targets: ["MyLambda"]),
12+
],
13+
dependencies: [
14+
// this is the dependency on the swift-aws-lambda-runtime library
15+
// in real-world projects this would say
16+
// .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0")
17+
.package(name: "swift-aws-lambda-runtime", path: "../.."),
18+
],
19+
targets: [
20+
.executableTarget(
21+
name: "MyLambda",
22+
dependencies: [
23+
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
24+
],
25+
path: "."
26+
),
27+
]
28+
)

Examples/Simple/Codable/Lambda.swift renamed to Examples/JSON/Lambda.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
import AWSLambdaRuntime
16-
import NIOCore
1716

1817
struct Request: Codable {
1918
let body: String

Examples/JSON/Package.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// swift-tools-version:5.5
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "swift-aws-lambda-runtime-example",
7+
platforms: [
8+
.macOS(.v12),
9+
],
10+
products: [
11+
.executable(name: "MyLambda", targets: ["MyLambda"]),
12+
],
13+
dependencies: [
14+
// this is the dependency on the swift-aws-lambda-runtime library
15+
// in real-world projects this would say
16+
// .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0")
17+
.package(name: "swift-aws-lambda-runtime", path: "../.."),
18+
],
19+
targets: [
20+
.executableTarget(
21+
name: "MyLambda",
22+
dependencies: [
23+
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
24+
],
25+
path: "."
26+
),
27+
]
28+
)

Examples/LambdaFunctions/Dockerfile

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

Examples/LambdaFunctions/scripts/SAM/CurrencyExchange-template.yml

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

Examples/LambdaFunctions/scripts/SAM/ErrorHandling-template.yml

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

Examples/LambdaFunctions/scripts/serverless/CurrencyExchange-template.yml

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

Examples/LambdaFunctions/scripts/serverless/ErrorHandling-template.yml

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

Examples/Simple/Testing/Package.swift renamed to Examples/Testing/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let package = Package(
1414
// this is the dependency on the swift-aws-lambda-runtime library
1515
// in real-world projects this would say
1616
// .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0")
17-
.package(name: "swift-aws-lambda-runtime", path: "../../.."),
17+
.package(name: "swift-aws-lambda-runtime", path: "../.."),
1818
],
1919
targets: [
2020
.executableTarget(

docker/docker-compose.al2.main.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,9 @@ services:
1010

1111
test:
1212
image: swift-aws-lambda:al2-main
13-
command: /bin/bash -cl "swift test --enable-test-discovery -Xswiftc -warnings-as-errors $${SANITIZER_ARG-} -Xswiftc -Xfrontend -Xswiftc -enable-experimental-concurrency"
1413

1514
test-samples:
1615
image: swift-aws-lambda:al2-main
17-
command: >-
18-
/bin/bash -clx "
19-
swift build -Xswiftc -Xfrontend -Xswiftc -enable-experimental-concurrency --package-path Examples/LambdaFunctions &&
20-
swift build -Xswiftc -Xfrontend -Xswiftc -enable-experimental-concurrency --package-path Examples/LocalDebugging/MyLambda"
2116

2217
shell:
2318
image: swift-aws-lambda:al2-main

0 commit comments

Comments
 (0)