Update and add examples to new APIs (#228)

* take advantage of @main where possible
* move the top level Sample code to the examples subdirectory
* extract a few examples form the "LambdaFunctions" directory (which is really a deployment demo) and move them to the top level Examples directory
*  rename "LambdaFunctions" examples as "Deployments" to make their intent clearer
* 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
* remove LinuxMain since its no longer required
This commit is contained in:
tomer doron
2021-09-25 10:30:04 +02:00
committed by GitHub
parent 7c1dea035d
commit b757de0241
49 changed files with 310 additions and 188 deletions
+41
View File
@@ -0,0 +1,41 @@
//===----------------------------------------------------------------------===//
//
// 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
struct Request: Codable {
let body: String
}
struct Response: Codable {
let body: String
}
// in this example we are receiving and responding with codables. Request and Response above are examples of how to use
// codables to model your request and response objects
@main
struct MyLambda: LambdaHandler {
typealias Event = Request
typealias Output = Response
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
Response(body: String(event.body.reversed()))
}
}
+28
View File
@@ -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: "."
),
]
)