mirror of
https://github.com/swift-server/swift-aws-lambda-runtime.git
synced 2026-06-02 07:27:33 +00:00
Add `S3EventNotifier` example ### Motivation: There is currently no example regarding an AWS event triggered lambda, such as a lambda that gets invoked on an S3 object upload. I've had to look for a while to figure out that the `AWSLambdaEvents` exists and that it can be used for that (had to find out via a Java example! 😜) so I think this could be useful and a somewhat common use case ### Modifications: Added an example of a lambda that gets triggered when an object gets uploaded to an S3 bucket. I have not described how to set up the actual S3 event in AWS because I figured if you needed such a lambda you'd know, but I can describe that too in the README if needed --------- Co-authored-by: Sébastien Stormacq <sebastien.stormacq@gmail.com>
51 lines
1.7 KiB
Swift
51 lines
1.7 KiB
Swift
// swift-tools-version: 6.0
|
|
import PackageDescription
|
|
|
|
// needed for CI to test the local version of the library
|
|
import struct Foundation.URL
|
|
|
|
let package = Package(
|
|
name: "S3EventNotifier",
|
|
platforms: [.macOS(.v15)],
|
|
dependencies: [
|
|
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main"),
|
|
.package(url: "https://github.com/swift-server/swift-aws-lambda-events", branch: "main"),
|
|
],
|
|
targets: [
|
|
.executableTarget(
|
|
name: "S3EventNotifier",
|
|
dependencies: [
|
|
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
|
|
.product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"),
|
|
]
|
|
)
|
|
]
|
|
)
|
|
|
|
if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"],
|
|
localDepsPath != "",
|
|
let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]),
|
|
v.isDirectory == true
|
|
{
|
|
// when we use the local runtime as deps, let's remove the dependency added above
|
|
let indexToRemove = package.dependencies.firstIndex { dependency in
|
|
if case .sourceControl(
|
|
name: _,
|
|
location: "https://github.com/swift-server/swift-aws-lambda-runtime.git",
|
|
requirement: _
|
|
) = dependency.kind {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
if let indexToRemove {
|
|
package.dependencies.remove(at: indexToRemove)
|
|
}
|
|
|
|
// then we add the dependency on LAMBDA_USE_LOCAL_DEPS' path (typically ../..)
|
|
print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)")
|
|
package.dependencies += [
|
|
.package(name: "swift-aws-lambda-runtime", path: localDepsPath)
|
|
]
|
|
}
|