Skip to content

add samples #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Examples/Simple/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.build
30 changes: 30 additions & 0 deletions Examples/Simple/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// swift-tools-version:5.2

import PackageDescription

let package = Package(
name: "swift-aws-lambda-events-samples",
platforms: [
.macOS(.v10_13),
],
products: [
// demonstrate how to integrate with AWS API Gateway
.executable(name: "APIGateway", targets: ["APIGateway"]),
],
dependencies: [
// this is the dependency on the swift-aws-lambda-runtime library
// in real-world projects this would say
// FIXME: update this once the https://github.com/swift-server/swift-aws-lambda-runtime/pull/216 is merged
// .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "1.0.0")
.package(url: "https://github.com/tomerd/swift-aws-lambda-runtime.git", .branch("remove-events")),
// this is the dependency on the swift-aws-lambda-events library
// .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime-events.git", from: "1.0.0")
.package(name: "swift-aws-lambda-events", path: "../.."),
],
targets: [
.target(name: "APIGateway", dependencies: [
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
.product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"),
]),
]
)
36 changes: 36 additions & 0 deletions Examples/Simple/Sources/APIGateway/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// 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 AWSLambdaEvents
import AWSLambdaRuntime
import NIO

// MARK: - Run Lambda

Lambda.run(APIGatewayProxyLambda())

// MARK: - Handler, Request and Response

// FIXME: Use proper Event abstractions once added to AWSLambdaRuntime
struct APIGatewayProxyLambda: EventLoopLambdaHandler {
public typealias In = APIGateway.V2.Request
public typealias Out = APIGateway.V2.Response

public func handle(context: Lambda.Context, event: APIGateway.V2.Request) -> EventLoopFuture<APIGateway.V2.Response> {
context.logger.debug("hello, api gateway!")
return context.eventLoop.makeSucceededFuture(
APIGateway.V2.Response(statusCode: .ok, body: "hello, world!")
)
}
}
15 changes: 15 additions & 0 deletions Examples/Simple/Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//===----------------------------------------------------------------------===//
//
// 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`")
3 changes: 3 additions & 0 deletions docker/docker-compose.1804.52.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ services:
test:
image: swift-aws-lambda-events:18.04-5.2

test-samples:
image: swift-aws-lambda-events:18.04-5.2

shell:
image: swift-aws-lambda-events:18.04-5.2
3 changes: 3 additions & 0 deletions docker/docker-compose.al2.52.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ services:
test:
image: swift-aws-lambda-events:al2-5.2

test-samples:
image: swift-aws-lambda-events:al2-5.2

shell:
image: swift-aws-lambda-events:al2-5.2
3 changes: 3 additions & 0 deletions docker/docker-compose.al2.53.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ services:
test:
image: swift-aws-lambda-events:al2-5.3

test-samples:
image: swift-aws-lambda-events:al2-5.3

shell:
image: swift-aws-lambda-events:al2-5.3
3 changes: 3 additions & 0 deletions docker/docker-compose.al2.54.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ services:
test:
image: swift-aws-lambda-events:al2-5.4

test-samples:
image: swift-aws-lambda-events:al2-5.4

shell:
image: swift-aws-lambda-events:al2-5.4
3 changes: 3 additions & 0 deletions docker/docker-compose.al2.55.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ services:
test:
image: swift-aws-lambda-events:al2-5.5

test-samples:
image: swift-aws-lambda-events:al2-5.5

shell:
image: swift-aws-lambda-events:al2-5.5
3 changes: 3 additions & 0 deletions docker/docker-compose.al2.main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ services:
test:
image: swift-aws-lambda-events:al2-main

test-samples:
image: swift-aws-lambda-events:al2-main

shell:
image: swift-aws-lambda-events:al2-main
7 changes: 7 additions & 0 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ services:
<<: *common
command: /bin/bash -cl "swift test --enable-test-discovery -Xswiftc -warnings-as-errors $${SANITIZER_ARG-}"

test-samples:
<<: *common
command: >-
/bin/bash -clx "
swift build --package-path Examples/Simple
"

# util

shell:
Expand Down