From e861641a9b516d83f7b9479cec786c3bdbf020b1 Mon Sep 17 00:00:00 2001 From: tom doron Date: Wed, 22 Sep 2021 17:55:01 -0700 Subject: [PATCH 1/2] update and add examples to new APIs motivation: keep code up to date with API changes changes: * take advantage of @main where possible * move the top level Sample code to a new "Simple" examples subdirectory * add a sample that demonstrates how to test a lambda now that SwiftPM can test executables directly * update the test-sample docker setup to build & test th new samples * fix a few typos and In/Out typealias left overs --- .../Sources/Benchmark/main.swift | 3 +- .../MyLambdaHandler.swift => Lambda.swift} | 3 +- .../LocalDebugging/MyLambda/Package.swift | 6 ++-- .../MyLambda/Tests/LinuxMain.swift | 15 --------- .../Shared/Tests/LinuxMain.swift | 15 --------- .../Simple/Codable/Lambda.swift | 26 +++++++-------- Examples/Simple/Codable/Package.swift | 28 ++++++++++++++++ .../Simple/String/Lambda.swift | 17 ++++++---- Examples/Simple/String/Package.swift | 28 ++++++++++++++++ Examples/Simple/Testing/Package.swift | 30 +++++++++++++++++ Examples/Simple/Testing/Sources/Lambda.swift | 32 +++++++++++++++++++ .../Testing/Tests/LambdaTests.swift} | 15 +++++++-- Package.swift | 2 -- Sources/AWSLambdaTesting/Lambda+Testing.swift | 10 +++--- .../LambdaHandlers.swift | 8 ++--- .../Lambda+CodeableTest.swift | 2 +- Tests/LinuxMain.swift | 15 --------- docker/docker-compose.yaml | 6 +++- scripts/soundness.sh | 2 +- 19 files changed, 175 insertions(+), 88 deletions(-) rename Examples/LocalDebugging/MyLambda/{Sources/MyLambda/MyLambdaHandler.swift => Lambda.swift} (96%) delete mode 100644 Examples/LocalDebugging/MyLambda/Tests/LinuxMain.swift delete mode 100644 Examples/LocalDebugging/Shared/Tests/LinuxMain.swift rename Sources/CodableSample/main.swift => Examples/Simple/Codable/Lambda.swift (58%) create mode 100644 Examples/Simple/Codable/Package.swift rename Sources/StringSample/main.swift => Examples/Simple/String/Lambda.swift (63%) create mode 100644 Examples/Simple/String/Package.swift create mode 100644 Examples/Simple/Testing/Package.swift create mode 100644 Examples/Simple/Testing/Sources/Lambda.swift rename Examples/{LambdaFunctions/Tests/LinuxMain.swift => Simple/Testing/Tests/LambdaTests.swift} (55%) delete mode 100644 Tests/LinuxMain.swift diff --git a/Examples/LambdaFunctions/Sources/Benchmark/main.swift b/Examples/LambdaFunctions/Sources/Benchmark/main.swift index d0d54706..ce6d3e0d 100644 --- a/Examples/LambdaFunctions/Sources/Benchmark/main.swift +++ b/Examples/LambdaFunctions/Sources/Benchmark/main.swift @@ -19,7 +19,6 @@ import NIO // use this example which is more performant. // `EventLoopLambdaHandler` does not offload the Lambda processing to a separate thread // while the closure-based handlers do. -Lambda.run { $0.eventLoop.makeSucceededFuture(BenchmarkHandler()) } struct BenchmarkHandler: EventLoopLambdaHandler { typealias Event = String @@ -29,3 +28,5 @@ struct BenchmarkHandler: EventLoopLambdaHandler { context.eventLoop.makeSucceededFuture("hello, world!") } } + +Lambda.run { $0.eventLoop.makeSucceededFuture(BenchmarkHandler()) } diff --git a/Examples/LocalDebugging/MyLambda/Sources/MyLambda/MyLambdaHandler.swift b/Examples/LocalDebugging/MyLambda/Lambda.swift similarity index 96% rename from Examples/LocalDebugging/MyLambda/Sources/MyLambda/MyLambdaHandler.swift rename to Examples/LocalDebugging/MyLambda/Lambda.swift index 3d4c88d3..b6a5d865 100644 --- a/Examples/LocalDebugging/MyLambda/Sources/MyLambda/MyLambdaHandler.swift +++ b/Examples/LocalDebugging/MyLambda/Lambda.swift @@ -17,8 +17,9 @@ import Shared // set LOCAL_LAMBDA_SERVER_ENABLED env variable to "true" to start // a local server simulator which will allow local debugging + @main -struct MyLambdaHandler: LambdaHandler { +struct MyLambda: LambdaHandler { typealias Event = Request typealias Output = Response diff --git a/Examples/LocalDebugging/MyLambda/Package.swift b/Examples/LocalDebugging/MyLambda/Package.swift index 17de9dcb..2b8860de 100644 --- a/Examples/LocalDebugging/MyLambda/Package.swift +++ b/Examples/LocalDebugging/MyLambda/Package.swift @@ -19,10 +19,12 @@ let package = Package( ], targets: [ .executableTarget( - name: "MyLambda", dependencies: [ + name: "MyLambda", + dependencies: [ .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), .product(name: "Shared", package: "Shared"), - ] + ], + path: "." ), ] ) diff --git a/Examples/LocalDebugging/MyLambda/Tests/LinuxMain.swift b/Examples/LocalDebugging/MyLambda/Tests/LinuxMain.swift deleted file mode 100644 index c46de763..00000000 --- a/Examples/LocalDebugging/MyLambda/Tests/LinuxMain.swift +++ /dev/null @@ -1,15 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the SwiftAWSLambdaRuntime open source project -// -// Copyright (c) 2020 Apple Inc. and the SwiftAWSLambdaRuntime project authors -// Licensed under Apache License v2.0 -// -// See LICENSE.txt for license information -// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors -// -// SPDX-License-Identifier: Apache-2.0 -// -//===----------------------------------------------------------------------===// - -preconditionFailure("use `swift test --enable-test-discovery`") diff --git a/Examples/LocalDebugging/Shared/Tests/LinuxMain.swift b/Examples/LocalDebugging/Shared/Tests/LinuxMain.swift deleted file mode 100644 index c46de763..00000000 --- a/Examples/LocalDebugging/Shared/Tests/LinuxMain.swift +++ /dev/null @@ -1,15 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the SwiftAWSLambdaRuntime open source project -// -// Copyright (c) 2020 Apple Inc. and the SwiftAWSLambdaRuntime project authors -// Licensed under Apache License v2.0 -// -// See LICENSE.txt for license information -// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors -// -// SPDX-License-Identifier: Apache-2.0 -// -//===----------------------------------------------------------------------===// - -preconditionFailure("use `swift test --enable-test-discovery`") diff --git a/Sources/CodableSample/main.swift b/Examples/Simple/Codable/Lambda.swift similarity index 58% rename from Sources/CodableSample/main.swift rename to Examples/Simple/Codable/Lambda.swift index dae2b39e..b4fb90ec 100644 --- a/Sources/CodableSample/main.swift +++ b/Examples/Simple/Codable/Lambda.swift @@ -2,7 +2,7 @@ // // This source file is part of the SwiftAWSLambdaRuntime open source project // -// Copyright (c) 2017-2020 Apple Inc. and the SwiftAWSLambdaRuntime project authors +// Copyright (c) 2021 Apple Inc. and the SwiftAWSLambdaRuntime project authors // Licensed under Apache License v2.0 // // See LICENSE.txt for license information @@ -24,23 +24,19 @@ struct Response: Codable { } // in this example we are receiving and responding with codables. Request and Response above are examples of how to use -// codables to model your reqeuest and response objects -struct Handler: EventLoopLambdaHandler { +// codables to model your request and response objects + +@main +struct MyLambda: LambdaHandler { typealias Event = Request typealias Output = Response - func handle(_ event: Request, context: Lambda.Context) -> EventLoopFuture { + init(context: Lambda.InitializationContext) async throws { + // setup your resources that you want to reuse for every invocation here. + } + + func handle(_ event: Request, context: Lambda.Context) async throws -> Response { // as an example, respond with the input event's reversed body - context.eventLoop.makeSucceededFuture(Response(body: String(event.body.reversed()))) + Response(body: String(event.body.reversed())) } } - -Lambda.run { $0.eventLoop.makeSucceededFuture(Handler()) } - -// MARK: - this can also be expressed as a closure: - -/* - Lambda.run { (_, request: Request, callback) in - callback(.success(Response(body: String(request.body.reversed())))) - } - */ diff --git a/Examples/Simple/Codable/Package.swift b/Examples/Simple/Codable/Package.swift new file mode 100644 index 00000000..0d8938f8 --- /dev/null +++ b/Examples/Simple/Codable/Package.swift @@ -0,0 +1,28 @@ +// swift-tools-version:5.5 + +import PackageDescription + +let package = Package( + name: "swift-aws-lambda-runtime-example", + platforms: [ + .macOS(.v12), + ], + products: [ + .executable(name: "MyLambda", targets: ["MyLambda"]), + ], + dependencies: [ + // this is the dependency on the swift-aws-lambda-runtime library + // in real-world projects this would say + // .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0") + .package(name: "swift-aws-lambda-runtime", path: "../../.."), + ], + targets: [ + .executableTarget( + name: "MyLambda", + dependencies: [ + .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), + ], + path: "." + ), + ] +) diff --git a/Sources/StringSample/main.swift b/Examples/Simple/String/Lambda.swift similarity index 63% rename from Sources/StringSample/main.swift rename to Examples/Simple/String/Lambda.swift index d80820f8..7fbdbe70 100644 --- a/Sources/StringSample/main.swift +++ b/Examples/Simple/String/Lambda.swift @@ -2,7 +2,7 @@ // // This source file is part of the SwiftAWSLambdaRuntime open source project // -// Copyright (c) 2017-2018 Apple Inc. and the SwiftAWSLambdaRuntime project authors +// Copyright (c) 2021 Apple Inc. and the SwiftAWSLambdaRuntime project authors // Licensed under Apache License v2.0 // // See LICENSE.txt for license information @@ -13,17 +13,20 @@ //===----------------------------------------------------------------------===// import AWSLambdaRuntimeCore -import NIOCore // in this example we are receiving and responding with strings -struct Handler: EventLoopLambdaHandler { + +@main +struct MyLambda: LambdaHandler { typealias Event = String typealias Output = String - func handle(_ event: String, context: Lambda.Context) -> EventLoopFuture { + init(context: Lambda.InitializationContext) async throws { + // setup your resources that you want to reuse for every invocation here. + } + + func handle(_ event: String, context: Lambda.Context) async throws -> String { // as an example, respond with the event's reversed body - context.eventLoop.makeSucceededFuture(String(event.reversed())) + String(event.reversed()) } } - -Lambda.run { $0.eventLoop.makeSucceededFuture(Handler()) } diff --git a/Examples/Simple/String/Package.swift b/Examples/Simple/String/Package.swift new file mode 100644 index 00000000..1f21c04c --- /dev/null +++ b/Examples/Simple/String/Package.swift @@ -0,0 +1,28 @@ +// swift-tools-version:5.5 + +import PackageDescription + +let package = Package( + name: "swift-aws-lambda-runtime-example", + platforms: [ + .macOS(.v12), + ], + products: [ + .executable(name: "MyLambda", targets: ["MyLambda"]), + ], + dependencies: [ + // this is the dependency on the swift-aws-lambda-runtime library + // in real-world projects this would say + // .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0") + .package(name: "swift-aws-lambda-runtime", path: "../../.."), + ], + targets: [ + .executableTarget( + name: "MyLambda", + dependencies: [ + .product(name: "AWSLambdaRuntimeCore", package: "swift-aws-lambda-runtime"), + ], + path: "." + ), + ] +) diff --git a/Examples/Simple/Testing/Package.swift b/Examples/Simple/Testing/Package.swift new file mode 100644 index 00000000..2df0bbff --- /dev/null +++ b/Examples/Simple/Testing/Package.swift @@ -0,0 +1,30 @@ +// swift-tools-version:5.5 + +import PackageDescription + +let package = Package( + name: "swift-aws-lambda-runtime-example", + platforms: [ + .macOS(.v12), + ], + products: [ + .executable(name: "MyLambda", targets: ["MyLambda"]), + ], + dependencies: [ + // this is the dependency on the swift-aws-lambda-runtime library + // in real-world projects this would say + // .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0") + .package(name: "swift-aws-lambda-runtime", path: "../../.."), + ], + targets: [ + .executableTarget( + name: "MyLambda", + dependencies: [ + .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), + .product(name: "AWSLambdaTesting", package: "swift-aws-lambda-runtime"), + ], + path: "Sources" + ), + .testTarget(name: "MyLambdaTests", dependencies: ["MyLambda"], path: "Tests"), + ] +) diff --git a/Examples/Simple/Testing/Sources/Lambda.swift b/Examples/Simple/Testing/Sources/Lambda.swift new file mode 100644 index 00000000..20d62aac --- /dev/null +++ b/Examples/Simple/Testing/Sources/Lambda.swift @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the SwiftAWSLambdaRuntime open source project +// +// Copyright (c) 2021 Apple Inc. and the SwiftAWSLambdaRuntime project authors +// Licensed under Apache License v2.0 +// +// See LICENSE.txt for license information +// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors +// +// SPDX-License-Identifier: Apache-2.0 +// +//===----------------------------------------------------------------------===// + +import AWSLambdaRuntime + +// in this example we are receiving and responding with strings + +@main +struct MyLambda: LambdaHandler { + typealias Event = String + typealias Output = String + + init(context: Lambda.InitializationContext) async throws { + // setup your resources that you want to reuse for every invocation here. + } + + func handle(_ event: String, context: Lambda.Context) async throws -> String { + // as an example, respond with the event's reversed body + String(event.reversed()) + } +} diff --git a/Examples/LambdaFunctions/Tests/LinuxMain.swift b/Examples/Simple/Testing/Tests/LambdaTests.swift similarity index 55% rename from Examples/LambdaFunctions/Tests/LinuxMain.swift rename to Examples/Simple/Testing/Tests/LambdaTests.swift index c46de763..26d6ea38 100644 --- a/Examples/LambdaFunctions/Tests/LinuxMain.swift +++ b/Examples/Simple/Testing/Tests/LambdaTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the SwiftAWSLambdaRuntime open source project // -// Copyright (c) 2020 Apple Inc. and the SwiftAWSLambdaRuntime project authors +// Copyright (c) 2021 Apple Inc. and the SwiftAWSLambdaRuntime project authors // Licensed under Apache License v2.0 // // See LICENSE.txt for license information @@ -12,4 +12,15 @@ // //===----------------------------------------------------------------------===// -preconditionFailure("use `swift test --enable-test-discovery`") +import AWSLambdaRuntime +import AWSLambdaTesting +@testable import MyLambda +import XCTest + +class LambdaTest: XCTestCase { + func testIt() throws { + let input = UUID().uuidString + let result = try Lambda.test(MyLambda.self, with: input) + XCTAssertEqual(result, String(input.reversed())) + } +} diff --git a/Package.swift b/Package.swift index e128dd3e..a6759014 100644 --- a/Package.swift +++ b/Package.swift @@ -52,7 +52,5 @@ let package = Package( .product(name: "NIOHTTP1", package: "swift-nio"), .product(name: "NIO", package: "swift-nio"), ]), - .target(name: "StringSample", dependencies: ["AWSLambdaRuntime"]), - .target(name: "CodableSample", dependencies: ["AWSLambdaRuntime"]), ] ) diff --git a/Sources/AWSLambdaTesting/Lambda+Testing.swift b/Sources/AWSLambdaTesting/Lambda+Testing.swift index 8f61419f..f2f712ac 100644 --- a/Sources/AWSLambdaTesting/Lambda+Testing.swift +++ b/Sources/AWSLambdaTesting/Lambda+Testing.swift @@ -13,18 +13,16 @@ //===----------------------------------------------------------------------===// // This functionality is designed to help with Lambda unit testing with XCTest -// #if filter required for release builds which do not support @testable import -// @testable is used to access of internal functions -// For exmaple: +// For example: // // func test() { // struct MyLambda: LambdaHandler { -// typealias In = String -// typealias Out = String +// typealias Event = String +// typealias Output = String // // init(context: Lambda.InitializationContext) {} // -// func handle(event: String, context: Lambda.Context) async throws -> String { +// func handle(_ event: String, context: Lambda.Context) async throws -> String { // "echo" + event // } // } diff --git a/Tests/AWSLambdaRuntimeCoreTests/LambdaHandlers.swift b/Tests/AWSLambdaRuntimeCoreTests/LambdaHandlers.swift index 67c12ae0..e2ba66f2 100644 --- a/Tests/AWSLambdaRuntimeCoreTests/LambdaHandlers.swift +++ b/Tests/AWSLambdaRuntimeCoreTests/LambdaHandlers.swift @@ -16,8 +16,8 @@ import AWSLambdaRuntimeCore import NIOCore struct EchoHandler: EventLoopLambdaHandler { - typealias In = String - typealias Out = String + typealias Event = String + typealias Output = String func handle(_ event: String, context: Lambda.Context) -> EventLoopFuture { context.eventLoop.makeSucceededFuture(event) @@ -25,8 +25,8 @@ struct EchoHandler: EventLoopLambdaHandler { } struct FailedHandler: EventLoopLambdaHandler { - typealias In = String - typealias Out = Void + typealias Event = String + typealias Output = Void private let reason: String diff --git a/Tests/AWSLambdaRuntimeTests/Lambda+CodeableTest.swift b/Tests/AWSLambdaRuntimeTests/Lambda+CodeableTest.swift index 770f1efb..6471ca1b 100644 --- a/Tests/AWSLambdaRuntimeTests/Lambda+CodeableTest.swift +++ b/Tests/AWSLambdaRuntimeTests/Lambda+CodeableTest.swift @@ -145,7 +145,7 @@ class CodableLambdaTest: XCTestCase { } #endif - // convencience method + // convenience method func newContext() -> Lambda.Context { Lambda.Context(requestID: UUID().uuidString, traceID: "abc123", diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift deleted file mode 100644 index 58f2ccfd..00000000 --- a/Tests/LinuxMain.swift +++ /dev/null @@ -1,15 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the SwiftAWSLambdaRuntime open source project -// -// Copyright (c) 2017-2020 Apple Inc. and the SwiftAWSLambdaRuntime project authors -// Licensed under Apache License v2.0 -// -// See LICENSE.txt for license information -// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors -// -// SPDX-License-Identifier: Apache-2.0 -// -//===----------------------------------------------------------------------===// - -preconditionFailure("use `swift test --enable-test-discovery`") diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 122ccd9d..50bba444 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -34,8 +34,12 @@ services: <<: *common command: >- /bin/bash -clx " + swift build --package-path Examples/Simple/String && + swift build --package-path Examples/Simple/Codable && + swift test --package-path Examples/Simple/Testing && swift build --package-path Examples/LambdaFunctions && - swift build --package-path Examples/LocalDebugging/MyLambda" + swift build --package-path Examples/LocalDebugging/MyLambda + " # util diff --git a/scripts/soundness.sh b/scripts/soundness.sh index 71d43e44..4fb39549 100755 --- a/scripts/soundness.sh +++ b/scripts/soundness.sh @@ -19,7 +19,7 @@ here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" function replace_acceptable_years() { # this needs to replace all acceptable forms with 'YEARS' - sed -e 's/2017-2018/YEARS/' -e 's/2017-2020/YEARS/' -e 's/2017-2021/YEARS/' -e 's/2019/YEARS/' -e 's/2020/YEARS/' + sed -e 's/2017-2018/YEARS/' -e 's/2017-2020/YEARS/' -e 's/2017-2021/YEARS/' -e 's/2019/YEARS/' -e 's/2020/YEARS/' -e 's/2021/YEARS/' } printf "=> Checking for unacceptable language... " From bd394611a4342b21df7333ae2db6d00f7ec82324 Mon Sep 17 00:00:00 2001 From: tom doron Date: Thu, 23 Sep 2021 21:37:00 -0700 Subject: [PATCH 2/2] flatten examples --- .../String => Benchmark}/Package.swift | 2 +- Examples/Benchmark/main.swift | 32 +++++++++++++++++++ .../.dockerignore | 0 Examples/Deployment/Dockerfile | 3 ++ .../Package.swift | 9 ------ .../{LambdaFunctions => Deployment}/README.md | 12 +++---- .../Sources/Benchmark/main.swift | 0 .../HelloWorld/HelloWorldHandler.swift | 0 .../scripts/SAM/APIGateway-template.yml | 0 .../scripts/SAM/Benchmark-template.yml | 0 .../scripts/SAM/HelloWorld-template.yml | 0 .../scripts/build-and-package.sh | 4 +-- .../scripts/config.sh | 0 .../scripts/deploy.sh | 0 .../scripts/package.sh | 0 .../scripts/sam-deploy.sh | 0 .../scripts/serverless-deploy.sh | 0 .../scripts/serverless-remove.sh | 0 .../serverless/APIGateway-template.yml | 0 .../scripts/serverless/Benchmark-template.yml | 0 .../serverless/HelloWorld-template.yml | 0 Examples/{Simple/String => Echo}/Lambda.swift | 8 ++--- .../{Simple/Codable => Echo}/Package.swift | 2 +- .../Lambda.swift} | 2 +- Examples/ErrorHandling/Package.swift | 28 ++++++++++++++++ .../Lambda.swift} | 2 +- Examples/Foundation/Package.swift | 28 ++++++++++++++++ .../{Simple/Codable => JSON}/Lambda.swift | 1 - Examples/JSON/Package.swift | 28 ++++++++++++++++ Examples/LambdaFunctions/Dockerfile | 3 -- .../scripts/SAM/CurrencyExchange-template.yml | 15 --------- .../scripts/SAM/ErrorHandling-template.yml | 14 -------- .../serverless/CurrencyExchange-template.yml | 20 ------------ .../serverless/ErrorHandling-template.yml | 20 ------------ Examples/{Simple => }/Testing/Package.swift | 2 +- .../{Simple => }/Testing/Sources/Lambda.swift | 0 .../Testing/Tests/LambdaTests.swift | 0 docker/docker-compose.al2.main.yaml | 5 --- docker/docker-compose.yaml | 15 +++++---- 39 files changed, 145 insertions(+), 110 deletions(-) rename Examples/{Simple/String => Benchmark}/Package.swift (91%) create mode 100644 Examples/Benchmark/main.swift rename Examples/{LambdaFunctions => Deployment}/.dockerignore (100%) create mode 100644 Examples/Deployment/Dockerfile rename Examples/{LambdaFunctions => Deployment}/Package.swift (66%) rename Examples/{LambdaFunctions => Deployment}/README.md (96%) rename Examples/{LambdaFunctions => Deployment}/Sources/Benchmark/main.swift (100%) rename Examples/{LambdaFunctions => Deployment}/Sources/HelloWorld/HelloWorldHandler.swift (100%) rename Examples/{LambdaFunctions => Deployment}/scripts/SAM/APIGateway-template.yml (100%) rename Examples/{LambdaFunctions => Deployment}/scripts/SAM/Benchmark-template.yml (100%) rename Examples/{LambdaFunctions => Deployment}/scripts/SAM/HelloWorld-template.yml (100%) rename Examples/{LambdaFunctions => Deployment}/scripts/build-and-package.sh (96%) rename Examples/{LambdaFunctions => Deployment}/scripts/config.sh (100%) rename Examples/{LambdaFunctions => Deployment}/scripts/deploy.sh (100%) rename Examples/{LambdaFunctions => Deployment}/scripts/package.sh (100%) rename Examples/{LambdaFunctions => Deployment}/scripts/sam-deploy.sh (100%) rename Examples/{LambdaFunctions => Deployment}/scripts/serverless-deploy.sh (100%) rename Examples/{LambdaFunctions => Deployment}/scripts/serverless-remove.sh (100%) rename Examples/{LambdaFunctions => Deployment}/scripts/serverless/APIGateway-template.yml (100%) rename Examples/{LambdaFunctions => Deployment}/scripts/serverless/Benchmark-template.yml (100%) rename Examples/{LambdaFunctions => Deployment}/scripts/serverless/HelloWorld-template.yml (100%) rename Examples/{Simple/String => Echo}/Lambda.swift (82%) rename Examples/{Simple/Codable => Echo}/Package.swift (91%) rename Examples/{LambdaFunctions/Sources/ErrorHandling/ErrorsHappenHandler.swift => ErrorHandling/Lambda.swift} (98%) create mode 100644 Examples/ErrorHandling/Package.swift rename Examples/{LambdaFunctions/Sources/CurrencyExchange/CurrencyExchangeHandler.swift => Foundation/Lambda.swift} (99%) create mode 100644 Examples/Foundation/Package.swift rename Examples/{Simple/Codable => JSON}/Lambda.swift (98%) create mode 100644 Examples/JSON/Package.swift delete mode 100644 Examples/LambdaFunctions/Dockerfile delete mode 100644 Examples/LambdaFunctions/scripts/SAM/CurrencyExchange-template.yml delete mode 100644 Examples/LambdaFunctions/scripts/SAM/ErrorHandling-template.yml delete mode 100644 Examples/LambdaFunctions/scripts/serverless/CurrencyExchange-template.yml delete mode 100644 Examples/LambdaFunctions/scripts/serverless/ErrorHandling-template.yml rename Examples/{Simple => }/Testing/Package.swift (93%) rename Examples/{Simple => }/Testing/Sources/Lambda.swift (100%) rename Examples/{Simple => }/Testing/Tests/LambdaTests.swift (100%) diff --git a/Examples/Simple/String/Package.swift b/Examples/Benchmark/Package.swift similarity index 91% rename from Examples/Simple/String/Package.swift rename to Examples/Benchmark/Package.swift index 1f21c04c..ddadbae8 100644 --- a/Examples/Simple/String/Package.swift +++ b/Examples/Benchmark/Package.swift @@ -14,7 +14,7 @@ let package = Package( // this is the dependency on the swift-aws-lambda-runtime library // in real-world projects this would say // .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0") - .package(name: "swift-aws-lambda-runtime", path: "../../.."), + .package(name: "swift-aws-lambda-runtime", path: "../.."), ], targets: [ .executableTarget( diff --git a/Examples/Benchmark/main.swift b/Examples/Benchmark/main.swift new file mode 100644 index 00000000..421d0cdc --- /dev/null +++ b/Examples/Benchmark/main.swift @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the SwiftAWSLambdaRuntime open source project +// +// Copyright (c) 2020 Apple Inc. and the SwiftAWSLambdaRuntime project authors +// Licensed under Apache License v2.0 +// +// See LICENSE.txt for license information +// See CONTRIBUTORS.txt for the list of SwiftAWSLambdaRuntime project authors +// +// SPDX-License-Identifier: Apache-2.0 +// +//===----------------------------------------------------------------------===// + +import AWSLambdaRuntimeCore +import NIOCore + +// If you would like to benchmark Swift's Lambda Runtime, +// use this example which is more performant. +// `EventLoopLambdaHandler` does not offload the Lambda processing to a separate thread +// while the closure-based handlers do. + +struct MyLambda: EventLoopLambdaHandler { + typealias Event = String + typealias Output = String + + func handle(_ event: String, context: Lambda.Context) -> EventLoopFuture { + context.eventLoop.makeSucceededFuture("hello, world!") + } +} + +Lambda.run { $0.eventLoop.makeSucceededFuture(MyLambda()) } diff --git a/Examples/LambdaFunctions/.dockerignore b/Examples/Deployment/.dockerignore similarity index 100% rename from Examples/LambdaFunctions/.dockerignore rename to Examples/Deployment/.dockerignore diff --git a/Examples/Deployment/Dockerfile b/Examples/Deployment/Dockerfile new file mode 100644 index 00000000..32962859 --- /dev/null +++ b/Examples/Deployment/Dockerfile @@ -0,0 +1,3 @@ +FROM swift:5.5-amazonlinux2 + +RUN yum -y install zip diff --git a/Examples/LambdaFunctions/Package.swift b/Examples/Deployment/Package.swift similarity index 66% rename from Examples/LambdaFunctions/Package.swift rename to Examples/Deployment/Package.swift index 52a21b98..a34069b9 100644 --- a/Examples/LambdaFunctions/Package.swift +++ b/Examples/Deployment/Package.swift @@ -13,9 +13,6 @@ let package = Package( // good for benchmarking .executable(name: "Benchmark", targets: ["Benchmark"]), // demonstrate different types of error handling - .executable(name: "ErrorHandling", targets: ["ErrorHandling"]), - // fully featured example with domain specific business logic - .executable(name: "CurrencyExchange", targets: ["CurrencyExchange"]), ], dependencies: [ // this is the dependency on the swift-aws-lambda-runtime library @@ -30,11 +27,5 @@ let package = Package( .executableTarget(name: "HelloWorld", dependencies: [ .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), ]), - .executableTarget(name: "ErrorHandling", dependencies: [ - .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), - ]), - .executableTarget(name: "CurrencyExchange", dependencies: [ - .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), - ]), ] ) diff --git a/Examples/LambdaFunctions/README.md b/Examples/Deployment/README.md similarity index 96% rename from Examples/LambdaFunctions/README.md rename to Examples/Deployment/README.md index 3c46a092..6066383d 100644 --- a/Examples/LambdaFunctions/README.md +++ b/Examples/Deployment/README.md @@ -1,14 +1,14 @@ -# Lambda Functions Examples +# Deployment Examples This sample project is a collection of Lambda functions that demonstrates how to write a simple Lambda function in Swift, and how to package and deploy it to the AWS Lambda platform. -The scripts are prepared to work from the `LambdaFunctions` folder. +The scripts are prepared to work from the `Deployment` folder. ``` git clone https://github.com/swift-server/swift-aws-lambda-runtime.git -cd swift-aws-lambda-runtime/Examples/LambdaFunctions +cd swift-aws-lambda-runtime/Examples/Deployment ``` 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: ./scripts/deploy.sh ``` - Notes: + Notes: - This script assumes you have AWS CLI installed and credentials setup in `~/.aws/credentials`. - The default lambda function name is `SwiftSample`. You can specify a different one updating `lambda_name` in `deploy.sh` - 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 For the APIGateway sample: -The Serverless template will provide an endpoint which you can use to test the Lambda. +The Serverless template will provide an endpoint which you can use to test the Lambda. Outuput example: @@ -174,4 +174,4 @@ For all other samples use the AWS Lambda console. ./scripts/serverless-remove.sh ``` -The script will ask you which sample Lambda you wish to remove from the previous depolyment. \ No newline at end of file +The script will ask you which sample Lambda you wish to remove from the previous deployment. diff --git a/Examples/LambdaFunctions/Sources/Benchmark/main.swift b/Examples/Deployment/Sources/Benchmark/main.swift similarity index 100% rename from Examples/LambdaFunctions/Sources/Benchmark/main.swift rename to Examples/Deployment/Sources/Benchmark/main.swift diff --git a/Examples/LambdaFunctions/Sources/HelloWorld/HelloWorldHandler.swift b/Examples/Deployment/Sources/HelloWorld/HelloWorldHandler.swift similarity index 100% rename from Examples/LambdaFunctions/Sources/HelloWorld/HelloWorldHandler.swift rename to Examples/Deployment/Sources/HelloWorld/HelloWorldHandler.swift diff --git a/Examples/LambdaFunctions/scripts/SAM/APIGateway-template.yml b/Examples/Deployment/scripts/SAM/APIGateway-template.yml similarity index 100% rename from Examples/LambdaFunctions/scripts/SAM/APIGateway-template.yml rename to Examples/Deployment/scripts/SAM/APIGateway-template.yml diff --git a/Examples/LambdaFunctions/scripts/SAM/Benchmark-template.yml b/Examples/Deployment/scripts/SAM/Benchmark-template.yml similarity index 100% rename from Examples/LambdaFunctions/scripts/SAM/Benchmark-template.yml rename to Examples/Deployment/scripts/SAM/Benchmark-template.yml diff --git a/Examples/LambdaFunctions/scripts/SAM/HelloWorld-template.yml b/Examples/Deployment/scripts/SAM/HelloWorld-template.yml similarity index 100% rename from Examples/LambdaFunctions/scripts/SAM/HelloWorld-template.yml rename to Examples/Deployment/scripts/SAM/HelloWorld-template.yml diff --git a/Examples/LambdaFunctions/scripts/build-and-package.sh b/Examples/Deployment/scripts/build-and-package.sh similarity index 96% rename from Examples/LambdaFunctions/scripts/build-and-package.sh rename to Examples/Deployment/scripts/build-and-package.sh index 4e45c486..f1e0a922 100755 --- a/Examples/LambdaFunctions/scripts/build-and-package.sh +++ b/Examples/Deployment/scripts/build-and-package.sh @@ -27,13 +27,13 @@ echo "done" echo "-------------------------------------------------------------------------" echo "building \"$executable\" lambda" echo "-------------------------------------------------------------------------" -docker run --rm -v "$workspace":/workspace -w /workspace/Examples/LambdaFunctions builder \ +docker run --rm -v "$workspace":/workspace -w /workspace/Examples/Deployment builder \ bash -cl "swift build --product $executable -c release" echo "done" echo "-------------------------------------------------------------------------" echo "packaging \"$executable\" lambda" echo "-------------------------------------------------------------------------" -docker run --rm -v "$workspace":/workspace -w /workspace/Examples/LambdaFunctions builder \ +docker run --rm -v "$workspace":/workspace -w /workspace/Examples/Deployment builder \ bash -cl "./scripts/package.sh $executable" echo "done" diff --git a/Examples/LambdaFunctions/scripts/config.sh b/Examples/Deployment/scripts/config.sh similarity index 100% rename from Examples/LambdaFunctions/scripts/config.sh rename to Examples/Deployment/scripts/config.sh diff --git a/Examples/LambdaFunctions/scripts/deploy.sh b/Examples/Deployment/scripts/deploy.sh similarity index 100% rename from Examples/LambdaFunctions/scripts/deploy.sh rename to Examples/Deployment/scripts/deploy.sh diff --git a/Examples/LambdaFunctions/scripts/package.sh b/Examples/Deployment/scripts/package.sh similarity index 100% rename from Examples/LambdaFunctions/scripts/package.sh rename to Examples/Deployment/scripts/package.sh diff --git a/Examples/LambdaFunctions/scripts/sam-deploy.sh b/Examples/Deployment/scripts/sam-deploy.sh similarity index 100% rename from Examples/LambdaFunctions/scripts/sam-deploy.sh rename to Examples/Deployment/scripts/sam-deploy.sh diff --git a/Examples/LambdaFunctions/scripts/serverless-deploy.sh b/Examples/Deployment/scripts/serverless-deploy.sh similarity index 100% rename from Examples/LambdaFunctions/scripts/serverless-deploy.sh rename to Examples/Deployment/scripts/serverless-deploy.sh diff --git a/Examples/LambdaFunctions/scripts/serverless-remove.sh b/Examples/Deployment/scripts/serverless-remove.sh similarity index 100% rename from Examples/LambdaFunctions/scripts/serverless-remove.sh rename to Examples/Deployment/scripts/serverless-remove.sh diff --git a/Examples/LambdaFunctions/scripts/serverless/APIGateway-template.yml b/Examples/Deployment/scripts/serverless/APIGateway-template.yml similarity index 100% rename from Examples/LambdaFunctions/scripts/serverless/APIGateway-template.yml rename to Examples/Deployment/scripts/serverless/APIGateway-template.yml diff --git a/Examples/LambdaFunctions/scripts/serverless/Benchmark-template.yml b/Examples/Deployment/scripts/serverless/Benchmark-template.yml similarity index 100% rename from Examples/LambdaFunctions/scripts/serverless/Benchmark-template.yml rename to Examples/Deployment/scripts/serverless/Benchmark-template.yml diff --git a/Examples/LambdaFunctions/scripts/serverless/HelloWorld-template.yml b/Examples/Deployment/scripts/serverless/HelloWorld-template.yml similarity index 100% rename from Examples/LambdaFunctions/scripts/serverless/HelloWorld-template.yml rename to Examples/Deployment/scripts/serverless/HelloWorld-template.yml diff --git a/Examples/Simple/String/Lambda.swift b/Examples/Echo/Lambda.swift similarity index 82% rename from Examples/Simple/String/Lambda.swift rename to Examples/Echo/Lambda.swift index 7fbdbe70..684ed45d 100644 --- a/Examples/Simple/String/Lambda.swift +++ b/Examples/Echo/Lambda.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// -import AWSLambdaRuntimeCore +import AWSLambdaRuntime // in this example we are receiving and responding with strings @@ -25,8 +25,8 @@ struct MyLambda: LambdaHandler { // setup your resources that you want to reuse for every invocation here. } - func handle(_ event: String, context: Lambda.Context) async throws -> String { - // as an example, respond with the event's reversed body - String(event.reversed()) + func handle(_ input: String, context: Lambda.Context) async throws -> String { + // as an example, respond with the input's reversed + String(input.reversed()) } } diff --git a/Examples/Simple/Codable/Package.swift b/Examples/Echo/Package.swift similarity index 91% rename from Examples/Simple/Codable/Package.swift rename to Examples/Echo/Package.swift index 0d8938f8..caae8f03 100644 --- a/Examples/Simple/Codable/Package.swift +++ b/Examples/Echo/Package.swift @@ -14,7 +14,7 @@ let package = Package( // this is the dependency on the swift-aws-lambda-runtime library // in real-world projects this would say // .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0") - .package(name: "swift-aws-lambda-runtime", path: "../../.."), + .package(name: "swift-aws-lambda-runtime", path: "../.."), ], targets: [ .executableTarget( diff --git a/Examples/LambdaFunctions/Sources/ErrorHandling/ErrorsHappenHandler.swift b/Examples/ErrorHandling/Lambda.swift similarity index 98% rename from Examples/LambdaFunctions/Sources/ErrorHandling/ErrorsHappenHandler.swift rename to Examples/ErrorHandling/Lambda.swift index f7d47dd6..e9b30e9f 100644 --- a/Examples/LambdaFunctions/Sources/ErrorHandling/ErrorsHappenHandler.swift +++ b/Examples/ErrorHandling/Lambda.swift @@ -17,7 +17,7 @@ import AWSLambdaRuntime // MARK: - Run Lambda @main -struct ErrorsHappenHandler: LambdaHandler { +struct MyLambda: LambdaHandler { typealias Event = Request typealias Output = Response diff --git a/Examples/ErrorHandling/Package.swift b/Examples/ErrorHandling/Package.swift new file mode 100644 index 00000000..caae8f03 --- /dev/null +++ b/Examples/ErrorHandling/Package.swift @@ -0,0 +1,28 @@ +// swift-tools-version:5.5 + +import PackageDescription + +let package = Package( + name: "swift-aws-lambda-runtime-example", + platforms: [ + .macOS(.v12), + ], + products: [ + .executable(name: "MyLambda", targets: ["MyLambda"]), + ], + dependencies: [ + // this is the dependency on the swift-aws-lambda-runtime library + // in real-world projects this would say + // .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0") + .package(name: "swift-aws-lambda-runtime", path: "../.."), + ], + targets: [ + .executableTarget( + name: "MyLambda", + dependencies: [ + .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), + ], + path: "." + ), + ] +) diff --git a/Examples/LambdaFunctions/Sources/CurrencyExchange/CurrencyExchangeHandler.swift b/Examples/Foundation/Lambda.swift similarity index 99% rename from Examples/LambdaFunctions/Sources/CurrencyExchange/CurrencyExchangeHandler.swift rename to Examples/Foundation/Lambda.swift index 1db53573..0921ac88 100644 --- a/Examples/LambdaFunctions/Sources/CurrencyExchange/CurrencyExchangeHandler.swift +++ b/Examples/Foundation/Lambda.swift @@ -24,7 +24,7 @@ import Logging // MARK: - Run Lambda @main -struct CurrencyExchangeHandler: LambdaHandler { +struct MyLambda: LambdaHandler { typealias Event = Request typealias Output = [Exchange] diff --git a/Examples/Foundation/Package.swift b/Examples/Foundation/Package.swift new file mode 100644 index 00000000..caae8f03 --- /dev/null +++ b/Examples/Foundation/Package.swift @@ -0,0 +1,28 @@ +// swift-tools-version:5.5 + +import PackageDescription + +let package = Package( + name: "swift-aws-lambda-runtime-example", + platforms: [ + .macOS(.v12), + ], + products: [ + .executable(name: "MyLambda", targets: ["MyLambda"]), + ], + dependencies: [ + // this is the dependency on the swift-aws-lambda-runtime library + // in real-world projects this would say + // .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0") + .package(name: "swift-aws-lambda-runtime", path: "../.."), + ], + targets: [ + .executableTarget( + name: "MyLambda", + dependencies: [ + .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), + ], + path: "." + ), + ] +) diff --git a/Examples/Simple/Codable/Lambda.swift b/Examples/JSON/Lambda.swift similarity index 98% rename from Examples/Simple/Codable/Lambda.swift rename to Examples/JSON/Lambda.swift index b4fb90ec..d009861d 100644 --- a/Examples/Simple/Codable/Lambda.swift +++ b/Examples/JSON/Lambda.swift @@ -13,7 +13,6 @@ //===----------------------------------------------------------------------===// import AWSLambdaRuntime -import NIOCore struct Request: Codable { let body: String diff --git a/Examples/JSON/Package.swift b/Examples/JSON/Package.swift new file mode 100644 index 00000000..caae8f03 --- /dev/null +++ b/Examples/JSON/Package.swift @@ -0,0 +1,28 @@ +// swift-tools-version:5.5 + +import PackageDescription + +let package = Package( + name: "swift-aws-lambda-runtime-example", + platforms: [ + .macOS(.v12), + ], + products: [ + .executable(name: "MyLambda", targets: ["MyLambda"]), + ], + dependencies: [ + // this is the dependency on the swift-aws-lambda-runtime library + // in real-world projects this would say + // .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0") + .package(name: "swift-aws-lambda-runtime", path: "../.."), + ], + targets: [ + .executableTarget( + name: "MyLambda", + dependencies: [ + .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), + ], + path: "." + ), + ] +) diff --git a/Examples/LambdaFunctions/Dockerfile b/Examples/LambdaFunctions/Dockerfile deleted file mode 100644 index d5315703..00000000 --- a/Examples/LambdaFunctions/Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM swift:5.2-amazonlinux2 - -RUN yum -y install zip diff --git a/Examples/LambdaFunctions/scripts/SAM/CurrencyExchange-template.yml b/Examples/LambdaFunctions/scripts/SAM/CurrencyExchange-template.yml deleted file mode 100644 index b7b4f250..00000000 --- a/Examples/LambdaFunctions/scripts/SAM/CurrencyExchange-template.yml +++ /dev/null @@ -1,15 +0,0 @@ -AWSTemplateFormatVersion : '2010-09-09' -Transform: AWS::Serverless-2016-10-31 -Description: A sample SAM template for deploying Lambda functions. - -Resources: -# CurrencyExchange Function - currencyExchangeFunction: - Type: AWS::Serverless::Function - Properties: - Handler: Provided - Runtime: provided - CodeUri: ../../.build/lambda/CurrencyExchange/lambda.zip - Timeout: 300 -# Instructs new versions to be published to an alias named "live". - AutoPublishAlias: live diff --git a/Examples/LambdaFunctions/scripts/SAM/ErrorHandling-template.yml b/Examples/LambdaFunctions/scripts/SAM/ErrorHandling-template.yml deleted file mode 100644 index c277ec72..00000000 --- a/Examples/LambdaFunctions/scripts/SAM/ErrorHandling-template.yml +++ /dev/null @@ -1,14 +0,0 @@ -AWSTemplateFormatVersion : '2010-09-09' -Transform: AWS::Serverless-2016-10-31 -Description: A sample SAM template for deploying Lambda functions. - -Resources: -# ErrorHandling Function - errorHandlingFunction: - Type: AWS::Serverless::Function - Properties: - Handler: Provided - Runtime: provided - CodeUri: ../../.build/lambda/ErrorHandling/lambda.zip -# Instructs new versions to be published to an alias named "live". - AutoPublishAlias: live diff --git a/Examples/LambdaFunctions/scripts/serverless/CurrencyExchange-template.yml b/Examples/LambdaFunctions/scripts/serverless/CurrencyExchange-template.yml deleted file mode 100644 index 7e5c6b09..00000000 --- a/Examples/LambdaFunctions/scripts/serverless/CurrencyExchange-template.yml +++ /dev/null @@ -1,20 +0,0 @@ -service: currency-swift-aws - -package: - artifact: .build/lambda/CurrencyExchange/lambda.zip - -provider: - name: aws - runtime: provided - iamRoleStatements: - - Effect: Allow - Action: - - logs:CreateLogGroup - - logs:CreateLogStream - - logs:PutLogEvents - Resource: "*" - -functions: - currencyExchangeFunction: - handler: CurrencyExchange - memorySize: 128 \ No newline at end of file diff --git a/Examples/LambdaFunctions/scripts/serverless/ErrorHandling-template.yml b/Examples/LambdaFunctions/scripts/serverless/ErrorHandling-template.yml deleted file mode 100644 index 367be490..00000000 --- a/Examples/LambdaFunctions/scripts/serverless/ErrorHandling-template.yml +++ /dev/null @@ -1,20 +0,0 @@ -service: errorhandling-swift-aws - -package: - artifact: .build/lambda/ErrorHandling/lambda.zip - -provider: - name: aws - runtime: provided - iamRoleStatements: - - Effect: Allow - Action: - - logs:CreateLogGroup - - logs:CreateLogStream - - logs:PutLogEvents - Resource: "*" - -functions: - errorHandlingFunction: - handler: ErrorHandling - memorySize: 128 \ No newline at end of file diff --git a/Examples/Simple/Testing/Package.swift b/Examples/Testing/Package.swift similarity index 93% rename from Examples/Simple/Testing/Package.swift rename to Examples/Testing/Package.swift index 2df0bbff..5f7cb131 100644 --- a/Examples/Simple/Testing/Package.swift +++ b/Examples/Testing/Package.swift @@ -14,7 +14,7 @@ let package = Package( // this is the dependency on the swift-aws-lambda-runtime library // in real-world projects this would say // .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0") - .package(name: "swift-aws-lambda-runtime", path: "../../.."), + .package(name: "swift-aws-lambda-runtime", path: "../.."), ], targets: [ .executableTarget( diff --git a/Examples/Simple/Testing/Sources/Lambda.swift b/Examples/Testing/Sources/Lambda.swift similarity index 100% rename from Examples/Simple/Testing/Sources/Lambda.swift rename to Examples/Testing/Sources/Lambda.swift diff --git a/Examples/Simple/Testing/Tests/LambdaTests.swift b/Examples/Testing/Tests/LambdaTests.swift similarity index 100% rename from Examples/Simple/Testing/Tests/LambdaTests.swift rename to Examples/Testing/Tests/LambdaTests.swift diff --git a/docker/docker-compose.al2.main.yaml b/docker/docker-compose.al2.main.yaml index 741c8a43..c63a13e2 100644 --- a/docker/docker-compose.al2.main.yaml +++ b/docker/docker-compose.al2.main.yaml @@ -10,14 +10,9 @@ services: test: image: swift-aws-lambda:al2-main - command: /bin/bash -cl "swift test --enable-test-discovery -Xswiftc -warnings-as-errors $${SANITIZER_ARG-} -Xswiftc -Xfrontend -Xswiftc -enable-experimental-concurrency" test-samples: image: swift-aws-lambda:al2-main - command: >- - /bin/bash -clx " - swift build -Xswiftc -Xfrontend -Xswiftc -enable-experimental-concurrency --package-path Examples/LambdaFunctions && - swift build -Xswiftc -Xfrontend -Xswiftc -enable-experimental-concurrency --package-path Examples/LocalDebugging/MyLambda" shell: image: swift-aws-lambda:al2-main diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 50bba444..48004fc6 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -1,6 +1,6 @@ # this file is not designed to be run directly # instead, use the docker-compose.. files -# eg docker-compose -f docker/docker-compose.yaml -f docker/docker-compose.al2.52.yaml run test +# eg docker-compose -f docker/docker-compose.yaml -f docker/docker-compose.al2.55.yaml run test version: "3" services: @@ -34,11 +34,14 @@ services: <<: *common command: >- /bin/bash -clx " - swift build --package-path Examples/Simple/String && - swift build --package-path Examples/Simple/Codable && - swift test --package-path Examples/Simple/Testing && - swift build --package-path Examples/LambdaFunctions && - swift build --package-path Examples/LocalDebugging/MyLambda + swift build --package-path Examples/Benchmark && + swift build --package-path Examples/Deployment && + swift build --package-path Examples/Echo && + swift build --package-path Examples/ErrorHandling && + swift build --package-path Examples/Foundation && + swift build --package-path Examples/JSON && + swift build --package-path Examples/LocalDebugging/MyLambda && + swift test --package-path Examples/Testing " # util