Skip to content

Commit 0505243

Browse files
authored
Merge pull request #1 from tomerd/feature/samples
2 parents 91cdbbe + 6c4d566 commit 0505243

11 files changed

+107
-0
lines changed

Examples/Simple/.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.build

Examples/Simple/Package.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// swift-tools-version:5.2
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "swift-aws-lambda-events-samples",
7+
platforms: [
8+
.macOS(.v10_13),
9+
],
10+
products: [
11+
// demonstrate how to integrate with AWS API Gateway
12+
.executable(name: "APIGateway", targets: ["APIGateway"]),
13+
],
14+
dependencies: [
15+
// this is the dependency on the swift-aws-lambda-runtime library
16+
// in real-world projects this would say
17+
// FIXME: update this once the https://github.com/swift-server/swift-aws-lambda-runtime/pull/216 is merged
18+
// .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0")
19+
.package(url: "https://github.com/tomerd/swift-aws-lambda-runtime.git", .branch("remove-events")),
20+
// this is the dependency on the swift-aws-lambda-events library
21+
// .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime-events.git", from: "1.0.0")
22+
.package(name: "swift-aws-lambda-events", path: "../.."),
23+
],
24+
targets: [
25+
.target(name: "APIGateway", dependencies: [
26+
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
27+
.product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"),
28+
]),
29+
]
30+
)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 AWSLambdaEvents
16+
import AWSLambdaRuntime
17+
import NIO
18+
19+
// MARK: - Run Lambda
20+
21+
Lambda.run(APIGatewayProxyLambda())
22+
23+
// MARK: - Handler, Request and Response
24+
25+
// FIXME: Use proper Event abstractions once added to AWSLambdaRuntime
26+
struct APIGatewayProxyLambda: EventLoopLambdaHandler {
27+
public typealias In = APIGateway.V2.Request
28+
public typealias Out = APIGateway.V2.Response
29+
30+
public func handle(context: Lambda.Context, event: APIGateway.V2.Request) -> EventLoopFuture<APIGateway.V2.Response> {
31+
context.logger.debug("hello, api gateway!")
32+
return context.eventLoop.makeSucceededFuture(
33+
APIGateway.V2.Response(statusCode: .ok, body: "hello, world!")
34+
)
35+
}
36+
}

Examples/Simple/Tests/LinuxMain.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
preconditionFailure("use `swift test --enable-test-discovery`")

docker/docker-compose.1804.52.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ services:
1313
test:
1414
image: swift-aws-lambda-events:18.04-5.2
1515

16+
test-samples:
17+
image: swift-aws-lambda-events:18.04-5.2
18+
1619
shell:
1720
image: swift-aws-lambda-events:18.04-5.2

docker/docker-compose.al2.52.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ services:
1111
test:
1212
image: swift-aws-lambda-events:al2-5.2
1313

14+
test-samples:
15+
image: swift-aws-lambda-events:al2-5.2
16+
1417
shell:
1518
image: swift-aws-lambda-events:al2-5.2

docker/docker-compose.al2.53.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ services:
1111
test:
1212
image: swift-aws-lambda-events:al2-5.3
1313

14+
test-samples:
15+
image: swift-aws-lambda-events:al2-5.3
16+
1417
shell:
1518
image: swift-aws-lambda-events:al2-5.3

docker/docker-compose.al2.54.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ services:
1111
test:
1212
image: swift-aws-lambda-events:al2-5.4
1313

14+
test-samples:
15+
image: swift-aws-lambda-events:al2-5.4
16+
1417
shell:
1518
image: swift-aws-lambda-events:al2-5.4

docker/docker-compose.al2.55.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ services:
1111
test:
1212
image: swift-aws-lambda-events:al2-5.5
1313

14+
test-samples:
15+
image: swift-aws-lambda-events:al2-5.5
16+
1417
shell:
1518
image: swift-aws-lambda-events:al2-5.5

docker/docker-compose.al2.main.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ services:
1111
test:
1212
image: swift-aws-lambda-events:al2-main
1313

14+
test-samples:
15+
image: swift-aws-lambda-events:al2-main
16+
1417
shell:
1518
image: swift-aws-lambda-events:al2-main

docker/docker-compose.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ services:
3030
<<: *common
3131
command: /bin/bash -cl "swift test --enable-test-discovery -Xswiftc -warnings-as-errors $${SANITIZER_ARG-}"
3232

33+
test-samples:
34+
<<: *common
35+
command: >-
36+
/bin/bash -clx "
37+
swift build --package-path Examples/Simple
38+
"
39+
3340
# util
3441

3542
shell:

0 commit comments

Comments
 (0)