Skip to content
Draft
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
8 changes: 8 additions & 0 deletions lambda/swift/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
276 changes: 276 additions & 0 deletions lambda/swift/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions lambda/swift/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// swift-tools-version: 6.0
import PackageDescription

let package = Package(
name: "SwiftExample",
platforms: [.macOS(.v15)],
dependencies: [
.package(url: "https://github.com/awslabs/aws-sdk-swift", from: "1.0.0"),
.package(url: "https://github.com/swift-server/swift-aws-lambda-events.git", from: "1.2.1"),
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", from: "2.0.0"),
.package(url: "https://github.com/swift-server/swift-service-lifecycle.git", from: "2.0.0"),
],
targets: [
.executableTarget(
name: "SwiftExample",
dependencies: [
.product(name: "AWSDynamoDB", package: "aws-sdk-swift"),
.product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"),
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
.product(name: "ServiceLifecycle", package: "swift-service-lifecycle"),
]
),
.testTarget(
name: "SwiftExampleTests",
dependencies: ["SwiftExample"],
resources: [.process("Resources")]
)
]
)
26 changes: 26 additions & 0 deletions lambda/swift/Sources/SwiftExample/Event.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import AWSDynamoDB

struct Event {
let id: String
let emitterCode: Int
let action: String
let user: User

func asItem() -> [String: DynamoDBClientTypes.AttributeValue] {
[
CodingKeys.id.rawValue: .s(id),
CodingKeys.emitterCode.rawValue: .n(String(emitterCode)),
CodingKeys.action.rawValue: .s(action),
CodingKeys.user.rawValue: .m(user.asItem())
]
}
}

extension Event: Codable {
enum CodingKeys: String, CodingKey {
case id = "eventId"
case emitterCode
case action
case user
}
}
25 changes: 25 additions & 0 deletions lambda/swift/Sources/SwiftExample/User.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import AWSDynamoDB

struct User {
let id: String
let sessionID: String
let deviceID: String

func asItem() -> [String: DynamoDBClientTypes.AttributeValue] {
[
CodingKeys.id.rawValue: .s(id),
CodingKeys.sessionID.rawValue: .s(sessionID),
CodingKeys.deviceID.rawValue: .s(deviceID),
]
}


}

extension User: Codable {
enum CodingKeys: String, CodingKey {
case id
case sessionID = "sessionId"
case deviceID = "deviceId"
}
}
Loading