Skip to content

Commit

Permalink
Add sample script
Browse files Browse the repository at this point in the history
  • Loading branch information
giginet committed Dec 3, 2018
1 parent db33e06 commit e4004e6
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Example/.gitignore
@@ -0,0 +1,4 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
8 changes: 8 additions & 0 deletions Example/Package.resolved
@@ -0,0 +1,8 @@
{
"object": {
"pins": [

]
},
"version": 1
}
16 changes: 16 additions & 0 deletions Example/Package.swift
@@ -0,0 +1,16 @@
// swift-tools-version:4.2
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "Example",
dependencies: [
.package(path: "../"),
],
targets: [
.target(
name: "Example",
dependencies: ["AWSLambdaRuntime"]),
]
)
3 changes: 3 additions & 0 deletions Example/README.md
@@ -0,0 +1,3 @@
# Example

A description of this package.
26 changes: 26 additions & 0 deletions Example/Sources/Example/main.swift
@@ -0,0 +1,26 @@
import Foundation
import AWSLambdaRuntime

struct User: Decodable {
let firstName: String
}

enum GreetingError: String, LambdaError {
var message: String {
switch self {
case .invalidPayload:
return "Payload is invalid"
}
}

case invalidPayload
}

run { context -> Result<GreetingError> in
guard let data = context.payload,
let user = try? JSONDecoder().decode(User.self, from: data) else {
return .failure(error: .invalidPayload)
}
let payload = try! JSONSerialization.data(withJSONObject: ["message": "Hello \(user.firstName)"])
return .success(payload: payload, contentType: "application/json")
}

0 comments on commit e4004e6

Please sign in to comment.