mirror of
https://github.com/swift-server/swift-aws-lambda-runtime.git
synced 2026-06-02 07:27:33 +00:00
Merge branch 'main' into sebsto/new-plugins
This commit is contained in:
@@ -5,12 +5,6 @@ import PackageDescription
|
||||
// needed for CI to test the local version of the library
|
||||
import struct Foundation.URL
|
||||
|
||||
#if os(macOS)
|
||||
let platforms: [PackageDescription.SupportedPlatform]? = [.macOS(.v15)]
|
||||
#else
|
||||
let platforms: [PackageDescription.SupportedPlatform]? = nil
|
||||
#endif
|
||||
|
||||
let package = Package(
|
||||
name: "swift-aws-lambda-runtime-example",
|
||||
platforms: [.macOS(.v15)],
|
||||
@@ -21,7 +15,7 @@ let package = Package(
|
||||
dependencies: [
|
||||
// during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below
|
||||
.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.git", branch: "main"),
|
||||
.package(url: "https://github.com/swift-server/swift-aws-lambda-events.git", from: "1.0.0"),
|
||||
],
|
||||
targets: [
|
||||
.executableTarget(
|
||||
|
||||
@@ -14,7 +14,7 @@ let package = Package(
|
||||
dependencies: [
|
||||
// during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below
|
||||
.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.git", branch: "main"),
|
||||
.package(url: "https://github.com/swift-server/swift-aws-lambda-events.git", from: "1.0.0"),
|
||||
],
|
||||
targets: [
|
||||
.executableTarget(
|
||||
|
||||
@@ -14,7 +14,7 @@ let package = Package(
|
||||
dependencies: [
|
||||
// during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below
|
||||
.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.git", branch: "main"),
|
||||
.package(url: "https://github.com/swift-server/swift-aws-lambda-events.git", from: "1.0.0"),
|
||||
],
|
||||
targets: [
|
||||
.executableTarget(
|
||||
|
||||
Generated
+11
-11
@@ -23,9 +23,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@aws-cdk/asset-awscli-v1": {
|
||||
"version": "2.2.215",
|
||||
"resolved": "https://registry.npmjs.org/@aws-cdk/asset-awscli-v1/-/asset-awscli-v1-2.2.215.tgz",
|
||||
"integrity": "sha512-D+Jzwpl+zlBGjJf7nuRcz6JFNwqDQ+IzwIq0VSC4LMRRvrkhGE/ZE+zab3EnjmVkipcQqtQe+PVKefgmxETbvA==",
|
||||
"version": "2.2.220",
|
||||
"resolved": "https://registry.npmjs.org/@aws-cdk/asset-awscli-v1/-/asset-awscli-v1-2.2.220.tgz",
|
||||
"integrity": "sha512-2eXZnnIgwWmXc7eRh8mRKPp6yHTKiQrLziRX/oVSfp4M6Jn2no0QFKJoHWqziF5MDQa5TF8qhD4FGsls/1nYPg==",
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"node_modules/@aws-cdk/asset-kubectl-v20": {
|
||||
@@ -41,16 +41,16 @@
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"node_modules/@aws-cdk/cloud-assembly-schema": {
|
||||
"version": "38.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@aws-cdk/cloud-assembly-schema/-/cloud-assembly-schema-38.0.1.tgz",
|
||||
"integrity": "sha512-KvPe+NMWAulfNVwY7jenFhzhuLhLqJ/OPy5jx7wUstbjnYnjRVLpUHPU3yCjXFE0J8cuJVdx95BJ4rOs66Pi9w==",
|
||||
"version": "39.2.1",
|
||||
"resolved": "https://registry.npmjs.org/@aws-cdk/cloud-assembly-schema/-/cloud-assembly-schema-39.2.1.tgz",
|
||||
"integrity": "sha512-cz18QG02p++ivQ5wdjLI8TyMk1p6kwQc1ExeL2A9RoUg1gCnwEBrkJMhiWgTroWBblT0GF0MqSvzkyeEdHqn2A==",
|
||||
"bundleDependencies": [
|
||||
"jsonschema",
|
||||
"semver"
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"jsonschema": "^1.4.1",
|
||||
"jsonschema": "~1.4.1",
|
||||
"semver": "^7.6.3"
|
||||
}
|
||||
},
|
||||
@@ -356,9 +356,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/aws-cdk-lib": {
|
||||
"version": "2.173.2",
|
||||
"resolved": "https://registry.npmjs.org/aws-cdk-lib/-/aws-cdk-lib-2.173.2.tgz",
|
||||
"integrity": "sha512-cL9+z8Pl3VZGoO7BwdsrFAOeud/vSl3at7OvmhihbNprMN15XuFUx/rViAU5OI1m92NbV4NBzYSLbSeCwYLNyw==",
|
||||
"version": "2.176.0",
|
||||
"resolved": "https://registry.npmjs.org/aws-cdk-lib/-/aws-cdk-lib-2.176.0.tgz",
|
||||
"integrity": "sha512-6Gs2kBaq4elQ4fNAOiCgbD9oOLx/heb/Lp4OVE6Uf7FulYW0DikWJXxR5GWJslTJ4/sCf3UU91q415fc0bruLg==",
|
||||
"bundleDependencies": [
|
||||
"@balena/dockerignore",
|
||||
"case",
|
||||
@@ -377,7 +377,7 @@
|
||||
"@aws-cdk/asset-awscli-v1": "^2.2.208",
|
||||
"@aws-cdk/asset-kubectl-v20": "^2.1.3",
|
||||
"@aws-cdk/asset-node-proxy-agent-v6": "^2.1.0",
|
||||
"@aws-cdk/cloud-assembly-schema": "^38.0.1",
|
||||
"@aws-cdk/cloud-assembly-schema": "^39.0.1",
|
||||
"@balena/dockerignore": "^1.0.2",
|
||||
"case": "1.6.3",
|
||||
"fs-extra": "^11.2.0",
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
// swift-tools-version:6.0
|
||||
// swift-tools-version:6.1
|
||||
|
||||
import PackageDescription
|
||||
|
||||
// needed for CI to test the local version of the library
|
||||
import struct Foundation.URL
|
||||
|
||||
#if os(macOS)
|
||||
let platforms: [PackageDescription.SupportedPlatform]? = [.macOS(.v15)]
|
||||
#else
|
||||
let platforms: [PackageDescription.SupportedPlatform]? = nil
|
||||
#endif
|
||||
|
||||
let package = Package(
|
||||
name: "swift-aws-lambda-runtime-example",
|
||||
platforms: platforms,
|
||||
platforms: [.macOS(.v15)],
|
||||
products: [
|
||||
.executable(name: "HelloJSON", targets: ["HelloJSON"])
|
||||
],
|
||||
dependencies: [
|
||||
// during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below
|
||||
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main")
|
||||
.package(
|
||||
url: "https://github.com/swift-server/swift-aws-lambda-runtime.git",
|
||||
branch: "ff-package-traits",
|
||||
traits: [
|
||||
.trait(name: "FoundationJSONSupport")
|
||||
]
|
||||
)
|
||||
],
|
||||
targets: [
|
||||
.executableTarget(
|
||||
|
||||
@@ -12,6 +12,35 @@ The handler is `(event: String, context: LambdaContext)`. The function takes two
|
||||
|
||||
The function return value will be encoded as your Lambda function response.
|
||||
|
||||
## Test locally
|
||||
|
||||
You can test your function locally before deploying it to AWS Lambda.
|
||||
|
||||
To start the local function, type the following commands:
|
||||
|
||||
```bash
|
||||
swift run
|
||||
```
|
||||
|
||||
It will compile your code and start the local server. You know the local server is ready to accept connections when you see this message.
|
||||
|
||||
```txt
|
||||
Building for debugging...
|
||||
[1/1] Write swift-version--644A47CB88185983.txt
|
||||
Build of product 'MyLambda' complete! (0.31s)
|
||||
2025-01-29T12:44:48+0100 info LocalServer : host="127.0.0.1" port=7000 [AWSLambdaRuntime] Server started and listening
|
||||
```
|
||||
|
||||
Then, from another Terminal, send your payload with `curl`. Note that the payload must be a valid JSON string. In the case of this function that accepts a simple String, it means the String must be wrapped in between double quotes.
|
||||
|
||||
```bash
|
||||
curl -d '"seb"' http://127.0.0.1:7000/invoke
|
||||
"Hello seb"
|
||||
```
|
||||
|
||||
> [!IMPORTANT]
|
||||
> The local server is only available in `DEBUG` mode. It will not start with `swift -c release run`.
|
||||
|
||||
## Build & Package
|
||||
|
||||
To build & archive the package, type the following commands.
|
||||
|
||||
+3
-1
@@ -28,6 +28,8 @@ This directory contains example code for Lambda functions.
|
||||
|
||||
- **[HelloWorld](HelloWorld/README.md)**: a simple Lambda function (requires [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)).
|
||||
|
||||
- **[S3EventNotifier](S3EventNotifier/README.md)**: a Lambda function that receives object-upload notifications from an [Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) bucket.
|
||||
|
||||
- **[S3_AWSSDK](S3_AWSSDK/README.md)**: a Lambda function that uses the [AWS SDK for Swift](https://docs.aws.amazon.com/sdk-for-swift/latest/developer-guide/getting-started.html) to invoke an [Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) API (requires [AWS SAM](https://aws.amazon.com/serverless/sam/)).
|
||||
|
||||
- **[S3_Soto](S3_Soto/README.md)**: a Lambda function that uses [Soto](https://github.com/soto-project/soto) to invoke an [Amazon S3](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) API (requires [AWS SAM](https://aws.amazon.com/serverless/sam/)).
|
||||
@@ -64,4 +66,4 @@ To obtain these keys, you need an AWS account:
|
||||
|
||||
4. **(Optional) Generate Temporary Security Credentials**: If you’re using temporary credentials (which are more secure for short-term access), use AWS Security Token Service (STS). You can call the `GetSessionToken` or `AssumeRole` API to generate temporary credentials, including a session token.
|
||||
|
||||
With these in hand, you can use AWS SigV4 to securely sign your requests and interact with AWS services from your Swift app.
|
||||
With these in hand, you can use AWS SigV4 to securely sign your requests and interact with AWS services from your Swift app.
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
.DS_Store
|
||||
/.build
|
||||
/Packages
|
||||
xcuserdata/
|
||||
DerivedData/
|
||||
.swiftpm/configuration/registries.json
|
||||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
|
||||
.netrc
|
||||
@@ -0,0 +1,57 @@
|
||||
// swift-tools-version: 6.0
|
||||
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
||||
|
||||
import PackageDescription
|
||||
|
||||
// needed for CI to test the local version of the library
|
||||
import struct Foundation.URL
|
||||
|
||||
let package = Package(
|
||||
name: "ResourcesPackaging",
|
||||
platforms: [.macOS(.v15)],
|
||||
products: [
|
||||
.executable(name: "MyLambda", targets: ["MyLambda"])
|
||||
],
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main")
|
||||
],
|
||||
targets: [
|
||||
.executableTarget(
|
||||
name: "MyLambda",
|
||||
dependencies: [
|
||||
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime")
|
||||
],
|
||||
path: ".",
|
||||
resources: [
|
||||
.process("hello.txt")
|
||||
]
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
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)
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftAWSLambdaRuntime open source project
|
||||
//
|
||||
// Copyright (c) 2025 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
|
||||
import Foundation
|
||||
|
||||
let runtime = LambdaRuntime {
|
||||
(event: String, context: LambdaContext) in
|
||||
guard let fileURL = Bundle.module.url(forResource: "hello", withExtension: "txt") else {
|
||||
fatalError("no file url")
|
||||
}
|
||||
return try String(contentsOf: fileURL, encoding: .utf8)
|
||||
}
|
||||
|
||||
try await runtime.run()
|
||||
@@ -0,0 +1 @@
|
||||
Hello World
|
||||
@@ -0,0 +1,9 @@
|
||||
.DS_Store
|
||||
/.build
|
||||
/.index-build
|
||||
/Packages
|
||||
xcuserdata/
|
||||
DerivedData/
|
||||
.swiftpm/configuration/registries.json
|
||||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
|
||||
.netrc
|
||||
@@ -0,0 +1,50 @@
|
||||
// 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)
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
# S3 Event Notifier
|
||||
|
||||
This example demonstrates how to write a Lambda that is invoked by an event originating from Amazon S3, such as a new object being uploaded to a bucket.
|
||||
|
||||
## Code
|
||||
|
||||
In this example the Lambda function receives an `S3Event` object defined in the `AWSLambdaEvents` library as input object. The `S3Event` object contains all the information about the S3 event that triggered the function, but what we are interested in is the bucket name and the object key, which are inside of a notification `Record`. The object contains an array of records, however since the Lambda function is triggered by a single event, we can safely assume that there is only one record in the array: the first one. Inside of this record, we can find the bucket name and the object key:
|
||||
|
||||
```swift
|
||||
guard let s3NotificationRecord = event.records.first else {
|
||||
throw LambdaError.noNotificationRecord
|
||||
}
|
||||
|
||||
let bucket = s3NotificationRecord.s3.bucket.name
|
||||
let key = s3NotificationRecord.s3.object.key.replacingOccurrences(of: "+", with: " ")
|
||||
```
|
||||
|
||||
The key is URL encoded, so we replace the `+` with a space.
|
||||
|
||||
## Build & Package
|
||||
|
||||
To build & archive the package you can use the following commands:
|
||||
|
||||
```bash
|
||||
swift build
|
||||
swift package archive --allow-network-connections docker
|
||||
```
|
||||
|
||||
If there are no errors, a ZIP file should be ready to deploy, located at `.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/S3EventNotifier/S3EventNotifier.zip`.
|
||||
|
||||
## Deploy
|
||||
|
||||
> [!IMPORTANT]
|
||||
> The Lambda function and the S3 bucket must be located in the same AWS Region. In the code below, we use `eu-west-1` (Ireland).
|
||||
|
||||
To deploy the Lambda function, you can use the `aws` command line:
|
||||
|
||||
```bash
|
||||
REGION=eu-west-1
|
||||
aws lambda create-function \
|
||||
--region "${REGION}" \
|
||||
--function-name S3EventNotifier \
|
||||
--zip-file fileb://.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/S3EventNotifier/S3EventNotifier.zip \
|
||||
--runtime provided.al2 \
|
||||
--handler provided \
|
||||
--architectures arm64 \
|
||||
--role arn:aws:iam::<YOUR_ACCOUNT_ID>:role/lambda_basic_execution
|
||||
```
|
||||
|
||||
The `--architectures` flag is only required when you build the binary on an Apple Silicon machine (Apple M1 or more recent). It defaults to `x64`.
|
||||
|
||||
Be sure to define `REGION` with the region where you want to deploy your Lambda function and replace `<YOUR_ACCOUNT_ID>` with your actual AWS account ID (for example: 012345678901).
|
||||
|
||||
Besides deploying the Lambda function you also need to create the S3 bucket and configure it to send events to the Lambda function. You can do this using the following commands:
|
||||
|
||||
```bash
|
||||
REGION=eu-west-1
|
||||
|
||||
aws s3api create-bucket \
|
||||
--region "${REGION}" \
|
||||
--bucket my-test-bucket \
|
||||
--create-bucket-configuration LocationConstraint="${REGION}"
|
||||
|
||||
aws lambda add-permission \
|
||||
--region "${REGION}" \
|
||||
--function-name S3EventNotifier \
|
||||
--statement-id S3InvokeFunction \
|
||||
--action lambda:InvokeFunction \
|
||||
--principal s3.amazonaws.com \
|
||||
--source-arn arn:aws:s3:::my-test-bucket
|
||||
|
||||
aws s3api put-bucket-notification-configuration \
|
||||
--region "${REGION}" \
|
||||
--bucket my-test-bucket \
|
||||
--notification-configuration '{
|
||||
"LambdaFunctionConfigurations": [{
|
||||
"LambdaFunctionArn": "arn:aws:lambda:${REGION}:<YOUR_ACCOUNT_ID>:function:S3EventNotifier",
|
||||
"Events": ["s3:ObjectCreated:*"]
|
||||
}]
|
||||
}'
|
||||
|
||||
touch testfile.txt && aws s3 cp testfile.txt s3://my-test-bucket/
|
||||
```
|
||||
|
||||
This will:
|
||||
- create a bucket named `my-test-bucket` in the `$REGION` region;
|
||||
- add a permission to the Lambda function to be invoked by Amazon S3;
|
||||
- configure the bucket to send `s3:ObjectCreated:*` events to the Lambda function named `S3EventNotifier`;
|
||||
- upload a file named `testfile.txt` to the bucket.
|
||||
|
||||
Replace `my-test-bucket` with your bucket name (bucket names are unique globaly and this one is already taken). Also replace `REGION` environment variable with the AWS Region where you deployed the Lambda function and `<YOUR_ACCOUNT_ID>` with your actual AWS account ID.
|
||||
|
||||
> [!IMPORTANT]
|
||||
> The Lambda function and the S3 bucket must be located in the same AWS Region. Adjust the code above according to your closest AWS Region.
|
||||
@@ -0,0 +1,33 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftAWSLambdaRuntime open source project
|
||||
//
|
||||
// Copyright (c) 2025 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 Foundation
|
||||
|
||||
let runtime = LambdaRuntime { (event: S3Event, context: LambdaContext) async throws in
|
||||
guard let s3NotificationRecord = event.records.first else {
|
||||
context.logger.error("No S3 notification record found in the event")
|
||||
return
|
||||
}
|
||||
|
||||
let bucket = s3NotificationRecord.s3.bucket.name
|
||||
let key = s3NotificationRecord.s3.object.key.replacingOccurrences(of: "+", with: " ")
|
||||
|
||||
context.logger.info("Received notification from S3 bucket '\(bucket)' for object with key '\(key)'")
|
||||
|
||||
// Here you could, for example, notify an API or a messaging service
|
||||
}
|
||||
|
||||
try await runtime.run()
|
||||
@@ -14,7 +14,7 @@ let package = Package(
|
||||
dependencies: [
|
||||
// during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below
|
||||
.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"),
|
||||
.package(url: "https://github.com/swift-server/swift-aws-lambda-events", from: "1.0.0"),
|
||||
.package(url: "https://github.com/awslabs/aws-sdk-swift", from: "1.0.0"),
|
||||
],
|
||||
targets: [
|
||||
|
||||
@@ -16,7 +16,7 @@ let package = Package(
|
||||
|
||||
// during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below
|
||||
.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"),
|
||||
.package(url: "https://github.com/swift-server/swift-aws-lambda-events", from: "1.0.0"),
|
||||
],
|
||||
targets: [
|
||||
.executableTarget(
|
||||
|
||||
@@ -14,7 +14,7 @@ let package = Package(
|
||||
dependencies: [
|
||||
// during CI, the dependency on local version of swift-aws-lambda-runtime is added dynamically below
|
||||
.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.git", branch: "main"),
|
||||
.package(url: "https://github.com/swift-server/swift-aws-lambda-events.git", from: "1.0.0"),
|
||||
],
|
||||
targets: [
|
||||
.executableTarget(
|
||||
|
||||
@@ -160,8 +160,8 @@ You must pass an event to the Lambda function. You can use the `event.json` file
|
||||
sam local invoke -e Tests/event.json
|
||||
|
||||
START RequestId: 3270171f-46d3-45f9-9bb6-3c2e5e9dc625 Version: $LATEST
|
||||
2024-12-21T16:49:31+0000 debug LambdaRuntime : [AWSLambdaRuntimeCore] LambdaRuntime initialized
|
||||
2024-12-21T16:49:31+0000 trace LambdaRuntime : lambda_ip=127.0.0.1 lambda_port=9001 [AWSLambdaRuntimeCore] Connection to control plane created
|
||||
2024-12-21T16:49:31+0000 debug LambdaRuntime : [AWSLambdaRuntime] LambdaRuntime initialized
|
||||
2024-12-21T16:49:31+0000 trace LambdaRuntime : lambda_ip=127.0.0.1 lambda_port=9001 [AWSLambdaRuntime] Connection to control plane created
|
||||
2024-12-21T16:49:31+0000 debug LambdaRuntime : [APIGatewayLambda] HTTP API Message received
|
||||
2024-12-21T16:49:31+0000 trace LambdaRuntime : [APIGatewayLambda] Event: APIGatewayV2Request(version: "2.0", routeKey: "$default", rawPath: "/", rawQueryString: "", cookies: [], headers: ["x-forwarded-proto": "https", "host": "a5q74es3k2.execute-api.us-east-1.amazonaws.com", "content-length": "0", "x-forwarded-for": "81.0.0.43", "accept": "*/*", "x-amzn-trace-id": "Root=1-66fb03de-07533930192eaf5f540db0cb", "x-forwarded-port": "443", "user-agent": "curl/8.7.1"], queryStringParameters: [:], pathParameters: [:], context: AWSLambdaEvents.APIGatewayV2Request.Context(accountId: "012345678901", apiId: "a5q74es3k2", domainName: "a5q74es3k2.execute-api.us-east-1.amazonaws.com", domainPrefix: "a5q74es3k2", stage: "$default", requestId: "e72KxgsRoAMEMSA=", http: AWSLambdaEvents.APIGatewayV2Request.Context.HTTP(method: GET, path: "/", protocol: "HTTP/1.1", sourceIp: "81.0.0.43", userAgent: "curl/8.7.1"), authorizer: nil, authentication: nil, time: "30/Sep/2024:20:02:38 +0000", timeEpoch: 1727726558220), stageVariables: [:], body: Optional("aGVsbG8gd29ybGQgb2YgU1dJRlQgTEFNQkRBIQ=="), isBase64Encoded: false)
|
||||
END RequestId: 5b71587a-39da-445e-855d-27a700e57efd
|
||||
|
||||
@@ -18,7 +18,7 @@ import Logging
|
||||
import Testing
|
||||
|
||||
@testable import APIGatewayLambda // to access the business code
|
||||
@testable import AWSLambdaRuntimeCore // to access the LambdaContext
|
||||
@testable import AWSLambdaRuntime // to access the LambdaContext
|
||||
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
|
||||
Reference in New Issue
Block a user