From 54e6473b32a21b5ea1d4a4237c7d0f19aba632fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Tue, 1 Jul 2025 23:20:04 +0200 Subject: [PATCH 1/8] move all example sunder one swift project --- .../.gitignore | 0 .../APIGateway+LambdaAuthorizer/Package.swift | 63 ------ .../APIGateway+LambdaAuthorizer/README.md | 4 +- Examples/APIGateway/.gitignore | 2 - Examples/APIGateway/Package.swift | 56 ----- Examples/APIGateway/README.md | 6 +- Examples/APIGateway/event.json | 69 ++++++ Examples/APIGateway/template.yaml | 2 +- Examples/BackgroundTasks/.gitignore | 8 - Examples/BackgroundTasks/Package.swift | 54 ----- Examples/BackgroundTasks/README.md | 2 +- Examples/CDK/Package.swift | 56 ----- Examples/CDK/README.md | 6 +- .../CDK/infra/lib/lambda-api-project-stack.ts | 2 +- Examples/HelloJSON/.gitignore | 4 - Examples/HelloJSON/Package.swift | 59 ------ Examples/HelloJSON/README.md | 2 +- Examples/HelloWorld/.gitignore | 4 - Examples/HelloWorld/Package.swift | 54 ----- Examples/HelloWorld/README.md | 10 +- Examples/Package.swift | 197 ++++++++++++++++++ Examples/README.md | 2 + Examples/ResourcesPackaging/.gitignore | 8 - Examples/ResourcesPackaging/Package.swift | 57 ----- Examples/S3EventNotifier/.gitignore | 9 - Examples/S3EventNotifier/Package.swift | 50 ----- Examples/S3_AWSSDK/.gitignore | 12 -- Examples/S3_AWSSDK/Package.swift | 57 ----- Examples/S3_AWSSDK/README.md | 4 +- Examples/S3_Soto/.gitignore | 12 -- Examples/S3_Soto/README.md | 4 +- Examples/Streaming/.gitignore | 8 - Examples/Streaming/README.md | 2 +- Examples/Testing/Package.swift | 64 ------ Examples/Testing/README.md | 6 +- Examples/Testing/Tests/BusinessTests.swift | 2 +- Examples/Testing/Tests/HandlerTests.swift | 3 +- Examples/Testing/template.yaml | 2 +- Examples/Tutorial/.gitignore | 8 - Examples/Tutorial/Package.swift | 51 ----- .../FoundationSupport/Lambda+JSON.swift | 4 +- Sources/AWSLambdaRuntime/Lambda+Codable.swift | 16 +- Tests/AWSLambdaRuntimeTests/PoolTests.swift | 4 +- 43 files changed, 312 insertions(+), 733 deletions(-) rename Examples/{APIGateway+LambdaAuthorizer => }/.gitignore (100%) delete mode 100644 Examples/APIGateway+LambdaAuthorizer/Package.swift delete mode 100644 Examples/APIGateway/.gitignore delete mode 100644 Examples/APIGateway/Package.swift create mode 100644 Examples/APIGateway/event.json delete mode 100644 Examples/BackgroundTasks/.gitignore delete mode 100644 Examples/BackgroundTasks/Package.swift delete mode 100644 Examples/CDK/Package.swift delete mode 100644 Examples/HelloJSON/.gitignore delete mode 100644 Examples/HelloJSON/Package.swift delete mode 100644 Examples/HelloWorld/.gitignore delete mode 100644 Examples/HelloWorld/Package.swift create mode 100644 Examples/Package.swift delete mode 100644 Examples/ResourcesPackaging/.gitignore delete mode 100644 Examples/ResourcesPackaging/Package.swift delete mode 100644 Examples/S3EventNotifier/.gitignore delete mode 100644 Examples/S3EventNotifier/Package.swift delete mode 100644 Examples/S3_AWSSDK/.gitignore delete mode 100644 Examples/S3_AWSSDK/Package.swift delete mode 100644 Examples/S3_Soto/.gitignore delete mode 100644 Examples/Streaming/.gitignore delete mode 100644 Examples/Testing/Package.swift delete mode 100644 Examples/Tutorial/.gitignore delete mode 100644 Examples/Tutorial/Package.swift diff --git a/Examples/APIGateway+LambdaAuthorizer/.gitignore b/Examples/.gitignore similarity index 100% rename from Examples/APIGateway+LambdaAuthorizer/.gitignore rename to Examples/.gitignore diff --git a/Examples/APIGateway+LambdaAuthorizer/Package.swift b/Examples/APIGateway+LambdaAuthorizer/Package.swift deleted file mode 100644 index 03117835..00000000 --- a/Examples/APIGateway+LambdaAuthorizer/Package.swift +++ /dev/null @@ -1,63 +0,0 @@ -// 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: "swift-aws-lambda-runtime-example", - platforms: [.macOS(.v15)], - products: [ - .executable(name: "APIGatewayLambda", targets: ["APIGatewayLambda"]), - .executable(name: "AuthorizerLambda", targets: ["AuthorizerLambda"]), - ], - 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", from: "1.0.0"), - ], - targets: [ - .executableTarget( - name: "APIGatewayLambda", - dependencies: [ - .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), - .product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"), - ] - ), - .executableTarget( - name: "AuthorizerLambda", - 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) - ] -} diff --git a/Examples/APIGateway+LambdaAuthorizer/README.md b/Examples/APIGateway+LambdaAuthorizer/README.md index a7a55812..a1c74655 100644 --- a/Examples/APIGateway+LambdaAuthorizer/README.md +++ b/Examples/APIGateway+LambdaAuthorizer/README.md @@ -18,8 +18,8 @@ This example uses an authorizer that returns the simple response. The authorizer To build the package, type the following commands. ```bash -swift build -swift package archive --allow-network-connections docker +swift build --target APIGatewayLambda --target AuthorizerLambda +swift package archive --products APIGatewayLambda --products AuthorizerLambda --allow-network-connections docker ``` If there is no error, there are two ZIP files ready to deploy, one for the authorizer function and one for the business function. diff --git a/Examples/APIGateway/.gitignore b/Examples/APIGateway/.gitignore deleted file mode 100644 index e4044f6f..00000000 --- a/Examples/APIGateway/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -samconfig.toml -Makefile diff --git a/Examples/APIGateway/Package.swift b/Examples/APIGateway/Package.swift deleted file mode 100644 index b2373801..00000000 --- a/Examples/APIGateway/Package.swift +++ /dev/null @@ -1,56 +0,0 @@ -// 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: "swift-aws-lambda-runtime-example", - platforms: [.macOS(.v15)], - products: [ - .executable(name: "APIGatewayLambda", targets: ["APIGatewayLambda"]) - ], - 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", from: "1.0.0"), - ], - targets: [ - .executableTarget( - name: "APIGatewayLambda", - dependencies: [ - .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), - .product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"), - ], - path: "Sources" - ) - ] -) - -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) - ] -} diff --git a/Examples/APIGateway/README.md b/Examples/APIGateway/README.md index d03c5343..74fbd054 100644 --- a/Examples/APIGateway/README.md +++ b/Examples/APIGateway/README.md @@ -21,12 +21,12 @@ The function must return a `APIGatewayV2Response`. To build the package, type the following commands. ```bash -swift build -swift package archive --allow-network-connections docker +swift build --target APIGateway +swift package archive --products APIGateway --allow-network-connections docker ``` If there is no error, there is a ZIP file ready to deploy. -The ZIP file is located at `.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/APIGatewayLambda/APIGatewayLambda.zip` +The ZIP file is located at `.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/APIGateway/APIGateway.zip` ## Deploy diff --git a/Examples/APIGateway/event.json b/Examples/APIGateway/event.json new file mode 100644 index 00000000..8993f51f --- /dev/null +++ b/Examples/APIGateway/event.json @@ -0,0 +1,69 @@ +{ + "version": "2.0", + "routeKey": "$default", + "rawPath": "/my/path", + "rawQueryString": "parameter1=value1¶meter1=value2¶meter2=value", + "cookies": [ + "cookie1", + "cookie2" + ], + "headers": { + "header1": "value1", + "header2": "value1,value2" + }, + "queryStringParameters": { + "parameter1": "value1,value2", + "parameter2": "value" + }, + "requestContext": { + "accountId": "123456789012", + "apiId": "api-id", + "authentication": { + "clientCert": { + "clientCertPem": "CERT_CONTENT", + "subjectDN": "www.example.com", + "issuerDN": "Example issuer", + "serialNumber": "a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1:a1", + "validity": { + "notBefore": "May 28 12:30:02 2019 GMT", + "notAfter": "Aug 5 09:36:04 2021 GMT" + } + } + }, + "authorizer": { + "jwt": { + "claims": { + "claim1": "value1", + "claim2": "value2" + }, + "scopes": [ + "scope1", + "scope2" + ] + } + }, + "domainName": "id.execute-api.us-east-1.amazonaws.com", + "domainPrefix": "id", + "http": { + "method": "POST", + "path": "/my/path", + "protocol": "HTTP/1.1", + "sourceIp": "192.0.2.1", + "userAgent": "agent" + }, + "requestId": "id", + "routeKey": "$default", + "stage": "$default", + "time": "12/Mar/2020:19:03:58 +0000", + "timeEpoch": 1583348638390 + }, + "body": "Hello from Lambda", + "pathParameters": { + "parameter1": "value1" + }, + "isBase64Encoded": false, + "stageVariables": { + "stageVariable1": "value1", + "stageVariable2": "value2" + } +} \ No newline at end of file diff --git a/Examples/APIGateway/template.yaml b/Examples/APIGateway/template.yaml index 939f09f8..8be258ea 100644 --- a/Examples/APIGateway/template.yaml +++ b/Examples/APIGateway/template.yaml @@ -7,7 +7,7 @@ Resources: APIGatewayLambda: Type: AWS::Serverless::Function Properties: - CodeUri: .build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/APIGatewayLambda/APIGatewayLambda.zip + CodeUri: .build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/APIGateway/APIGateway.zip Timeout: 60 Handler: swift.bootstrap # ignored by the Swift runtime Runtime: provided.al2 diff --git a/Examples/BackgroundTasks/.gitignore b/Examples/BackgroundTasks/.gitignore deleted file mode 100644 index 0023a534..00000000 --- a/Examples/BackgroundTasks/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -.DS_Store -/.build -/Packages -xcuserdata/ -DerivedData/ -.swiftpm/configuration/registries.json -.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata -.netrc diff --git a/Examples/BackgroundTasks/Package.swift b/Examples/BackgroundTasks/Package.swift deleted file mode 100644 index 3d5b52bb..00000000 --- a/Examples/BackgroundTasks/Package.swift +++ /dev/null @@ -1,54 +0,0 @@ -// 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: "swift-aws-lambda-runtime-example", - platforms: [.macOS(.v15)], - products: [ - .executable(name: "BackgroundTasks", targets: ["BackgroundTasks"]) - ], - 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") - ], - targets: [ - .executableTarget( - name: "BackgroundTasks", - dependencies: [ - .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime") - ], - path: "Sources" - ) - ] -) - -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) - ] -} diff --git a/Examples/BackgroundTasks/README.md b/Examples/BackgroundTasks/README.md index e1bf0ddd..1d3a4695 100644 --- a/Examples/BackgroundTasks/README.md +++ b/Examples/BackgroundTasks/README.md @@ -25,7 +25,7 @@ Once the struct is created and the `handle(...)` method is defined, the sample c To build & archive the package, type the following commands. ```bash -swift package archive --allow-network-connections docker +swift package archive --products BackgroundTasks --allow-network-connections docker ``` If there is no error, there is a ZIP file ready to deploy. diff --git a/Examples/CDK/Package.swift b/Examples/CDK/Package.swift deleted file mode 100644 index b2373801..00000000 --- a/Examples/CDK/Package.swift +++ /dev/null @@ -1,56 +0,0 @@ -// 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: "swift-aws-lambda-runtime-example", - platforms: [.macOS(.v15)], - products: [ - .executable(name: "APIGatewayLambda", targets: ["APIGatewayLambda"]) - ], - 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", from: "1.0.0"), - ], - targets: [ - .executableTarget( - name: "APIGatewayLambda", - dependencies: [ - .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), - .product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"), - ], - path: "Sources" - ) - ] -) - -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) - ] -} diff --git a/Examples/CDK/README.md b/Examples/CDK/README.md index 69b772ec..b107819b 100644 --- a/Examples/CDK/README.md +++ b/Examples/CDK/README.md @@ -11,12 +11,12 @@ The Lambda function takes all HTTP headers it receives as input and returns them To build the package, type the following commands. ```bash -swift build -swift package archive --allow-network-connections docker +swift build --target CDKAPIGatewayLambda +swift package archive --products CDKAPIGatewayLambda --allow-network-connections docker ``` If there is no error, there is a ZIP file ready to deploy. -The ZIP file is located at `.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/APIGatewayLambda/APIGatewayLambda.zip` +The ZIP file is located at `.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/CDKAPIGatewayLambda/CDKAPIGatewayLambda.zip` ## Deploy diff --git a/Examples/CDK/infra/lib/lambda-api-project-stack.ts b/Examples/CDK/infra/lib/lambda-api-project-stack.ts index 3598478c..31dcef4c 100644 --- a/Examples/CDK/infra/lib/lambda-api-project-stack.ts +++ b/Examples/CDK/infra/lib/lambda-api-project-stack.ts @@ -26,7 +26,7 @@ export class LambdaApiStack extends cdk.Stack { runtime: lambda.Runtime.PROVIDED_AL2, architecture: lambda.Architecture.ARM_64, handler: 'bootstrap', - code: lambda.Code.fromAsset('../.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/APIGatewayLambda/APIGatewayLambda.zip'), + code: lambda.Code.fromAsset('../.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/CDKAPIGatewayLambda/CDKAPIGatewayLambda.zip'), memorySize: 512, timeout: cdk.Duration.seconds(30), environment: { diff --git a/Examples/HelloJSON/.gitignore b/Examples/HelloJSON/.gitignore deleted file mode 100644 index e41d0be5..00000000 --- a/Examples/HelloJSON/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -response.json -samconfig.toml -template.yaml -Makefile diff --git a/Examples/HelloJSON/Package.swift b/Examples/HelloJSON/Package.swift deleted file mode 100644 index 9f26ff9d..00000000 --- a/Examples/HelloJSON/Package.swift +++ /dev/null @@ -1,59 +0,0 @@ -// swift-tools-version:6.1 - -import PackageDescription - -// needed for CI to test the local version of the library -import struct Foundation.URL - -let package = Package( - name: "swift-aws-lambda-runtime-example", - 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: "ff-package-traits", - traits: [ - .trait(name: "FoundationJSONSupport") - ] - ) - ], - targets: [ - .executableTarget( - name: "HelloJSON", - dependencies: [ - .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime") - ] - ) - ] -) - -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) - ] -} diff --git a/Examples/HelloJSON/README.md b/Examples/HelloJSON/README.md index d3f1dc29..5c6bce09 100644 --- a/Examples/HelloJSON/README.md +++ b/Examples/HelloJSON/README.md @@ -21,7 +21,7 @@ The function return value will be encoded to a `HelloResponse` as your Lambda fu To build & archive the package, type the following commands. ```bash -swift package archive --allow-network-connections docker +swift package archive --products HelloJSON --allow-network-connections docker ``` If there is no error, there is a ZIP file ready to deploy. diff --git a/Examples/HelloWorld/.gitignore b/Examples/HelloWorld/.gitignore deleted file mode 100644 index e41d0be5..00000000 --- a/Examples/HelloWorld/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -response.json -samconfig.toml -template.yaml -Makefile diff --git a/Examples/HelloWorld/Package.swift b/Examples/HelloWorld/Package.swift deleted file mode 100644 index 17d5e4a4..00000000 --- a/Examples/HelloWorld/Package.swift +++ /dev/null @@ -1,54 +0,0 @@ -// 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: "swift-aws-lambda-runtime-example", - platforms: [.macOS(.v15)], - products: [ - .executable(name: "MyLambda", targets: ["MyLambda"]) - ], - 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") - ], - targets: [ - .executableTarget( - name: "MyLambda", - dependencies: [ - .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime") - ], - path: "Sources" - ) - ] -) - -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) - ] -} diff --git a/Examples/HelloWorld/README.md b/Examples/HelloWorld/README.md index c4eacfc2..ba7cfdd8 100644 --- a/Examples/HelloWorld/README.md +++ b/Examples/HelloWorld/README.md @@ -19,7 +19,7 @@ You can test your function locally before deploying it to AWS Lambda. To start the local function, type the following commands: ```bash -swift run +swift run HelloWorld ``` 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. @@ -46,12 +46,12 @@ curl -d '"seb"' http://127.0.0.1:7000/invoke To build & archive the package, type the following commands. ```bash -swift build -swift package archive --allow-network-connections docker +swift build --target HelloWorld +swift package archive --products HelloWorld --allow-network-connections docker ``` If there is no error, there is a ZIP file ready to deploy. -The ZIP file is located at `.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/MyLambda/MyLambda.zip` +The ZIP file is located at `.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/HelloWorld/HelloWorld.zip` ## Deploy @@ -60,7 +60,7 @@ Here is how to deploy using the `aws` command line. ```bash aws lambda create-function \ --function-name MyLambda \ ---zip-file fileb://.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/MyLambda/MyLambda.zip \ +--zip-file fileb://.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/HelloWorld/HelloWorld.zip \ --runtime provided.al2 \ --handler provided \ --architectures arm64 \ diff --git a/Examples/Package.swift b/Examples/Package.swift new file mode 100644 index 00000000..c1c81149 --- /dev/null +++ b/Examples/Package.swift @@ -0,0 +1,197 @@ +// 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: "swift-aws-lambda-runtime-example", + platforms: [.macOS(.v15)], + products: [ + // APIGateway + .executable(name: "APIGateway", targets: ["APIGateway"]), + // APIGateway+LambdaAuthorizer + .executable(name: "APIGatewayLambda", targets: ["APIGatewayLambda"]), + .executable(name: "AuthorizerLambda", targets: ["AuthorizerLambda"]), + // BackgroundTasks + .executable(name: "BackgroundTasks", targets: ["BackgroundTasks"]), + // CDK + .executable(name: "CDKAPIGatewayLambda", targets: ["CDKAPIGatewayLambda"]), + // HelloJSON + .executable(name: "HelloJSON", targets: ["HelloJSON"]), + // HelloWorld + .executable(name: "HelloWorld", targets: ["HelloWorld"]), + // ResourcesPackaging + .executable(name: "ResourcesPackaging", targets: ["ResourcesPackaging"]), + // AWSSDKExample + .executable(name: "AWSSDKExample", targets: ["AWSSDKExample"]), + // SotoExample + .executable(name: "SotoExample", targets: ["SotoExample"]), + // S3EventNotifier + .executable(name: "S3EventNotifier", targets: ["S3EventNotifier"]), + // StreamingNumbers + .executable(name: "StreamingNumbers", targets: ["StreamingNumbers"]), + // Testing + .executable(name: "TestedLambda", targets: ["TestedLambda"]), + // Tutorial + .executable(name: "Palindrome", targets: ["Palindrome"]), + ], + 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", from: "1.0.0"), + // for the AWS SDK example + .package(url: "https://github.com/awslabs/aws-sdk-swift", from: "1.0.0"), + // for the Soto Example + .package(url: "https://github.com/soto-project/soto.git", from: "7.0.0"), + ], + targets: [ + .executableTarget( + name: "APIGateway", + dependencies: [ + .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), + .product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"), + ], + path: "APIGateway/Sources" + ), + .executableTarget( + name: "APIGatewayLambda", + dependencies: [ + .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), + .product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"), + ], + path: "APIGateway+LambdaAuthorizer/Sources/APIGatewayLambda" + ), + .executableTarget( + name: "AuthorizerLambda", + dependencies: [ + .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), + .product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"), + ], + path: "APIGateway+LambdaAuthorizer/Sources/AuthorizerLambda" + ), + .executableTarget( + name: "BackgroundTasks", + dependencies: [ + .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime") + ], + path: "BackgroundTasks/Sources" + ), + .executableTarget( + name: "CDKAPIGatewayLambda", + dependencies: [ + .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), + .product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"), + ], + path: "CDK/Sources" + ), + .executableTarget( + name: "HelloJSON", + dependencies: [ + .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime") + ], + path: "HelloJSON/Sources" + ), + .executableTarget( + name: "HelloWorld", + dependencies: [ + .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime") + ], + path: "HelloWorld/Sources" + ), + .executableTarget( + name: "ResourcesPackaging", + dependencies: [ + .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime") + ], + path: "ResourcesPackaging", + resources: [ + .process("hello.txt") + ] + ), + .executableTarget( + name: "AWSSDKExample", + dependencies: [ + .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), + .product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"), + .product(name: "AWSS3", package: "aws-sdk-swift"), + ], + path: "S3_AWSSDK/Sources" + ), + .executableTarget( + name: "SotoExample", + dependencies: [ + .product(name: "SotoS3", package: "soto"), + .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), + .product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"), + ], + path: "S3_Soto/Sources" + ), + .executableTarget( + name: "S3EventNotifier", + dependencies: [ + .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), + .product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"), + ], + path: "S3EventNotifier/Sources" + ), + .executableTarget( + name: "StreamingNumbers", + dependencies: [ + .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime") + ], + path: "Streaming/Sources" + ), + .executableTarget( + name: "TestedLambda", + dependencies: [ + .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), + .product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"), + ], + path: "Testing/Sources" + ), + .testTarget( + name: "LambdaFunctionTests", + dependencies: ["TestedLambda"], + path: "Testing/Tests", + resources: [ + .process("event.json") + ] + ), + .executableTarget( + name: "Palindrome", + dependencies: [ + .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime") + ], + path: "Tutorial/Sources" + ) + ] +) + +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) + ] +} diff --git a/Examples/README.md b/Examples/README.md index 973df897..c61fec0e 100644 --- a/Examples/README.md +++ b/Examples/README.md @@ -16,6 +16,8 @@ This directory contains example code for Lambda functions. ## Examples +All the commands in the example's README are supposed to be run from the Example/ directory, unless otherwise instructed. + - **[API Gateway](APIGateway/README.md)**: an HTTPS REST API with [Amazon API Gateway](https://docs.aws.amazon.com/apigateway/latest/developerguide/welcome.html) and a Lambda function as backend (requires [AWS SAM](https://aws.amazon.com/serverless/sam/)). - **[API Gateway with Lambda Authorizer](APIGateway+LambdaAuthorizer/README.md)**: an HTTPS REST API with [Amazon API Gateway](https://docs.aws.amazon.com/apigateway/latest/developerguide/welcome.html) protected by a Lambda authorizer (requires [AWS SAM](https://aws.amazon.com/serverless/sam/)). diff --git a/Examples/ResourcesPackaging/.gitignore b/Examples/ResourcesPackaging/.gitignore deleted file mode 100644 index 0023a534..00000000 --- a/Examples/ResourcesPackaging/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -.DS_Store -/.build -/Packages -xcuserdata/ -DerivedData/ -.swiftpm/configuration/registries.json -.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata -.netrc diff --git a/Examples/ResourcesPackaging/Package.swift b/Examples/ResourcesPackaging/Package.swift deleted file mode 100644 index 4680b74a..00000000 --- a/Examples/ResourcesPackaging/Package.swift +++ /dev/null @@ -1,57 +0,0 @@ -// 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) - ] -} diff --git a/Examples/S3EventNotifier/.gitignore b/Examples/S3EventNotifier/.gitignore deleted file mode 100644 index 10edc03d..00000000 --- a/Examples/S3EventNotifier/.gitignore +++ /dev/null @@ -1,9 +0,0 @@ -.DS_Store -/.build -/.index-build -/Packages -xcuserdata/ -DerivedData/ -.swiftpm/configuration/registries.json -.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata -.netrc diff --git a/Examples/S3EventNotifier/Package.swift b/Examples/S3EventNotifier/Package.swift deleted file mode 100644 index 6554b385..00000000 --- a/Examples/S3EventNotifier/Package.swift +++ /dev/null @@ -1,50 +0,0 @@ -// 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) - ] -} diff --git a/Examples/S3_AWSSDK/.gitignore b/Examples/S3_AWSSDK/.gitignore deleted file mode 100644 index 70799e05..00000000 --- a/Examples/S3_AWSSDK/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -.DS_Store -.aws-sam/ -.build -samtemplate.toml -*/build/* -/.build -/Packages -xcuserdata/ -DerivedData/ -.swiftpm/configuration/registries.json -.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata -.netrc \ No newline at end of file diff --git a/Examples/S3_AWSSDK/Package.swift b/Examples/S3_AWSSDK/Package.swift deleted file mode 100644 index 0eec7c6b..00000000 --- a/Examples/S3_AWSSDK/Package.swift +++ /dev/null @@ -1,57 +0,0 @@ -// 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: "AWSSDKExample", - platforms: [.macOS(.v15)], - products: [ - .executable(name: "AWSSDKExample", targets: ["AWSSDKExample"]) - ], - 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", from: "1.0.0"), - .package(url: "https://github.com/awslabs/aws-sdk-swift", from: "1.0.0"), - ], - targets: [ - .executableTarget( - name: "AWSSDKExample", - dependencies: [ - .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), - .product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"), - .product(name: "AWSS3", package: "aws-sdk-swift"), - ] - ) - ] -) - -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) - ] -} diff --git a/Examples/S3_AWSSDK/README.md b/Examples/S3_AWSSDK/README.md index 4c84c277..2574c57b 100644 --- a/Examples/S3_AWSSDK/README.md +++ b/Examples/S3_AWSSDK/README.md @@ -24,8 +24,8 @@ It then extracts the list of bucket names from the output and creates a `\n`-sep To build the package, type the following commands. ```bash -swift build -swift package archive --allow-network-connections docker +swift build --target AWSSDKExample +swift package archive --products AWSSDKExample --allow-network-connections docker ``` If there is no error, there is a ZIP file ready to deploy. diff --git a/Examples/S3_Soto/.gitignore b/Examples/S3_Soto/.gitignore deleted file mode 100644 index 70799e05..00000000 --- a/Examples/S3_Soto/.gitignore +++ /dev/null @@ -1,12 +0,0 @@ -.DS_Store -.aws-sam/ -.build -samtemplate.toml -*/build/* -/.build -/Packages -xcuserdata/ -DerivedData/ -.swiftpm/configuration/registries.json -.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata -.netrc \ No newline at end of file diff --git a/Examples/S3_Soto/README.md b/Examples/S3_Soto/README.md index 7ae0fa16..a248f322 100644 --- a/Examples/S3_Soto/README.md +++ b/Examples/S3_Soto/README.md @@ -24,8 +24,8 @@ Finally, the handler extracts the list of bucket names from the output to create To build the package, type the following command. ```bash -swift build -swift package archive --allow-network-connections docker +swift build --target SotoExample +swift package archive --products SotoExample --allow-network-connections docker ``` If there is no error, there is a ZIP file ready to deploy. diff --git a/Examples/Streaming/.gitignore b/Examples/Streaming/.gitignore deleted file mode 100644 index 0023a534..00000000 --- a/Examples/Streaming/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -.DS_Store -/.build -/Packages -xcuserdata/ -DerivedData/ -.swiftpm/configuration/registries.json -.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata -.netrc diff --git a/Examples/Streaming/README.md b/Examples/Streaming/README.md index 86a42754..876911ad 100644 --- a/Examples/Streaming/README.md +++ b/Examples/Streaming/README.md @@ -28,7 +28,7 @@ Once the struct is created and the `handle(...)` method is defined, the sample c To build & archive the package, type the following commands. ```bash -swift package archive --allow-network-connections docker +swift package archive --product StreamingNumbers --allow-network-connections docker ``` If there is no error, there is a ZIP file ready to deploy. diff --git a/Examples/Testing/Package.swift b/Examples/Testing/Package.swift deleted file mode 100644 index db196325..00000000 --- a/Examples/Testing/Package.swift +++ /dev/null @@ -1,64 +0,0 @@ -// 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: "swift-aws-lambda-runtime-example", - platforms: [.macOS(.v15)], - products: [ - .executable(name: "APIGatewayLambda", targets: ["APIGatewayLambda"]) - ], - 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", from: "1.0.0"), - ], - targets: [ - .executableTarget( - name: "APIGatewayLambda", - dependencies: [ - .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), - .product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"), - ], - path: "Sources" - ), - .testTarget( - name: "LambdaFunctionTests", - dependencies: ["APIGatewayLambda"], - path: "Tests", - resources: [ - .process("event.json") - ] - ), - ] -) - -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) - ] -} diff --git a/Examples/Testing/README.md b/Examples/Testing/README.md index 9bfd0e28..bedc8b8f 100644 --- a/Examples/Testing/README.md +++ b/Examples/Testing/README.md @@ -17,7 +17,7 @@ To include a sample event in your test targets, you must add the `event.json` fi ```swift .testTarget( name: "LambdaFunctionTests", - dependencies: ["APIGatewayLambda"], + dependencies: ["TestingAPIGatewayLambda"], path: "Tests", resources: [ .process("event.json") @@ -54,7 +54,7 @@ class BusinessTests { ```swift .testTarget( name: "BusinessTests", - dependencies: ["APIGatewayLambda"], + dependencies: ["TestingAPIGatewayLambda"], path: "Tests" ) ``` @@ -134,7 +134,7 @@ You can test your Lambda function locally by invoking it with the Swift AWS Lamb You must pass an event to the Lambda function. You can use the `Tests/event.json` file for this purpose. The return value is a `APIGatewayV2Response` object in this example. -Just type `swift run` to run the Lambda function locally, this starts a local HTTP endpoint on localhost:7000. +Just type `swift run --target TestedLambda` to run the Lambda function locally, this starts a local HTTP endpoint on localhost:7000. ```sh LOG_LEVEL=trace swift run diff --git a/Examples/Testing/Tests/BusinessTests.swift b/Examples/Testing/Tests/BusinessTests.swift index 85f821e1..35be1be2 100644 --- a/Examples/Testing/Tests/BusinessTests.swift +++ b/Examples/Testing/Tests/BusinessTests.swift @@ -14,7 +14,7 @@ import Testing -@testable import APIGatewayLambda // to access the business code +@testable import TestedLambda // to access the business code let valuesToTest: [(String, String)] = [ ("hello world", "Hello world"), // happy path diff --git a/Examples/Testing/Tests/HandlerTests.swift b/Examples/Testing/Tests/HandlerTests.swift index 85cc4e4e..27fec766 100644 --- a/Examples/Testing/Tests/HandlerTests.swift +++ b/Examples/Testing/Tests/HandlerTests.swift @@ -13,11 +13,10 @@ //===----------------------------------------------------------------------===// import AWSLambdaEvents -import AWSLambdaRuntime import Logging import Testing -@testable import APIGatewayLambda // to access the business code +@testable import TestedLambda // to access the business code @testable import AWSLambdaRuntime // to access the LambdaContext #if canImport(FoundationEssentials) diff --git a/Examples/Testing/template.yaml b/Examples/Testing/template.yaml index c981c978..ef7f60dd 100644 --- a/Examples/Testing/template.yaml +++ b/Examples/Testing/template.yaml @@ -7,7 +7,7 @@ Resources: APIGatewayLambda: Type: AWS::Serverless::Function Properties: - CodeUri: .build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/APIGatewayLambda/APIGatewayLambda.zip + CodeUri: .build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/TestedLambda/TestedLambda.zip Timeout: 60 Handler: swift.bootstrap # ignored by the Swift runtime Runtime: provided.al2 diff --git a/Examples/Tutorial/.gitignore b/Examples/Tutorial/.gitignore deleted file mode 100644 index 0023a534..00000000 --- a/Examples/Tutorial/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -.DS_Store -/.build -/Packages -xcuserdata/ -DerivedData/ -.swiftpm/configuration/registries.json -.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata -.netrc diff --git a/Examples/Tutorial/Package.swift b/Examples/Tutorial/Package.swift deleted file mode 100644 index 8fd031c1..00000000 --- a/Examples/Tutorial/Package.swift +++ /dev/null @@ -1,51 +0,0 @@ -// swift-tools-version: 6.0 -// The swift-tools-version declares the minimum version of Swift required to build this package. - -import PackageDescription - -import struct Foundation.URL - -let package = Package( - name: "Palindrome", - platforms: [.macOS(.v15)], - dependencies: [ - .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main") - ], - targets: [ - // Targets are the basic building blocks of a package, defining a module or a test suite. - // Targets can depend on other targets in this package and products from dependencies. - .executableTarget( - name: "Palindrome", - dependencies: [ - .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime") - ] - ) - ] -) - -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) - ] -} diff --git a/Sources/AWSLambdaRuntime/FoundationSupport/Lambda+JSON.swift b/Sources/AWSLambdaRuntime/FoundationSupport/Lambda+JSON.swift index 9b47bd7d..5152af71 100644 --- a/Sources/AWSLambdaRuntime/FoundationSupport/Lambda+JSON.swift +++ b/Sources/AWSLambdaRuntime/FoundationSupport/Lambda+JSON.swift @@ -95,7 +95,7 @@ extension LambdaRuntime { decoder: JSONDecoder = JSONDecoder(), encoder: JSONEncoder = JSONEncoder(), logger: Logger = Logger(label: "LambdaRuntime"), - body: sending @escaping (Event, LambdaContext) async throws -> Output + body: @Sendable @escaping (Event, LambdaContext) async throws -> Output ) where Handler == LambdaCodableAdapter< @@ -122,7 +122,7 @@ extension LambdaRuntime { public convenience init( decoder: JSONDecoder = JSONDecoder(), logger: Logger = Logger(label: "LambdaRuntime"), - body: sending @escaping (Event, LambdaContext) async throws -> Void + body: @Sendable @escaping (Event, LambdaContext) async throws -> Void ) where Handler == LambdaCodableAdapter< diff --git a/Sources/AWSLambdaRuntime/Lambda+Codable.swift b/Sources/AWSLambdaRuntime/Lambda+Codable.swift index abc8728b..6aafa71f 100644 --- a/Sources/AWSLambdaRuntime/Lambda+Codable.swift +++ b/Sources/AWSLambdaRuntime/Lambda+Codable.swift @@ -16,7 +16,7 @@ import NIOCore /// The protocol a decoder must conform to so that it can be used with ``LambdaCodableAdapter`` to decode incoming /// `ByteBuffer` events. -public protocol LambdaEventDecoder { +public protocol LambdaEventDecoder: Sendable { /// Decode the `ByteBuffer` representing the received event into the generic `Event` type /// the handler will receive. /// - Parameters: @@ -28,7 +28,7 @@ public protocol LambdaEventDecoder { /// The protocol an encoder must conform to so that it can be used with ``LambdaCodableAdapter`` to encode the generic /// ``LambdaOutputEncoder/Output`` object into a `ByteBuffer`. -public protocol LambdaOutputEncoder { +public protocol LambdaOutputEncoder: Sendable { associatedtype Output /// Encode the generic type `Output` the handler has returned into a `ByteBuffer`. @@ -52,7 +52,7 @@ public struct LambdaHandlerAdapter< Event: Decodable, Output, Handler: LambdaHandler ->: LambdaWithBackgroundProcessingHandler where Handler.Event == Event, Handler.Output == Output { +>: LambdaWithBackgroundProcessingHandler where Handler.Event == Event, Handler.Output == Output, Handler: Sendable { @usableFromInline let handler: Handler /// Initializes an instance given a concrete handler. @@ -86,7 +86,15 @@ public struct LambdaCodableAdapter< Output, Decoder: LambdaEventDecoder, Encoder: LambdaOutputEncoder ->: StreamingLambdaHandler where Handler.Event == Event, Handler.Output == Output, Encoder.Output == Output { +>: StreamingLambdaHandler +where + Handler.Event == Event, + Handler.Output == Output, + Encoder.Output == Output, + Handler: Sendable, + Decoder: Sendable, + Encoder: Sendable +{ @usableFromInline let handler: Handler @usableFromInline let encoder: Encoder @usableFromInline let decoder: Decoder diff --git a/Tests/AWSLambdaRuntimeTests/PoolTests.swift b/Tests/AWSLambdaRuntimeTests/PoolTests.swift index cfeea6a2..1f312ff3 100644 --- a/Tests/AWSLambdaRuntimeTests/PoolTests.swift +++ b/Tests/AWSLambdaRuntimeTests/PoolTests.swift @@ -60,7 +60,7 @@ struct PoolTests { let iterations = 1000 // Start consumer task first - let consumer = Task { @Sendable in + let consumer = Task { [iterations] in var receivedValues = Set() var count = 0 for try await value in pool { @@ -119,7 +119,7 @@ struct PoolTests { let messagesPerProducer = 1000 // Start consumer - let consumer = Task { @Sendable in + let consumer = Task { [producerCount, messagesPerProducer] in var receivedValues = [Int]() var count = 0 for try await value in pool { From d8f6224d764ea4368c68063774ed8817eeeeacf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Tue, 1 Jul 2025 23:31:45 +0200 Subject: [PATCH 2/8] CI for new example structure --- .github/workflows/pull_request.yml | 4 ++-- .github/workflows/scripts/integration_tests.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 058a2888..0b18dc33 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -33,10 +33,10 @@ jobs: name: "Integration tests" examples_enabled: true matrix_linux_command: "LAMBDA_USE_LOCAL_DEPS=../.. swift build" - # We pass the list of examples here, but we can't pass an array as argument + # We pass the list of examples targets here, but we can't pass an array as argument # Instead, we pass a String with a valid JSON array. # The workaround is mentioned here https://github.com/orgs/community/discussions/11692 - examples: "[ 'APIGateway', 'APIGateway+LambdaAuthorizer', 'BackgroundTasks', 'HelloJSON', 'HelloWorld', 'ResourcesPackaging', 'S3EventNotifier', 'S3_AWSSDK', 'S3_Soto', 'Streaming', 'Testing', 'Tutorial' ]" + examples: "[ 'APIGateway', 'APIGatewayLambda', 'AuthorizerLambda', 'BackgroundTasks', 'CDKAPIGAtewayLambda','HelloJSON', 'HelloWorld', 'ResourcesPackaging', 'S3EventNotifier', 'AWSSDKExample', 'SotoExample', 'StreamingNumbers', 'TestedLambda', 'Palindrome' ]" archive_plugin_examples: "[ 'HelloWorld', 'ResourcesPackaging' ]" archive_plugin_enabled: true diff --git a/.github/workflows/scripts/integration_tests.sh b/.github/workflows/scripts/integration_tests.sh index 8d11b313..dea6d7c0 100755 --- a/.github/workflows/scripts/integration_tests.sh +++ b/.github/workflows/scripts/integration_tests.sh @@ -24,9 +24,9 @@ test -n "${SWIFT_VERSION:-}" || fatal "SWIFT_VERSION unset" test -n "${COMMAND:-}" || fatal "COMMAND unset" test -n "${EXAMPLE:-}" || fatal "EXAMPLE unset" -pushd Examples/"$EXAMPLE" > /dev/null +pushd Examples > /dev/null log "Running command with Swift $SWIFT_VERSION" -eval "$COMMAND" +eval "$COMMAND --target $EXAMPLE" popd From 6439cc64b0216da651fd39d7aa061ad1dd8e4922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Tue, 1 Jul 2025 23:43:21 +0200 Subject: [PATCH 3/8] recover previous version of files --- .../FoundationSupport/Lambda+JSON.swift | 4 ++-- Sources/AWSLambdaRuntime/Lambda+Codable.swift | 16 ++++------------ Tests/AWSLambdaRuntimeTests/PoolTests.swift | 4 ++-- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/Sources/AWSLambdaRuntime/FoundationSupport/Lambda+JSON.swift b/Sources/AWSLambdaRuntime/FoundationSupport/Lambda+JSON.swift index 5152af71..9b47bd7d 100644 --- a/Sources/AWSLambdaRuntime/FoundationSupport/Lambda+JSON.swift +++ b/Sources/AWSLambdaRuntime/FoundationSupport/Lambda+JSON.swift @@ -95,7 +95,7 @@ extension LambdaRuntime { decoder: JSONDecoder = JSONDecoder(), encoder: JSONEncoder = JSONEncoder(), logger: Logger = Logger(label: "LambdaRuntime"), - body: @Sendable @escaping (Event, LambdaContext) async throws -> Output + body: sending @escaping (Event, LambdaContext) async throws -> Output ) where Handler == LambdaCodableAdapter< @@ -122,7 +122,7 @@ extension LambdaRuntime { public convenience init( decoder: JSONDecoder = JSONDecoder(), logger: Logger = Logger(label: "LambdaRuntime"), - body: @Sendable @escaping (Event, LambdaContext) async throws -> Void + body: sending @escaping (Event, LambdaContext) async throws -> Void ) where Handler == LambdaCodableAdapter< diff --git a/Sources/AWSLambdaRuntime/Lambda+Codable.swift b/Sources/AWSLambdaRuntime/Lambda+Codable.swift index 6aafa71f..abc8728b 100644 --- a/Sources/AWSLambdaRuntime/Lambda+Codable.swift +++ b/Sources/AWSLambdaRuntime/Lambda+Codable.swift @@ -16,7 +16,7 @@ import NIOCore /// The protocol a decoder must conform to so that it can be used with ``LambdaCodableAdapter`` to decode incoming /// `ByteBuffer` events. -public protocol LambdaEventDecoder: Sendable { +public protocol LambdaEventDecoder { /// Decode the `ByteBuffer` representing the received event into the generic `Event` type /// the handler will receive. /// - Parameters: @@ -28,7 +28,7 @@ public protocol LambdaEventDecoder: Sendable { /// The protocol an encoder must conform to so that it can be used with ``LambdaCodableAdapter`` to encode the generic /// ``LambdaOutputEncoder/Output`` object into a `ByteBuffer`. -public protocol LambdaOutputEncoder: Sendable { +public protocol LambdaOutputEncoder { associatedtype Output /// Encode the generic type `Output` the handler has returned into a `ByteBuffer`. @@ -52,7 +52,7 @@ public struct LambdaHandlerAdapter< Event: Decodable, Output, Handler: LambdaHandler ->: LambdaWithBackgroundProcessingHandler where Handler.Event == Event, Handler.Output == Output, Handler: Sendable { +>: LambdaWithBackgroundProcessingHandler where Handler.Event == Event, Handler.Output == Output { @usableFromInline let handler: Handler /// Initializes an instance given a concrete handler. @@ -86,15 +86,7 @@ public struct LambdaCodableAdapter< Output, Decoder: LambdaEventDecoder, Encoder: LambdaOutputEncoder ->: StreamingLambdaHandler -where - Handler.Event == Event, - Handler.Output == Output, - Encoder.Output == Output, - Handler: Sendable, - Decoder: Sendable, - Encoder: Sendable -{ +>: StreamingLambdaHandler where Handler.Event == Event, Handler.Output == Output, Encoder.Output == Output { @usableFromInline let handler: Handler @usableFromInline let encoder: Encoder @usableFromInline let decoder: Decoder diff --git a/Tests/AWSLambdaRuntimeTests/PoolTests.swift b/Tests/AWSLambdaRuntimeTests/PoolTests.swift index 1f312ff3..cfeea6a2 100644 --- a/Tests/AWSLambdaRuntimeTests/PoolTests.swift +++ b/Tests/AWSLambdaRuntimeTests/PoolTests.swift @@ -60,7 +60,7 @@ struct PoolTests { let iterations = 1000 // Start consumer task first - let consumer = Task { [iterations] in + let consumer = Task { @Sendable in var receivedValues = Set() var count = 0 for try await value in pool { @@ -119,7 +119,7 @@ struct PoolTests { let messagesPerProducer = 1000 // Start consumer - let consumer = Task { [producerCount, messagesPerProducer] in + let consumer = Task { @Sendable in var receivedValues = [Int]() var count = 0 for try await value in pool { From f1ab9f55c7c34a2fd890f1a3b512729be83b2835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Tue, 1 Jul 2025 23:45:36 +0200 Subject: [PATCH 4/8] fix ci --- .github/workflows/pull_request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 0b18dc33..4f8bb17a 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -32,7 +32,7 @@ jobs: with: name: "Integration tests" examples_enabled: true - matrix_linux_command: "LAMBDA_USE_LOCAL_DEPS=../.. swift build" + matrix_linux_command: "LAMBDA_USE_LOCAL_DEPS=.. swift build" # We pass the list of examples targets here, but we can't pass an array as argument # Instead, we pass a String with a valid JSON array. # The workaround is mentioned here https://github.com/orgs/community/discussions/11692 From a896700eff7075a1f2fb9ec9ce2f6a85df8d02d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Tue, 1 Jul 2025 23:47:37 +0200 Subject: [PATCH 5/8] swift-format --- Examples/Package.swift | 2 +- Examples/Testing/Tests/HandlerTests.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Examples/Package.swift b/Examples/Package.swift index c1c81149..5eaeaaef 100644 --- a/Examples/Package.swift +++ b/Examples/Package.swift @@ -165,7 +165,7 @@ let package = Package( .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime") ], path: "Tutorial/Sources" - ) + ), ] ) diff --git a/Examples/Testing/Tests/HandlerTests.swift b/Examples/Testing/Tests/HandlerTests.swift index 27fec766..343cf391 100644 --- a/Examples/Testing/Tests/HandlerTests.swift +++ b/Examples/Testing/Tests/HandlerTests.swift @@ -16,8 +16,8 @@ import AWSLambdaEvents import Logging import Testing -@testable import TestedLambda // to access the business code @testable import AWSLambdaRuntime // to access the LambdaContext +@testable import TestedLambda // to access the business code #if canImport(FoundationEssentials) import FoundationEssentials From 1f093b94c57d80e5efbd62646099022328a4e806 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Wed, 2 Jul 2025 00:01:40 +0200 Subject: [PATCH 6/8] fix ci --- .github/workflows/integration_tests.yml | 29 ++----------------- .github/workflows/pull_request.yml | 2 -- .../workflows/scripts/check-archive-plugin.sh | 4 +-- .../scripts/check-link-foundation.sh | 6 ++-- .../workflows/scripts/integration_tests.sh | 4 +-- 5 files changed, 8 insertions(+), 37 deletions(-) diff --git a/.github/workflows/integration_tests.yml b/.github/workflows/integration_tests.yml index 422ef82e..d59bb196 100644 --- a/.github/workflows/integration_tests.yml +++ b/.github/workflows/integration_tests.yml @@ -7,14 +7,6 @@ on: type: string description: "The name of the workflow used for the concurrency group." required: true - # We pass the list of examples here, but we can't pass an array as argument - # Instead, we pass a String with a valid JSON array. - # The workaround is mentioned here https://github.com/orgs/community/discussions/11692 - examples: - type: string - description: "The list of examples to run. Pass a String with a valid JSON array such as \"[ 'HelloWorld', 'APIGateway' ]\"" - required: true - default: "" examples_enabled: type: boolean description: "Boolean to enable the compilation of examples. Defaults to true." @@ -32,10 +24,6 @@ on: type: boolean description: "Boolean to enable the check for Foundation dependency. Defaults to true." default: true - matrix_linux_command: - type: string - description: "The command of the current Swift version linux matrix job to execute." - required: true matrix_linux_swift_container_image: type: string description: "Container image for the matrix job. Defaults to matching latest Swift 6.1 Amazon Linux 2 image." @@ -48,19 +36,9 @@ concurrency: jobs: test-examples: - name: Test Examples/${{ matrix.examples }} on ${{ matrix.swift.swift_version }} + name: Test Examples if: ${{ inputs.examples_enabled }} runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - examples: ${{ fromJson(inputs.examples) }} - - # We are using only one Swift version - swift: - - image: ${{ inputs.matrix_linux_swift_container_image }} - container: - image: ${{ matrix.swift.image }} steps: # GitHub checkout action has a dep on NodeJS 20 which is not running on Amazonlinux2 # workaround is to manually checkout the repository @@ -89,11 +67,8 @@ jobs: # https://github.com/actions/checkout/issues/766 run: git config --global --add safe.directory ${GITHUB_WORKSPACE} - - name: Run matrix job + - name: Run build for all examples working-directory: ${{ github.event.repository.name }} # until we can use action/checkout@v4 - env: - COMMAND: ${{ inputs.matrix_linux_command }} - EXAMPLE: ${{ matrix.examples }} run: | .github/workflows/scripts/integration_tests.sh diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 4f8bb17a..51439fb6 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -32,11 +32,9 @@ jobs: with: name: "Integration tests" examples_enabled: true - matrix_linux_command: "LAMBDA_USE_LOCAL_DEPS=.. swift build" # We pass the list of examples targets here, but we can't pass an array as argument # Instead, we pass a String with a valid JSON array. # The workaround is mentioned here https://github.com/orgs/community/discussions/11692 - examples: "[ 'APIGateway', 'APIGatewayLambda', 'AuthorizerLambda', 'BackgroundTasks', 'CDKAPIGAtewayLambda','HelloJSON', 'HelloWorld', 'ResourcesPackaging', 'S3EventNotifier', 'AWSSDKExample', 'SotoExample', 'StreamingNumbers', 'TestedLambda', 'Palindrome' ]" archive_plugin_examples: "[ 'HelloWorld', 'ResourcesPackaging' ]" archive_plugin_enabled: true diff --git a/.github/workflows/scripts/check-archive-plugin.sh b/.github/workflows/scripts/check-archive-plugin.sh index 218ee79a..8986fa63 100755 --- a/.github/workflows/scripts/check-archive-plugin.sh +++ b/.github/workflows/scripts/check-archive-plugin.sh @@ -23,10 +23,10 @@ OUTPUT_DIR=.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager OUTPUT_FILE=${OUTPUT_DIR}/MyLambda/bootstrap ZIP_FILE=${OUTPUT_DIR}/MyLambda/MyLambda.zip -pushd "Examples/${EXAMPLE}" || exit 1 +pushd "Examples" || exit 1 # package the example (docker and swift toolchain are installed on the GH runner) -LAMBDA_USE_LOCAL_DEPS=../.. swift package archive --allow-network-connections docker || exit 1 +LAMBDA_USE_LOCAL_DEPS=.. swift package archive --product "${EXAMPLE}" --allow-network-connections docker || exit 1 # did the plugin generated a Linux binary? [ -f "${OUTPUT_FILE}" ] diff --git a/.github/workflows/scripts/check-link-foundation.sh b/.github/workflows/scripts/check-link-foundation.sh index be84116c..87e5fae4 100755 --- a/.github/workflows/scripts/check-link-foundation.sh +++ b/.github/workflows/scripts/check-link-foundation.sh @@ -19,13 +19,13 @@ fatal() { error "$@"; exit 1; } EXAMPLE=APIGateway OUTPUT_DIR=.build/release -OUTPUT_FILE=${OUTPUT_DIR}/APIGatewayLambda +OUTPUT_FILE=${OUTPUT_DIR}/APIGateway LIBS_TO_CHECK="libFoundation.so libFoundationInternationalization.so lib_FoundationICU.so" -pushd Examples/${EXAMPLE} || fatal "Failed to change directory to Examples/${EXAMPLE}." +pushd Examples || fatal "Failed to change directory to Examples." # recompile the example without the --static-swift-stdlib flag -LAMBDA_USE_LOCAL_DEPS=../.. swift build -c release -Xlinker -s || fatal "Failed to build the example." +LAMBDA_USE_LOCAL_DEPS=.. swift build --target "${EXAMPLE}" -c release -Xlinker -s || fatal "Failed to build the example." # check if the binary exists if [ ! -f "${OUTPUT_FILE}" ]; then diff --git a/.github/workflows/scripts/integration_tests.sh b/.github/workflows/scripts/integration_tests.sh index dea6d7c0..cd936ea5 100755 --- a/.github/workflows/scripts/integration_tests.sh +++ b/.github/workflows/scripts/integration_tests.sh @@ -21,12 +21,10 @@ fatal() { error "$@"; exit 1; } SWIFT_VERSION=$(swift --version) test -n "${SWIFT_VERSION:-}" || fatal "SWIFT_VERSION unset" -test -n "${COMMAND:-}" || fatal "COMMAND unset" -test -n "${EXAMPLE:-}" || fatal "EXAMPLE unset" pushd Examples > /dev/null log "Running command with Swift $SWIFT_VERSION" -eval "$COMMAND --target $EXAMPLE" +eval "swift build && swift test" popd From 6134b03d52857423791fc830762396e1c75969b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Wed, 2 Jul 2025 00:22:56 +0200 Subject: [PATCH 7/8] fix test example for linux --- Examples/Testing/Tests/HandlerTests.swift | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Examples/Testing/Tests/HandlerTests.swift b/Examples/Testing/Tests/HandlerTests.swift index 343cf391..a9af1ce7 100644 --- a/Examples/Testing/Tests/HandlerTests.swift +++ b/Examples/Testing/Tests/HandlerTests.swift @@ -32,11 +32,9 @@ public struct HandlerTest { public func invokeHandler() async throws { // read event.json file - let testBundle = Bundle.module - guard let eventURL = testBundle.url(forResource: "event", withExtension: "json") else { - Issue.record("event.json not found in test bundle") - return - } + let eventURL = URL(fileURLWithPath: #filePath) + .deletingLastPathComponent() + .appendingPathComponent("event.json") let eventData = try Data(contentsOf: eventURL) // decode the event From 7280a2a7a3877a223a7834e38d159c679be45731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Wed, 2 Jul 2025 07:45:58 +0200 Subject: [PATCH 8/8] fix architve test script --- .../workflows/scripts/check-archive-plugin.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/scripts/check-archive-plugin.sh b/.github/workflows/scripts/check-archive-plugin.sh index 8986fa63..35835814 100755 --- a/.github/workflows/scripts/check-archive-plugin.sh +++ b/.github/workflows/scripts/check-archive-plugin.sh @@ -20,28 +20,30 @@ fatal() { error "$@"; exit 1; } test -n "${EXAMPLE:-}" || fatal "EXAMPLE unset" OUTPUT_DIR=.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager -OUTPUT_FILE=${OUTPUT_DIR}/MyLambda/bootstrap -ZIP_FILE=${OUTPUT_DIR}/MyLambda/MyLambda.zip pushd "Examples" || exit 1 # package the example (docker and swift toolchain are installed on the GH runner) LAMBDA_USE_LOCAL_DEPS=.. swift package archive --product "${EXAMPLE}" --allow-network-connections docker || exit 1 +# find the zip file in the OUTPUT_FILE directory +ZIP_FILE=$(find "${OUTPUT_DIR}" -type f -name "*.zip" | head -n 1) +OUTPUT_FILE=$(find "${OUTPUT_DIR}" -type f -name "bootstrap" | head -n 1) + # did the plugin generated a Linux binary? -[ -f "${OUTPUT_FILE}" ] -file "${OUTPUT_FILE}" | grep --silent ELF +[ -f "${OUTPUT_FILE}" ] || exit 1 +file "${OUTPUT_FILE}" | grep --silent ELF || exit 1 # did the plugin created a ZIP file? -[ -f "${ZIP_FILE}" ] +[ -f "${ZIP_FILE}" ] || exit 1 # does the ZIP file contain the bootstrap? -unzip -l "${ZIP_FILE}" | grep --silent bootstrap +unzip -l "${ZIP_FILE}" | grep --silent bootstrap || exit 1 # if EXAMPLE is ResourcesPackaging, check if the ZIP file contains hello.txt if [ "$EXAMPLE" == "ResourcesPackaging" ]; then echo "Checking if resource was added to the ZIP file" - unzip -l "${ZIP_FILE}" | grep --silent hello.txt + unzip -l "${ZIP_FILE}" | grep --silent hello.txt SUCCESS=$? if [ "$SUCCESS" -eq 1 ]; then log "❌ Resource not found." && exit 1