From cb2cddec138f1e7a4b7132a9ca8a5b9e96c56ad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Tue, 8 Oct 2024 14:51:49 +0200 Subject: [PATCH 01/33] fix typos on API GAteway example --- Examples/APIGateway/Package.swift | 4 ++-- Examples/APIGateway/README.md | 8 ++++---- Examples/APIGateway/template.yaml | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Examples/APIGateway/Package.swift b/Examples/APIGateway/Package.swift index a2df5b73..4390e055 100644 --- a/Examples/APIGateway/Package.swift +++ b/Examples/APIGateway/Package.swift @@ -16,7 +16,7 @@ let package = Package( name: "swift-aws-lambda-runtime-example", platforms: platforms, products: [ - .executable(name: "APIGAtewayLambda", targets: ["APIGAtewayLambda"]) + .executable(name: "APIGatewayLambda", targets: ["APIGatewayLambda"]) ], dependencies: [ // dependency on swift-aws-lambda-runtime is added dynamically below @@ -26,7 +26,7 @@ let package = Package( ], targets: [ .executableTarget( - name: "APIGAtewayLambda", + name: "APIGatewayLambda", dependencies: [ .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), .product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"), diff --git a/Examples/APIGateway/README.md b/Examples/APIGateway/README.md index f534f9ba..4a002b77 100644 --- a/Examples/APIGateway/README.md +++ b/Examples/APIGateway/README.md @@ -26,7 +26,7 @@ swift package archive --allow-network-access 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/APIGatewayLambda/APIGatewayLambda.zip` ## Deploy @@ -40,9 +40,9 @@ To actually deploy your Lambda function and create the infrastructure, type the ```bash sam deploy \ -----resolve-s3 \ +--resolve-s3 \ --template-file template.yaml \ ---stack-name MyLambda \ +--stack-name APIGAtewayLambda \ --capabilities CAPABILITY_IAM ``` @@ -54,7 +54,7 @@ The output is similar to this one. Outputs ----------------------------------------------------------------------------------------------------------------------------- Key APIGAtewayEndpoint -Description API Gateway endpoint UR" +Description API Gateway endpoint URL" Value https://a5q74es3k2.execute-api.us-east-1.amazonaws.com ----------------------------------------------------------------------------------------------------------------------------- ``` diff --git a/Examples/APIGateway/template.yaml b/Examples/APIGateway/template.yaml index 700c09b0..67c30562 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/APIGatewayLambda/APIGatewayLambda.zip Timeout: 60 Handler: swift.bootstrap Runtime: provided.al2 From bd07401475b7d595d1421d921a36a348bafd6948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Tue, 8 Oct 2024 15:48:09 +0200 Subject: [PATCH 02/33] add aws sdk example --- Examples/AWSSDK/.gitignore | 12 ++++ Examples/AWSSDK/Package.swift | 42 +++++++++++++ Examples/AWSSDK/README.md | 94 ++++++++++++++++++++++++++++++ Examples/AWSSDK/Sources/main.swift | 39 +++++++++++++ Examples/AWSSDK/template.yaml | 58 ++++++++++++++++++ 5 files changed, 245 insertions(+) create mode 100644 Examples/AWSSDK/.gitignore create mode 100644 Examples/AWSSDK/Package.swift create mode 100644 Examples/AWSSDK/README.md create mode 100644 Examples/AWSSDK/Sources/main.swift create mode 100644 Examples/AWSSDK/template.yaml diff --git a/Examples/AWSSDK/.gitignore b/Examples/AWSSDK/.gitignore new file mode 100644 index 00000000..70799e05 --- /dev/null +++ b/Examples/AWSSDK/.gitignore @@ -0,0 +1,12 @@ +.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/AWSSDK/Package.swift b/Examples/AWSSDK/Package.swift new file mode 100644 index 00000000..359b062d --- /dev/null +++ b/Examples/AWSSDK/Package.swift @@ -0,0 +1,42 @@ +// swift-tools-version: 6.0.0 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +//===----------------------------------------------------------------------===// +// +// This source file is part of the AWS Lambda Swift +// VSCode extension open source project. +// +// Copyright (c) 2024, the VSCode AWS Lambda Swift extension project authors. +// Licensed under Apache License v2.0. +// +// See LICENSE.txt for license information +// See CONTRIBUTORS.txt for the list of VSCode AWS Lambda Swift project authors +// +// SPDX-License-Identifier: Apache-2.0 +// +//===----------------------------------------------------------------------===// + +import PackageDescription + +let package = Package( + name: "aws-swift-app", + platforms: [.macOS(.v15)], + products: [ + .executable(name: "AWSSDKExample", targets: ["AWSSDKExample"]) + ], + dependencies: [ + .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime", branch: "main"), + .package(url: "https://github.com/swift-server/swift-aws-lambda-events", branch: "main"), + .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"), + ] + ) + ] +) diff --git a/Examples/AWSSDK/README.md b/Examples/AWSSDK/README.md new file mode 100644 index 00000000..5cead9fe --- /dev/null +++ b/Examples/AWSSDK/README.md @@ -0,0 +1,94 @@ +sam deploy \ +--resolve-s3 \ +--template-file template.yaml \ +--stack-name AWSSDKExample \ +--capabilities CAPABILITY_IAM + +# API Gateway + +This is a simple example of an AWS Lambda function that uses the [AWS SDK for Swift](https://github.com/awslabs/aws-sdk-swift) to read data from Amazon S3. + +## Code + +The Lambda function reads all bucket names from your AWS account and return them as a String. + +The code creates a `LambdaRuntime` struct. In it's simplest form, the initializer takes a function as argument. The function is the handler that will be invoked when the API Gateway receives an HTTP request. + +The handler is `(event: APIGatewayV2Request, context: LambdaContext) -> APIGatewayV2Response`. The function takes two arguments: +- the event argument is a `APIGatewayV2Request`. It is the parameter passed by the API Gateway. It contains all data passed in the HTTP request and some meta data. +- the context argument is a `Lambda Context`. It is a description of the runtime context. + +The function must return a `APIGatewayV2Response`. + +`APIGatewayV2Request` and `APIGatewayV2Response` are defined in the [Swift AWS Lambda Events](https://github.com/swift-server/swift-aws-lambda-events) library. + +The handler creates an S3 client and `ListBucketsInput` object. It passes the input object to the client and receives an output response. +It then extract the list of bucket names from the output to create a `\n` separated list of names, as a `String` + +## Build & Package + +To build the package, type the following commands. + +```bash +swift build +swift package archive --allow-network-access 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/AWSSDKExample/AWSSDKExample.zip` + +## Deploy + +The deployment must include the Lambda function and an API Gateway. We use the [Serverless Application Model (SAM)](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html) to deploy the infrastructure. + +**Prerequisites** : Install the [SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html) + +The example directory contains a file named `template.yaml` that describes the deployment. + +To actually deploy your Lambda function and create the infrastructure, type the following `sam` command. + +```bash +sam deploy \ +--resolve-s3 \ +--template-file template.yaml \ +--stack-name AWSSDKExample \ +--capabilities CAPABILITY_IAM +``` + +At the end of the deployment, the script lists the API Gateway endpoint. +The output is similar to this one. + +``` +----------------------------------------------------------------------------------------------------------------------------- +Outputs +----------------------------------------------------------------------------------------------------------------------------- +Key APIGAtewayEndpoint +Description API Gateway endpoint URL" +Value https://a5q74es3k2.execute-api.us-east-1.amazonaws.com +----------------------------------------------------------------------------------------------------------------------------- +``` + +## Invoke your Lambda function + +To invoke the Lambda function, use this `curl` command line. + +```bash +curl https://a5q74es3k2.execute-api.us-east-1.amazonaws.com +``` + +Be sure to replace the URL with the API Gateway endpoint returned in the previous step. + +This should print text similar to + +```bash +my_bucket_1 +my_bucket_2 +``` + +## Undeploy + +When done testing, you can delete the infrastructure with this command. + +```bash +sam delete +``` \ No newline at end of file diff --git a/Examples/AWSSDK/Sources/main.swift b/Examples/AWSSDK/Sources/main.swift new file mode 100644 index 00000000..ebe7e962 --- /dev/null +++ b/Examples/AWSSDK/Sources/main.swift @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the SwiftAWSLambdaRuntime open source project +// +// Copyright (c) 2024 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 AWSLambdaEvents + +import AWSS3 + + +func handler(event: APIGatewayV2Request, context: LambdaContext) async throws -> APIGatewayV2Response { + + var response: APIGatewayV2Response + do { + // read the list of buckets + context.logger.debug("Reading list of buckets") + let client = try await S3Client() + let output = try await client.listBuckets(input: ListBucketsInput()) + let bucketList = output.buckets?.compactMap { $0.name } + response = APIGatewayV2Response(statusCode: .ok, body: bucketList?.joined(separator: "\n")) + } catch { + context.logger.error("\(error)") + response = APIGatewayV2Response(statusCode: .internalServerError, body: "[ERROR] \(error)") + } + return response +} + +let runtime = LambdaRuntime.init(body: handler) +try await runtime.run() diff --git a/Examples/AWSSDK/template.yaml b/Examples/AWSSDK/template.yaml new file mode 100644 index 00000000..4bda38fe --- /dev/null +++ b/Examples/AWSSDK/template.yaml @@ -0,0 +1,58 @@ +#===----------------------------------------------------------------------===// +# +# This source file is part of the AWS Lambda Swift +# VSCode extension open source project. +# +# Copyright (c) 2024, the VSCode AWS Lambda Swift extension project authors. +# Licensed under Apache License v2.0. +# +# See LICENSE.txt for license information +# See CONTRIBUTORS.txt for the list of VSCode AWS Lambda Swift project authors +# +# SPDX-License-Identifier: Apache-2.0 +# +#===----------------------------------------------------------------------===// + +AWSTemplateFormatVersion: '2010-09-09' +Transform: AWS::Serverless-2016-10-31 +Description: SAM Template for AWS SDK Example + +Resources: + # Lambda function + AWSSDKExample: + Type: AWS::Serverless::Function + Properties: + CodeUri: .build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/AWSSDKExample/AWSSDKExample.zip + Timeout: 60 + Handler: swift.bootstrap + Runtime: provided.al2 + MemorySize: 512 + Architectures: + - arm64 + Environment: + Variables: + # by default, AWS Lambda runtime produces no log + # use `LOG_LEVEL: debug` for for lifecycle and event handling information + # use `LOG_LEVEL: trace` for detailed input event information + LOG_LEVEL: trace + + # Handles all methods of the REST API + Events: + Api: + Type: HttpApi + + # Add an IAM policy to this function. + # It grants the function permissions to read the list of buckets in your account. + Policies: + - Statement: + - Sid: ListAllS3BucketsInYourAccount + Effect: Allow + Action: + - s3:ListAllMyBuckets + Resource: '*' + +# print API endpoint +Outputs: + SwiftAPIEndpoint: + Description: "API Gateway endpoint URL for your application" + Value: !Sub "https://${ServerlessHttpApi}.execute-api.${AWS::Region}.amazonaws.com" From 570b41697794121fc5fe2644577e6ac6015d97d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Tue, 8 Oct 2024 17:48:31 +0200 Subject: [PATCH 03/33] adjust for local CI --- Examples/AWSSDK/Package.swift | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/Examples/AWSSDK/Package.swift b/Examples/AWSSDK/Package.swift index 359b062d..6b9562d7 100644 --- a/Examples/AWSSDK/Package.swift +++ b/Examples/AWSSDK/Package.swift @@ -18,14 +18,25 @@ import PackageDescription +// needed for CI to test the local version of the library +import class Foundation.ProcessInfo +import struct Foundation.URL + +#if os(macOS) +let platforms: [PackageDescription.SupportedPlatform]? = [.macOS(.v15)] +#else +let platforms: [PackageDescription.SupportedPlatform]? = nil +#endif + let package = Package( - name: "aws-swift-app", - platforms: [.macOS(.v15)], + name: "AWSSDKExample", + platforms: platforms, products: [ .executable(name: "AWSSDKExample", targets: ["AWSSDKExample"]) ], dependencies: [ - .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime", branch: "main"), + // dependency on 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/awslabs/aws-sdk-swift", from: "1.0.0") ], @@ -40,3 +51,21 @@ let package = Package( ) ] ) + +if let localDepsPath = ProcessInfo.processInfo.environment["LAMBDA_USE_LOCAL_DEPS"], + localDepsPath != "", + let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), + let _ = v.isDirectory +{ + print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)") + package.dependencies += [ + .package(name: "swift-aws-lambda-runtime", path: localDepsPath) + ] + +} else { + print("[INFO] LAMBDA_USE_LOCAL_DEPS is not pointing to your local swift-aws-lambda-runtime code") + print("[INFO] This project will compile against the main branch of the Lambda Runtime on GitHub") + package.dependencies += [ + .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main") + ] +} From 5e8082454476eb40302da8aacf9ffeb7a7767059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Tue, 8 Oct 2024 17:48:45 +0200 Subject: [PATCH 04/33] add soto example --- Examples/Soto/.gitignore | 12 ++++ Examples/Soto/Package.swift | 73 +++++++++++++++++++++++++ Examples/Soto/README.md | 94 ++++++++++++++++++++++++++++++++ Examples/Soto/Sources/main.swift | 41 ++++++++++++++ Examples/Soto/template.yaml | 58 ++++++++++++++++++++ 5 files changed, 278 insertions(+) create mode 100644 Examples/Soto/.gitignore create mode 100644 Examples/Soto/Package.swift create mode 100644 Examples/Soto/README.md create mode 100644 Examples/Soto/Sources/main.swift create mode 100644 Examples/Soto/template.yaml diff --git a/Examples/Soto/.gitignore b/Examples/Soto/.gitignore new file mode 100644 index 00000000..70799e05 --- /dev/null +++ b/Examples/Soto/.gitignore @@ -0,0 +1,12 @@ +.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/Soto/Package.swift b/Examples/Soto/Package.swift new file mode 100644 index 00000000..0af1a267 --- /dev/null +++ b/Examples/Soto/Package.swift @@ -0,0 +1,73 @@ +// swift-tools-version: 6.0 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +//===----------------------------------------------------------------------===// +// +// This source file is part of the AWS Lambda Swift +// VSCode extension open source project. +// +// Copyright (c) 2024, the VSCode AWS Lambda Swift extension project authors. +// Licensed under Apache License v2.0. +// +// See LICENSE.txt for license information +// See CONTRIBUTORS.txt for the list of VSCode AWS Lambda Swift project authors +// +// SPDX-License-Identifier: Apache-2.0 +// +//===----------------------------------------------------------------------===// + +import PackageDescription + +// needed for CI to test the local version of the library +import class Foundation.ProcessInfo +import struct Foundation.URL + +#if os(macOS) +let platforms: [PackageDescription.SupportedPlatform]? = [.macOS(.v15)] +#else +let platforms: [PackageDescription.SupportedPlatform]? = nil +#endif + + +let package = Package( + name: "SotoLambdaExample", + platforms: platforms, + products: [ + .executable(name: "SotoLambdaExample", targets: ["SotoExample"]) + ], + dependencies: [ + .package(url: "https://github.com/soto-project/soto.git", from: "7.0.0"), + + // dependency on 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") + ], + targets: [ + .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"), + ] + ) + ] +) + +if let localDepsPath = ProcessInfo.processInfo.environment["LAMBDA_USE_LOCAL_DEPS"], + localDepsPath != "", + let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), + let _ = v.isDirectory +{ + print("[INFO] Compiling against swift-aws-lambda-runtime located at \(localDepsPath)") + package.dependencies += [ + .package(name: "swift-aws-lambda-runtime", path: localDepsPath) + ] + +} else { + print("[INFO] LAMBDA_USE_LOCAL_DEPS is not pointing to your local swift-aws-lambda-runtime code") + print("[INFO] This project will compile against the main branch of the Lambda Runtime on GitHub") + package.dependencies += [ + .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main") + ] +} \ No newline at end of file diff --git a/Examples/Soto/README.md b/Examples/Soto/README.md new file mode 100644 index 00000000..5cead9fe --- /dev/null +++ b/Examples/Soto/README.md @@ -0,0 +1,94 @@ +sam deploy \ +--resolve-s3 \ +--template-file template.yaml \ +--stack-name AWSSDKExample \ +--capabilities CAPABILITY_IAM + +# API Gateway + +This is a simple example of an AWS Lambda function that uses the [AWS SDK for Swift](https://github.com/awslabs/aws-sdk-swift) to read data from Amazon S3. + +## Code + +The Lambda function reads all bucket names from your AWS account and return them as a String. + +The code creates a `LambdaRuntime` struct. In it's simplest form, the initializer takes a function as argument. The function is the handler that will be invoked when the API Gateway receives an HTTP request. + +The handler is `(event: APIGatewayV2Request, context: LambdaContext) -> APIGatewayV2Response`. The function takes two arguments: +- the event argument is a `APIGatewayV2Request`. It is the parameter passed by the API Gateway. It contains all data passed in the HTTP request and some meta data. +- the context argument is a `Lambda Context`. It is a description of the runtime context. + +The function must return a `APIGatewayV2Response`. + +`APIGatewayV2Request` and `APIGatewayV2Response` are defined in the [Swift AWS Lambda Events](https://github.com/swift-server/swift-aws-lambda-events) library. + +The handler creates an S3 client and `ListBucketsInput` object. It passes the input object to the client and receives an output response. +It then extract the list of bucket names from the output to create a `\n` separated list of names, as a `String` + +## Build & Package + +To build the package, type the following commands. + +```bash +swift build +swift package archive --allow-network-access 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/AWSSDKExample/AWSSDKExample.zip` + +## Deploy + +The deployment must include the Lambda function and an API Gateway. We use the [Serverless Application Model (SAM)](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html) to deploy the infrastructure. + +**Prerequisites** : Install the [SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html) + +The example directory contains a file named `template.yaml` that describes the deployment. + +To actually deploy your Lambda function and create the infrastructure, type the following `sam` command. + +```bash +sam deploy \ +--resolve-s3 \ +--template-file template.yaml \ +--stack-name AWSSDKExample \ +--capabilities CAPABILITY_IAM +``` + +At the end of the deployment, the script lists the API Gateway endpoint. +The output is similar to this one. + +``` +----------------------------------------------------------------------------------------------------------------------------- +Outputs +----------------------------------------------------------------------------------------------------------------------------- +Key APIGAtewayEndpoint +Description API Gateway endpoint URL" +Value https://a5q74es3k2.execute-api.us-east-1.amazonaws.com +----------------------------------------------------------------------------------------------------------------------------- +``` + +## Invoke your Lambda function + +To invoke the Lambda function, use this `curl` command line. + +```bash +curl https://a5q74es3k2.execute-api.us-east-1.amazonaws.com +``` + +Be sure to replace the URL with the API Gateway endpoint returned in the previous step. + +This should print text similar to + +```bash +my_bucket_1 +my_bucket_2 +``` + +## Undeploy + +When done testing, you can delete the infrastructure with this command. + +```bash +sam delete +``` \ No newline at end of file diff --git a/Examples/Soto/Sources/main.swift b/Examples/Soto/Sources/main.swift new file mode 100644 index 00000000..f42361ab --- /dev/null +++ b/Examples/Soto/Sources/main.swift @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the SwiftAWSLambdaRuntime open source project +// +// Copyright (c) 2024 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 AWSLambdaEvents + +import SotoS3 + +let client = AWSClient() +let s3 = S3(client: client, region: .useast1) + +func handler(event: APIGatewayV2Request, context: LambdaContext) async throws -> APIGatewayV2Response { + + var response: APIGatewayV2Response + do { + context.logger.debug("Reading list of buckets") + + // read the list of buckets + let bucketResponse = try await s3.listBuckets() + let bucketList = bucketResponse.buckets?.compactMap { $0.name } + response = APIGatewayV2Response(statusCode: .ok, body: bucketList?.joined(separator: "\n")) + } catch { + context.logger.error("\(error)") + response = APIGatewayV2Response(statusCode: .internalServerError, body: "[ERROR] \(error)") + } + return response +} + +let runtime = LambdaRuntime.init(body: handler) +try await runtime.run() diff --git a/Examples/Soto/template.yaml b/Examples/Soto/template.yaml new file mode 100644 index 00000000..85b91540 --- /dev/null +++ b/Examples/Soto/template.yaml @@ -0,0 +1,58 @@ +#===----------------------------------------------------------------------===// +# +# This source file is part of the AWS Lambda Swift +# VSCode extension open source project. +# +# Copyright (c) 2024, the VSCode AWS Lambda Swift extension project authors. +# Licensed under Apache License v2.0. +# +# See LICENSE.txt for license information +# See CONTRIBUTORS.txt for the list of VSCode AWS Lambda Swift project authors +# +# SPDX-License-Identifier: Apache-2.0 +# +#===----------------------------------------------------------------------===// + +AWSTemplateFormatVersion: '2010-09-09' +Transform: AWS::Serverless-2016-10-31 +Description: SAM Template for AWS SDK Example + +Resources: + # Lambda function + SotoExample: + Type: AWS::Serverless::Function + Properties: + CodeUri: .build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/SotoExample/SotoExample.zip + Timeout: 60 + Handler: swift.bootstrap + Runtime: provided.al2 + MemorySize: 512 + Architectures: + - arm64 + Environment: + Variables: + # by default, AWS Lambda runtime produces no log + # use `LOG_LEVEL: debug` for for lifecycle and event handling information + # use `LOG_LEVEL: trace` for detailed input event information + LOG_LEVEL: trace + + # Handles all methods of the REST API + Events: + Api: + Type: HttpApi + + # Add an IAM policy to this function. + # It grants the function permissions to read the list of buckets in your account. + Policies: + - Statement: + - Sid: ListAllS3BucketsInYourAccount + Effect: Allow + Action: + - s3:ListAllMyBuckets + Resource: '*' + +# print API endpoint +Outputs: + SwiftAPIEndpoint: + Description: "API Gateway endpoint URL for your application" + Value: !Sub "https://${ServerlessHttpApi}.execute-api.${AWS::Region}.amazonaws.com" From c75c9999621e7450fd37cfc635b8431541802bd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Tue, 8 Oct 2024 17:52:29 +0200 Subject: [PATCH 05/33] update soto example readme --- Examples/Soto/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Examples/Soto/README.md b/Examples/Soto/README.md index 5cead9fe..e32beffc 100644 --- a/Examples/Soto/README.md +++ b/Examples/Soto/README.md @@ -6,7 +6,7 @@ sam deploy \ # API Gateway -This is a simple example of an AWS Lambda function that uses the [AWS SDK for Swift](https://github.com/awslabs/aws-sdk-swift) to read data from Amazon S3. +This is a simple example of an AWS Lambda function that uses the [Soto SDK for AWS](https://github.com/soto-project/soto) to read data from Amazon S3. ## Code @@ -22,7 +22,7 @@ The function must return a `APIGatewayV2Response`. `APIGatewayV2Request` and `APIGatewayV2Response` are defined in the [Swift AWS Lambda Events](https://github.com/swift-server/swift-aws-lambda-events) library. -The handler creates an S3 client and `ListBucketsInput` object. It passes the input object to the client and receives an output response. +The handler creates AWS and S3 clients. It then calls `listBuckets()` on the S3 client and receives an output response. It then extract the list of bucket names from the output to create a `\n` separated list of names, as a `String` ## Build & Package @@ -35,7 +35,7 @@ swift package archive --allow-network-access 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/AWSSDKExample/AWSSDKExample.zip` +The ZIP file is located at `.build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/SotoExample/SotoExample.zip` ## Deploy @@ -51,7 +51,7 @@ To actually deploy your Lambda function and create the infrastructure, type the sam deploy \ --resolve-s3 \ --template-file template.yaml \ ---stack-name AWSSDKExample \ +--stack-name SotoExample \ --capabilities CAPABILITY_IAM ``` From b5457381bb818878963f7176e67ed1c4285b389f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Tue, 8 Oct 2024 19:46:09 +0200 Subject: [PATCH 06/33] format --- Examples/AWSSDK/Sources/main.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Examples/AWSSDK/Sources/main.swift b/Examples/AWSSDK/Sources/main.swift index ebe7e962..33910a72 100644 --- a/Examples/AWSSDK/Sources/main.swift +++ b/Examples/AWSSDK/Sources/main.swift @@ -17,7 +17,6 @@ import AWSLambdaEvents import AWSS3 - func handler(event: APIGatewayV2Request, context: LambdaContext) async throws -> APIGatewayV2Response { var response: APIGatewayV2Response From 6bf8f0f2d938e7874faf975524529f2c38027903 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Tue, 8 Oct 2024 19:47:10 +0200 Subject: [PATCH 07/33] swift format --- Examples/AWSSDK/Package.swift | 10 +++++----- Examples/AWSSDK/Sources/main.swift | 5 ++--- Examples/Soto/Package.swift | 13 ++++++------- Examples/Soto/Sources/main.swift | 7 +++---- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/Examples/AWSSDK/Package.swift b/Examples/AWSSDK/Package.swift index 6b9562d7..1e43da0a 100644 --- a/Examples/AWSSDK/Package.swift +++ b/Examples/AWSSDK/Package.swift @@ -3,7 +3,7 @@ //===----------------------------------------------------------------------===// // -// This source file is part of the AWS Lambda Swift +// This source file is part of the AWS Lambda Swift // VSCode extension open source project. // // Copyright (c) 2024, the VSCode AWS Lambda Swift extension project authors. @@ -38,15 +38,15 @@ let package = Package( // dependency on 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/awslabs/aws-sdk-swift", 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"), + .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), + .product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"), + .product(name: "AWSS3", package: "aws-sdk-swift"), ] ) ] diff --git a/Examples/AWSSDK/Sources/main.swift b/Examples/AWSSDK/Sources/main.swift index 33910a72..6ac380dc 100644 --- a/Examples/AWSSDK/Sources/main.swift +++ b/Examples/AWSSDK/Sources/main.swift @@ -12,16 +12,15 @@ // //===----------------------------------------------------------------------===// -import AWSLambdaRuntime import AWSLambdaEvents - +import AWSLambdaRuntime import AWSS3 func handler(event: APIGatewayV2Request, context: LambdaContext) async throws -> APIGatewayV2Response { var response: APIGatewayV2Response do { - // read the list of buckets + // read the list of buckets context.logger.debug("Reading list of buckets") let client = try await S3Client() let output = try await client.listBuckets(input: ListBucketsInput()) diff --git a/Examples/Soto/Package.swift b/Examples/Soto/Package.swift index 0af1a267..0ba9db8b 100644 --- a/Examples/Soto/Package.swift +++ b/Examples/Soto/Package.swift @@ -3,7 +3,7 @@ //===----------------------------------------------------------------------===// // -// This source file is part of the AWS Lambda Swift +// This source file is part of the AWS Lambda Swift // VSCode extension open source project. // // Copyright (c) 2024, the VSCode AWS Lambda Swift extension project authors. @@ -28,7 +28,6 @@ let platforms: [PackageDescription.SupportedPlatform]? = [.macOS(.v15)] let platforms: [PackageDescription.SupportedPlatform]? = nil #endif - let package = Package( name: "SotoLambdaExample", platforms: platforms, @@ -37,18 +36,18 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/soto-project/soto.git", from: "7.0.0"), - + // dependency on 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", branch: "main"), ], targets: [ .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"), + .product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"), + .product(name: "AWSLambdaEvents", package: "swift-aws-lambda-events"), ] ) ] @@ -70,4 +69,4 @@ if let localDepsPath = ProcessInfo.processInfo.environment["LAMBDA_USE_LOCAL_DEP package.dependencies += [ .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main") ] -} \ No newline at end of file +} diff --git a/Examples/Soto/Sources/main.swift b/Examples/Soto/Sources/main.swift index f42361ab..a98fd6e7 100644 --- a/Examples/Soto/Sources/main.swift +++ b/Examples/Soto/Sources/main.swift @@ -12,9 +12,8 @@ // //===----------------------------------------------------------------------===// -import AWSLambdaRuntime import AWSLambdaEvents - +import AWSLambdaRuntime import SotoS3 let client = AWSClient() @@ -25,8 +24,8 @@ func handler(event: APIGatewayV2Request, context: LambdaContext) async throws -> var response: APIGatewayV2Response do { context.logger.debug("Reading list of buckets") - - // read the list of buckets + + // read the list of buckets let bucketResponse = try await s3.listBuckets() let bucketList = bucketResponse.buckets?.compactMap { $0.name } response = APIGatewayV2Response(statusCode: .ok, body: bucketList?.joined(separator: "\n")) From 77b0c8679425e2565905ca8cd5aaf1fdc4fccffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Tue, 8 Oct 2024 21:41:05 +0200 Subject: [PATCH 08/33] fix uppercase A --- Examples/APIGateway/README.md | 4 ++-- Examples/APIGateway/template.yaml | 4 ++-- Examples/AWSSDK/README.md | 8 +------- Examples/Soto/README.md | 2 +- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/Examples/APIGateway/README.md b/Examples/APIGateway/README.md index 4a002b77..be4c8b8c 100644 --- a/Examples/APIGateway/README.md +++ b/Examples/APIGateway/README.md @@ -42,7 +42,7 @@ To actually deploy your Lambda function and create the infrastructure, type the sam deploy \ --resolve-s3 \ --template-file template.yaml \ ---stack-name APIGAtewayLambda \ +--stack-name APIGatewayLambda \ --capabilities CAPABILITY_IAM ``` @@ -53,7 +53,7 @@ The output is similar to this one. ----------------------------------------------------------------------------------------------------------------------------- Outputs ----------------------------------------------------------------------------------------------------------------------------- -Key APIGAtewayEndpoint +Key APIGatewayEndpoint Description API Gateway endpoint URL" Value https://a5q74es3k2.execute-api.us-east-1.amazonaws.com ----------------------------------------------------------------------------------------------------------------------------- diff --git a/Examples/APIGateway/template.yaml b/Examples/APIGateway/template.yaml index 67c30562..3388be16 100644 --- a/Examples/APIGateway/template.yaml +++ b/Examples/APIGateway/template.yaml @@ -4,7 +4,7 @@ Description: SAM Template for QuoteService Resources: # Lambda function - APIGAtewayLambda: + APIGatewayLambda: Type: AWS::Serverless::Function Properties: CodeUri: .build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/APIGatewayLambda/APIGatewayLambda.zip @@ -26,6 +26,6 @@ Resources: Outputs: # print API Gateway endpoint - APIGAtewayEndpoint: + APIGatewayEndpoint: Description: API Gateway endpoint UR" Value: !Sub "https://${ServerlessHttpApi}.execute-api.${AWS::Region}.amazonaws.com" diff --git a/Examples/AWSSDK/README.md b/Examples/AWSSDK/README.md index 5cead9fe..0a1cf75b 100644 --- a/Examples/AWSSDK/README.md +++ b/Examples/AWSSDK/README.md @@ -1,9 +1,3 @@ -sam deploy \ ---resolve-s3 \ ---template-file template.yaml \ ---stack-name AWSSDKExample \ ---capabilities CAPABILITY_IAM - # API Gateway This is a simple example of an AWS Lambda function that uses the [AWS SDK for Swift](https://github.com/awslabs/aws-sdk-swift) to read data from Amazon S3. @@ -62,7 +56,7 @@ The output is similar to this one. ----------------------------------------------------------------------------------------------------------------------------- Outputs ----------------------------------------------------------------------------------------------------------------------------- -Key APIGAtewayEndpoint +Key APIGatewayEndpoint Description API Gateway endpoint URL" Value https://a5q74es3k2.execute-api.us-east-1.amazonaws.com ----------------------------------------------------------------------------------------------------------------------------- diff --git a/Examples/Soto/README.md b/Examples/Soto/README.md index e32beffc..488fd48b 100644 --- a/Examples/Soto/README.md +++ b/Examples/Soto/README.md @@ -62,7 +62,7 @@ The output is similar to this one. ----------------------------------------------------------------------------------------------------------------------------- Outputs ----------------------------------------------------------------------------------------------------------------------------- -Key APIGAtewayEndpoint +Key APIGatewayEndpoint Description API Gateway endpoint URL" Value https://a5q74es3k2.execute-api.us-east-1.amazonaws.com ----------------------------------------------------------------------------------------------------------------------------- From 83446a8a60767a61287d1c4d746caac001ede271 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Tue, 8 Oct 2024 21:41:42 +0200 Subject: [PATCH 09/33] remove unnecessary license header file --- Examples/AWSSDK/Package.swift | 18 +----------------- Examples/AWSSDK/template.yaml | 15 --------------- 2 files changed, 1 insertion(+), 32 deletions(-) diff --git a/Examples/AWSSDK/Package.swift b/Examples/AWSSDK/Package.swift index 1e43da0a..aef7d90d 100644 --- a/Examples/AWSSDK/Package.swift +++ b/Examples/AWSSDK/Package.swift @@ -1,20 +1,4 @@ -// swift-tools-version: 6.0.0 -// The swift-tools-version declares the minimum version of Swift required to build this package. - -//===----------------------------------------------------------------------===// -// -// This source file is part of the AWS Lambda Swift -// VSCode extension open source project. -// -// Copyright (c) 2024, the VSCode AWS Lambda Swift extension project authors. -// Licensed under Apache License v2.0. -// -// See LICENSE.txt for license information -// See CONTRIBUTORS.txt for the list of VSCode AWS Lambda Swift project authors -// -// SPDX-License-Identifier: Apache-2.0 -// -//===----------------------------------------------------------------------===// +// swift-tools-version: 6.0 import PackageDescription diff --git a/Examples/AWSSDK/template.yaml b/Examples/AWSSDK/template.yaml index 4bda38fe..7499ae40 100644 --- a/Examples/AWSSDK/template.yaml +++ b/Examples/AWSSDK/template.yaml @@ -1,18 +1,3 @@ -#===----------------------------------------------------------------------===// -# -# This source file is part of the AWS Lambda Swift -# VSCode extension open source project. -# -# Copyright (c) 2024, the VSCode AWS Lambda Swift extension project authors. -# Licensed under Apache License v2.0. -# -# See LICENSE.txt for license information -# See CONTRIBUTORS.txt for the list of VSCode AWS Lambda Swift project authors -# -# SPDX-License-Identifier: Apache-2.0 -# -#===----------------------------------------------------------------------===// - AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: SAM Template for AWS SDK Example From 1030816ee1063982b1a8b78f32038ddeb8bb709d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Tue, 8 Oct 2024 21:42:09 +0200 Subject: [PATCH 10/33] use trailing closure syntax + reuse S3 client --- Examples/AWSSDK/Sources/main.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Examples/AWSSDK/Sources/main.swift b/Examples/AWSSDK/Sources/main.swift index 6ac380dc..b4616c0e 100644 --- a/Examples/AWSSDK/Sources/main.swift +++ b/Examples/AWSSDK/Sources/main.swift @@ -14,15 +14,16 @@ import AWSLambdaEvents import AWSLambdaRuntime -import AWSS3 -func handler(event: APIGatewayV2Request, context: LambdaContext) async throws -> APIGatewayV2Response { +@preconcurrency import AWSS3 +let client = try await S3Client() + +let runtime = LambdaRuntime.init { (event: APIGatewayV2Request, context: LambdaContext) async throws -> APIGatewayV2Response in var response: APIGatewayV2Response do { // read the list of buckets context.logger.debug("Reading list of buckets") - let client = try await S3Client() let output = try await client.listBuckets(input: ListBucketsInput()) let bucketList = output.buckets?.compactMap { $0.name } response = APIGatewayV2Response(statusCode: .ok, body: bucketList?.joined(separator: "\n")) @@ -33,5 +34,4 @@ func handler(event: APIGatewayV2Request, context: LambdaContext) async throws -> return response } -let runtime = LambdaRuntime.init(body: handler) try await runtime.run() From ba1f39d03d71aae4be7e9cc375c2d7ba6a87bb1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Tue, 8 Oct 2024 21:42:52 +0200 Subject: [PATCH 11/33] remove unnecessary license header --- Examples/Soto/Package.swift | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/Examples/Soto/Package.swift b/Examples/Soto/Package.swift index 0ba9db8b..d0e43238 100644 --- a/Examples/Soto/Package.swift +++ b/Examples/Soto/Package.swift @@ -1,20 +1,4 @@ // swift-tools-version: 6.0 -// The swift-tools-version declares the minimum version of Swift required to build this package. - -//===----------------------------------------------------------------------===// -// -// This source file is part of the AWS Lambda Swift -// VSCode extension open source project. -// -// Copyright (c) 2024, the VSCode AWS Lambda Swift extension project authors. -// Licensed under Apache License v2.0. -// -// See LICENSE.txt for license information -// See CONTRIBUTORS.txt for the list of VSCode AWS Lambda Swift project authors -// -// SPDX-License-Identifier: Apache-2.0 -// -//===----------------------------------------------------------------------===// import PackageDescription From 33202cdf61b9c4d91138996acb55b2a83c2e11a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Tue, 8 Oct 2024 21:46:35 +0200 Subject: [PATCH 12/33] remove condition on Linux for platform --- Examples/APIGateway/Package.swift | 8 +------- Examples/AWSSDK/Package.swift | 8 +------- Examples/HelloWorld/Package.swift | 8 +------- Examples/Soto/Package.swift | 8 +------- 4 files changed, 4 insertions(+), 28 deletions(-) diff --git a/Examples/APIGateway/Package.swift b/Examples/APIGateway/Package.swift index 4390e055..94a8fada 100644 --- a/Examples/APIGateway/Package.swift +++ b/Examples/APIGateway/Package.swift @@ -6,15 +6,9 @@ import PackageDescription import class Foundation.ProcessInfo 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: "APIGatewayLambda", targets: ["APIGatewayLambda"]) ], diff --git a/Examples/AWSSDK/Package.swift b/Examples/AWSSDK/Package.swift index aef7d90d..ed01c437 100644 --- a/Examples/AWSSDK/Package.swift +++ b/Examples/AWSSDK/Package.swift @@ -6,15 +6,9 @@ import PackageDescription import class Foundation.ProcessInfo import struct Foundation.URL -#if os(macOS) -let platforms: [PackageDescription.SupportedPlatform]? = [.macOS(.v15)] -#else -let platforms: [PackageDescription.SupportedPlatform]? = nil -#endif - let package = Package( name: "AWSSDKExample", - platforms: platforms, + platforms: [.macOS(.v15)], products: [ .executable(name: "AWSSDKExample", targets: ["AWSSDKExample"]) ], diff --git a/Examples/HelloWorld/Package.swift b/Examples/HelloWorld/Package.swift index 6468fb88..597bfe3f 100644 --- a/Examples/HelloWorld/Package.swift +++ b/Examples/HelloWorld/Package.swift @@ -6,15 +6,9 @@ import PackageDescription import class Foundation.ProcessInfo 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: "MyLambda", targets: ["MyLambda"]) ], diff --git a/Examples/Soto/Package.swift b/Examples/Soto/Package.swift index d0e43238..e3d0f541 100644 --- a/Examples/Soto/Package.swift +++ b/Examples/Soto/Package.swift @@ -6,15 +6,9 @@ import PackageDescription import class Foundation.ProcessInfo import struct Foundation.URL -#if os(macOS) -let platforms: [PackageDescription.SupportedPlatform]? = [.macOS(.v15)] -#else -let platforms: [PackageDescription.SupportedPlatform]? = nil -#endif - let package = Package( name: "SotoLambdaExample", - platforms: platforms, + platforms: [.macOS(.v15)], products: [ .executable(name: "SotoLambdaExample", targets: ["SotoExample"]) ], From 46e5337e6a0f72e2c0a24cb288b921d7a3687f3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Tue, 8 Oct 2024 22:11:03 +0200 Subject: [PATCH 13/33] swift format --- Examples/AWSSDK/Sources/main.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Examples/AWSSDK/Sources/main.swift b/Examples/AWSSDK/Sources/main.swift index b4616c0e..3f50b7f8 100644 --- a/Examples/AWSSDK/Sources/main.swift +++ b/Examples/AWSSDK/Sources/main.swift @@ -14,11 +14,12 @@ import AWSLambdaEvents import AWSLambdaRuntime - @preconcurrency import AWSS3 + let client = try await S3Client() -let runtime = LambdaRuntime.init { (event: APIGatewayV2Request, context: LambdaContext) async throws -> APIGatewayV2Response in +let runtime = LambdaRuntime.init { + (event: APIGatewayV2Request, context: LambdaContext) async throws -> APIGatewayV2Response in var response: APIGatewayV2Response do { From 683cd55405c2c6c582d182b4f903ee6ee6b5c2fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Tue, 8 Oct 2024 22:30:54 +0200 Subject: [PATCH 14/33] remove unnecessary license header --- Examples/Soto/template.yaml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Examples/Soto/template.yaml b/Examples/Soto/template.yaml index 85b91540..9f9854af 100644 --- a/Examples/Soto/template.yaml +++ b/Examples/Soto/template.yaml @@ -1,17 +1,3 @@ -#===----------------------------------------------------------------------===// -# -# This source file is part of the AWS Lambda Swift -# VSCode extension open source project. -# -# Copyright (c) 2024, the VSCode AWS Lambda Swift extension project authors. -# Licensed under Apache License v2.0. -# -# See LICENSE.txt for license information -# See CONTRIBUTORS.txt for the list of VSCode AWS Lambda Swift project authors -# -# SPDX-License-Identifier: Apache-2.0 -# -#===----------------------------------------------------------------------===// AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 From cc3f3c2fdc23b2c15e99c8142a471e646c6ac3e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Tue, 8 Oct 2024 22:40:20 +0200 Subject: [PATCH 15/33] add soto client shutdown --- Examples/Soto/Sources/main.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Examples/Soto/Sources/main.swift b/Examples/Soto/Sources/main.swift index a98fd6e7..caa70116 100644 --- a/Examples/Soto/Sources/main.swift +++ b/Examples/Soto/Sources/main.swift @@ -37,4 +37,6 @@ func handler(event: APIGatewayV2Request, context: LambdaContext) async throws -> } let runtime = LambdaRuntime.init(body: handler) + try await runtime.run() +try await client.shutdown() From 0e4fa0cea05a84b40a6d18afb903c1235d4e1029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Wed, 9 Oct 2024 10:36:47 +0200 Subject: [PATCH 16/33] revert platform dance to not break CI --- Examples/APIGateway/Package.swift | 8 +++++++- Examples/AWSSDK/Package.swift | 8 +++++++- Examples/HelloWorld/Package.swift | 8 +++++++- Examples/Soto/Package.swift | 8 +++++++- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Examples/APIGateway/Package.swift b/Examples/APIGateway/Package.swift index 94a8fada..4390e055 100644 --- a/Examples/APIGateway/Package.swift +++ b/Examples/APIGateway/Package.swift @@ -6,9 +6,15 @@ import PackageDescription import class Foundation.ProcessInfo 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)], + platforms: platforms, products: [ .executable(name: "APIGatewayLambda", targets: ["APIGatewayLambda"]) ], diff --git a/Examples/AWSSDK/Package.swift b/Examples/AWSSDK/Package.swift index ed01c437..aef7d90d 100644 --- a/Examples/AWSSDK/Package.swift +++ b/Examples/AWSSDK/Package.swift @@ -6,9 +6,15 @@ import PackageDescription import class Foundation.ProcessInfo import struct Foundation.URL +#if os(macOS) +let platforms: [PackageDescription.SupportedPlatform]? = [.macOS(.v15)] +#else +let platforms: [PackageDescription.SupportedPlatform]? = nil +#endif + let package = Package( name: "AWSSDKExample", - platforms: [.macOS(.v15)], + platforms: platforms, products: [ .executable(name: "AWSSDKExample", targets: ["AWSSDKExample"]) ], diff --git a/Examples/HelloWorld/Package.swift b/Examples/HelloWorld/Package.swift index 597bfe3f..6468fb88 100644 --- a/Examples/HelloWorld/Package.swift +++ b/Examples/HelloWorld/Package.swift @@ -6,9 +6,15 @@ import PackageDescription import class Foundation.ProcessInfo 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)], + platforms: platforms, products: [ .executable(name: "MyLambda", targets: ["MyLambda"]) ], diff --git a/Examples/Soto/Package.swift b/Examples/Soto/Package.swift index e3d0f541..d0e43238 100644 --- a/Examples/Soto/Package.swift +++ b/Examples/Soto/Package.swift @@ -6,9 +6,15 @@ import PackageDescription import class Foundation.ProcessInfo import struct Foundation.URL +#if os(macOS) +let platforms: [PackageDescription.SupportedPlatform]? = [.macOS(.v15)] +#else +let platforms: [PackageDescription.SupportedPlatform]? = nil +#endif + let package = Package( name: "SotoLambdaExample", - platforms: [.macOS(.v15)], + platforms: platforms, products: [ .executable(name: "SotoLambdaExample", targets: ["SotoExample"]) ], From 39deb51f38c3036c2fe149bb1e7810e0a6d77219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Wed, 9 Oct 2024 11:17:40 +0200 Subject: [PATCH 17/33] remove unnecessary init --- Examples/AWSSDK/Sources/main.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Examples/AWSSDK/Sources/main.swift b/Examples/AWSSDK/Sources/main.swift index 3f50b7f8..6665893c 100644 --- a/Examples/AWSSDK/Sources/main.swift +++ b/Examples/AWSSDK/Sources/main.swift @@ -18,7 +18,7 @@ import AWSLambdaRuntime let client = try await S3Client() -let runtime = LambdaRuntime.init { +let runtime = LambdaRuntime { (event: APIGatewayV2Request, context: LambdaContext) async throws -> APIGatewayV2Response in var response: APIGatewayV2Response From bc3fe1afee9fbe0e5176042e28b8a99d5c49953c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Wed, 9 Oct 2024 17:07:38 +0200 Subject: [PATCH 18/33] rename directory to SotoS3 --- Examples/{Soto => SotoS3}/.gitignore | 0 Examples/{Soto => SotoS3}/Package.swift | 0 Examples/{Soto => SotoS3}/README.md | 0 Examples/{Soto => SotoS3}/Sources/main.swift | 0 Examples/{Soto => SotoS3}/template.yaml | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename Examples/{Soto => SotoS3}/.gitignore (100%) rename Examples/{Soto => SotoS3}/Package.swift (100%) rename Examples/{Soto => SotoS3}/README.md (100%) rename Examples/{Soto => SotoS3}/Sources/main.swift (100%) rename Examples/{Soto => SotoS3}/template.yaml (100%) diff --git a/Examples/Soto/.gitignore b/Examples/SotoS3/.gitignore similarity index 100% rename from Examples/Soto/.gitignore rename to Examples/SotoS3/.gitignore diff --git a/Examples/Soto/Package.swift b/Examples/SotoS3/Package.swift similarity index 100% rename from Examples/Soto/Package.swift rename to Examples/SotoS3/Package.swift diff --git a/Examples/Soto/README.md b/Examples/SotoS3/README.md similarity index 100% rename from Examples/Soto/README.md rename to Examples/SotoS3/README.md diff --git a/Examples/Soto/Sources/main.swift b/Examples/SotoS3/Sources/main.swift similarity index 100% rename from Examples/Soto/Sources/main.swift rename to Examples/SotoS3/Sources/main.swift diff --git a/Examples/Soto/template.yaml b/Examples/SotoS3/template.yaml similarity index 100% rename from Examples/Soto/template.yaml rename to Examples/SotoS3/template.yaml From 0e9b0458a4191b388138112d826e31254c4081b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Wed, 9 Oct 2024 23:42:08 +0200 Subject: [PATCH 19/33] change directory name to focus on use case first, lib second --- Examples/{AWSSDK => S3_AWSSDK}/.gitignore | 0 Examples/{AWSSDK => S3_AWSSDK}/Package.swift | 0 Examples/{AWSSDK => S3_AWSSDK}/README.md | 0 Examples/{AWSSDK => S3_AWSSDK}/Sources/main.swift | 0 Examples/{AWSSDK => S3_AWSSDK}/template.yaml | 0 Examples/{SotoS3 => S3_Soto}/.gitignore | 0 Examples/{SotoS3 => S3_Soto}/Package.swift | 0 Examples/{SotoS3 => S3_Soto}/README.md | 0 Examples/{SotoS3 => S3_Soto}/Sources/main.swift | 0 Examples/{SotoS3 => S3_Soto}/template.yaml | 0 10 files changed, 0 insertions(+), 0 deletions(-) rename Examples/{AWSSDK => S3_AWSSDK}/.gitignore (100%) rename Examples/{AWSSDK => S3_AWSSDK}/Package.swift (100%) rename Examples/{AWSSDK => S3_AWSSDK}/README.md (100%) rename Examples/{AWSSDK => S3_AWSSDK}/Sources/main.swift (100%) rename Examples/{AWSSDK => S3_AWSSDK}/template.yaml (100%) rename Examples/{SotoS3 => S3_Soto}/.gitignore (100%) rename Examples/{SotoS3 => S3_Soto}/Package.swift (100%) rename Examples/{SotoS3 => S3_Soto}/README.md (100%) rename Examples/{SotoS3 => S3_Soto}/Sources/main.swift (100%) rename Examples/{SotoS3 => S3_Soto}/template.yaml (100%) diff --git a/Examples/AWSSDK/.gitignore b/Examples/S3_AWSSDK/.gitignore similarity index 100% rename from Examples/AWSSDK/.gitignore rename to Examples/S3_AWSSDK/.gitignore diff --git a/Examples/AWSSDK/Package.swift b/Examples/S3_AWSSDK/Package.swift similarity index 100% rename from Examples/AWSSDK/Package.swift rename to Examples/S3_AWSSDK/Package.swift diff --git a/Examples/AWSSDK/README.md b/Examples/S3_AWSSDK/README.md similarity index 100% rename from Examples/AWSSDK/README.md rename to Examples/S3_AWSSDK/README.md diff --git a/Examples/AWSSDK/Sources/main.swift b/Examples/S3_AWSSDK/Sources/main.swift similarity index 100% rename from Examples/AWSSDK/Sources/main.swift rename to Examples/S3_AWSSDK/Sources/main.swift diff --git a/Examples/AWSSDK/template.yaml b/Examples/S3_AWSSDK/template.yaml similarity index 100% rename from Examples/AWSSDK/template.yaml rename to Examples/S3_AWSSDK/template.yaml diff --git a/Examples/SotoS3/.gitignore b/Examples/S3_Soto/.gitignore similarity index 100% rename from Examples/SotoS3/.gitignore rename to Examples/S3_Soto/.gitignore diff --git a/Examples/SotoS3/Package.swift b/Examples/S3_Soto/Package.swift similarity index 100% rename from Examples/SotoS3/Package.swift rename to Examples/S3_Soto/Package.swift diff --git a/Examples/SotoS3/README.md b/Examples/S3_Soto/README.md similarity index 100% rename from Examples/SotoS3/README.md rename to Examples/S3_Soto/README.md diff --git a/Examples/SotoS3/Sources/main.swift b/Examples/S3_Soto/Sources/main.swift similarity index 100% rename from Examples/SotoS3/Sources/main.swift rename to Examples/S3_Soto/Sources/main.swift diff --git a/Examples/SotoS3/template.yaml b/Examples/S3_Soto/template.yaml similarity index 100% rename from Examples/SotoS3/template.yaml rename to Examples/S3_Soto/template.yaml From 9c917452f5deb5d0e8b0e960614c5ed5eaffedad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Wed, 9 Oct 2024 23:56:12 +0200 Subject: [PATCH 20/33] fix typos in the readme --- Examples/S3_AWSSDK/README.md | 9 +++++---- Examples/S3_Soto/README.md | 19 +++++++------------ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/Examples/S3_AWSSDK/README.md b/Examples/S3_AWSSDK/README.md index 0a1cf75b..58a7b83d 100644 --- a/Examples/S3_AWSSDK/README.md +++ b/Examples/S3_AWSSDK/README.md @@ -1,10 +1,10 @@ -# API Gateway +# List Amazon S3 Buckets with the AWS SDK for Swift This is a simple example of an AWS Lambda function that uses the [AWS SDK for Swift](https://github.com/awslabs/aws-sdk-swift) to read data from Amazon S3. ## Code -The Lambda function reads all bucket names from your AWS account and return them as a String. +The Lambda function reads all bucket names from your AWS account and returns them as a String. The code creates a `LambdaRuntime` struct. In it's simplest form, the initializer takes a function as argument. The function is the handler that will be invoked when the API Gateway receives an HTTP request. @@ -17,7 +17,7 @@ The function must return a `APIGatewayV2Response`. `APIGatewayV2Request` and `APIGatewayV2Response` are defined in the [Swift AWS Lambda Events](https://github.com/swift-server/swift-aws-lambda-events) library. The handler creates an S3 client and `ListBucketsInput` object. It passes the input object to the client and receives an output response. -It then extract the list of bucket names from the output to create a `\n` separated list of names, as a `String` +It then extracts the list of bucket names from the output and creates a `\n`-separated list of names, as a `String` ## Build & Package @@ -77,9 +77,10 @@ This should print text similar to ```bash my_bucket_1 my_bucket_2 +... ``` -## Undeploy +## Delete the infrastructure When done testing, you can delete the infrastructure with this command. diff --git a/Examples/S3_Soto/README.md b/Examples/S3_Soto/README.md index 488fd48b..c9c0e4a1 100644 --- a/Examples/S3_Soto/README.md +++ b/Examples/S3_Soto/README.md @@ -1,16 +1,10 @@ -sam deploy \ ---resolve-s3 \ ---template-file template.yaml \ ---stack-name AWSSDKExample \ ---capabilities CAPABILITY_IAM - -# API Gateway +# List Amazon S3 Buckets with Soto This is a simple example of an AWS Lambda function that uses the [Soto SDK for AWS](https://github.com/soto-project/soto) to read data from Amazon S3. ## Code -The Lambda function reads all bucket names from your AWS account and return them as a String. +The Lambda function reads all bucket names from your AWS account and returns them as a String. The code creates a `LambdaRuntime` struct. In it's simplest form, the initializer takes a function as argument. The function is the handler that will be invoked when the API Gateway receives an HTTP request. @@ -22,12 +16,12 @@ The function must return a `APIGatewayV2Response`. `APIGatewayV2Request` and `APIGatewayV2Response` are defined in the [Swift AWS Lambda Events](https://github.com/swift-server/swift-aws-lambda-events) library. -The handler creates AWS and S3 clients. It then calls `listBuckets()` on the S3 client and receives an output response. -It then extract the list of bucket names from the output to create a `\n` separated list of names, as a `String` +The handler creates two clients : an AWS client that manages the communication with AWS API and and the S3 client that expose the S3 API. Then, the handler calls `listBuckets()` on the S3 client and receives an output response. +Finally, the handler extracts the list of bucket names from the output to create a `\n`-separated list of names, as a `String`. ## Build & Package -To build the package, type the following commands. +To build the package, type the following command. ```bash swift build @@ -83,9 +77,10 @@ This should print text similar to ```bash my_bucket_1 my_bucket_2 +... ``` -## Undeploy +## Delete the infrastructure When done testing, you can delete the infrastructure with this command. From a3b29c6a0b25647941e48b5372f173ade456039a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Thu, 10 Oct 2024 11:43:42 +0200 Subject: [PATCH 21/33] add new examples to CI --- .github/workflows/examples_matrix.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/examples_matrix.yml b/.github/workflows/examples_matrix.yml index 39ec1d26..adb09efa 100644 --- a/.github/workflows/examples_matrix.yml +++ b/.github/workflows/examples_matrix.yml @@ -33,7 +33,7 @@ jobs: fail-fast: false matrix: # This should be passed as an argument in input. Can we pass arrays as argument ? - examples : [ "HelloWorld", "APIGateway" ] + examples : [ "HelloWorld", "APIGateway", "S3_AWSSDK", "S3_Soto" ] # examples: ${{ inputs.examples }} # We are using only one Swift version From 96efb9a7531d57a25d95e47fd960eb930c074642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Thu, 10 Oct 2024 11:50:13 +0200 Subject: [PATCH 22/33] fix CI for examples --- .github/workflows/examples_matrix.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/examples_matrix.yml b/.github/workflows/examples_matrix.yml index adb09efa..8c57b863 100644 --- a/.github/workflows/examples_matrix.yml +++ b/.github/workflows/examples_matrix.yml @@ -56,5 +56,5 @@ jobs: COMMAND: ${{ inputs.matrix_linux_command }} EXAMPLE: ${{ matrix.examples }} run: | - apt-get -qq update && apt-get -qq -y install curl + apt-get -qq update && apt-get -qq -y install curl openssl libssl-dev ./scripts/integration_tests.sh \ No newline at end of file From b47d1b87a84280775fa453a5cad6431f3f6483b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Thu, 10 Oct 2024 12:01:14 +0200 Subject: [PATCH 23/33] use amazonlinux docker image instead of ubuntu --- .github/workflows/examples_matrix.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/examples_matrix.yml b/.github/workflows/examples_matrix.yml index 8c57b863..be66358a 100644 --- a/.github/workflows/examples_matrix.yml +++ b/.github/workflows/examples_matrix.yml @@ -18,7 +18,7 @@ on: matrix_linux_swift_container_image: type: string description: "Container image for the matrix job. Defaults to matching latest Swift Ubuntu image." - default: "swift:latest" + default: "swift:amazonlinux2" ## We are cancelling previously triggered workflow runs concurrency: @@ -39,7 +39,7 @@ jobs: # We are using only one Swift version swift: - image: ${{ inputs.matrix_linux_swift_container_image }} - swift_version: "6.0.1-noble" + swift_version: "6.0.1-amazonlinux2" container: image: ${{ matrix.swift.image }} steps: @@ -56,5 +56,4 @@ jobs: COMMAND: ${{ inputs.matrix_linux_command }} EXAMPLE: ${{ matrix.examples }} run: | - apt-get -qq update && apt-get -qq -y install curl openssl libssl-dev ./scripts/integration_tests.sh \ No newline at end of file From 38ab48a3b31f00f72d7be02befa67f2f33871e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Thu, 10 Oct 2024 12:23:11 +0200 Subject: [PATCH 24/33] dynamically add runtime dependency based on env var --- Examples/APIGateway/Package.swift | 28 ++++++++++++++++------------ Examples/HelloWorld/Package.swift | 27 ++++++++++++++++----------- Examples/S3_AWSSDK/Package.swift | 29 +++++++++++++++++------------ Examples/S3_Soto/Package.swift | 31 ++++++++++++++++++------------- 4 files changed, 67 insertions(+), 48 deletions(-) diff --git a/Examples/APIGateway/Package.swift b/Examples/APIGateway/Package.swift index 4390e055..6d182eda 100644 --- a/Examples/APIGateway/Package.swift +++ b/Examples/APIGateway/Package.swift @@ -19,9 +19,8 @@ let package = Package( .executable(name: "APIGatewayLambda", targets: ["APIGatewayLambda"]) ], dependencies: [ - // dependency on swift-aws-lambda-runtime is added dynamically below - // .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main") - + // 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") ], targets: [ @@ -36,20 +35,25 @@ let package = Package( ] ) -if let localDepsPath = ProcessInfo.processInfo.environment["LAMBDA_USE_LOCAL_DEPS"], +if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], localDepsPath != "", let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), - let _ = v.isDirectory + 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) ] - -} else { - print("[INFO] LAMBDA_USE_LOCAL_DEPS is not pointing to your local swift-aws-lambda-runtime code") - print("[INFO] This project will compile against the main branch of the Lambda Runtime on GitHub") - package.dependencies += [ - .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main") - ] } diff --git a/Examples/HelloWorld/Package.swift b/Examples/HelloWorld/Package.swift index 6468fb88..58d6e1c7 100644 --- a/Examples/HelloWorld/Package.swift +++ b/Examples/HelloWorld/Package.swift @@ -19,8 +19,8 @@ let package = Package( .executable(name: "MyLambda", targets: ["MyLambda"]) ], dependencies: [ - // dependency on swift-aws-lambda-runtime is added dynamically below - // .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main") + // 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( @@ -33,20 +33,25 @@ let package = Package( ] ) -if let localDepsPath = ProcessInfo.processInfo.environment["LAMBDA_USE_LOCAL_DEPS"], +if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], localDepsPath != "", let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), - let _ = v.isDirectory + 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) ] - -} else { - print("[INFO] LAMBDA_USE_LOCAL_DEPS is not pointing to your local swift-aws-lambda-runtime code") - print("[INFO] This project will compile against the main branch of the Lambda Runtime on GitHub") - package.dependencies += [ - .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main") - ] } diff --git a/Examples/S3_AWSSDK/Package.swift b/Examples/S3_AWSSDK/Package.swift index aef7d90d..1babdd34 100644 --- a/Examples/S3_AWSSDK/Package.swift +++ b/Examples/S3_AWSSDK/Package.swift @@ -19,8 +19,8 @@ let package = Package( .executable(name: "AWSSDKExample", targets: ["AWSSDKExample"]) ], dependencies: [ - // dependency on swift-aws-lambda-runtime is added dynamically below - // .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main") + // 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/awslabs/aws-sdk-swift", from: "1.0.0"), ], @@ -36,20 +36,25 @@ let package = Package( ] ) -if let localDepsPath = ProcessInfo.processInfo.environment["LAMBDA_USE_LOCAL_DEPS"], +if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], localDepsPath != "", let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), - let _ = v.isDirectory + 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) ] - -} else { - print("[INFO] LAMBDA_USE_LOCAL_DEPS is not pointing to your local swift-aws-lambda-runtime code") - print("[INFO] This project will compile against the main branch of the Lambda Runtime on GitHub") - package.dependencies += [ - .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main") - ] -} +} \ No newline at end of file diff --git a/Examples/S3_Soto/Package.swift b/Examples/S3_Soto/Package.swift index d0e43238..c647d9db 100644 --- a/Examples/S3_Soto/Package.swift +++ b/Examples/S3_Soto/Package.swift @@ -13,16 +13,16 @@ let platforms: [PackageDescription.SupportedPlatform]? = nil #endif let package = Package( - name: "SotoLambdaExample", + name: "SotoExample", platforms: platforms, products: [ - .executable(name: "SotoLambdaExample", targets: ["SotoExample"]) + .executable(name: "SotoExample", targets: ["SotoExample"]) ], dependencies: [ .package(url: "https://github.com/soto-project/soto.git", from: "7.0.0"), - // dependency on swift-aws-lambda-runtime is added dynamically below - // .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main") + // 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"), ], targets: [ @@ -37,20 +37,25 @@ let package = Package( ] ) -if let localDepsPath = ProcessInfo.processInfo.environment["LAMBDA_USE_LOCAL_DEPS"], +if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], localDepsPath != "", let v = try? URL(fileURLWithPath: localDepsPath).resourceValues(forKeys: [.isDirectoryKey]), - let _ = v.isDirectory + 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) ] - -} else { - print("[INFO] LAMBDA_USE_LOCAL_DEPS is not pointing to your local swift-aws-lambda-runtime code") - print("[INFO] This project will compile against the main branch of the Lambda Runtime on GitHub") - package.dependencies += [ - .package(url: "https://github.com/swift-server/swift-aws-lambda-runtime.git", branch: "main") - ] } From 4e73292e61c8be9e6ab1d1a46e4068250e10a638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Thu, 10 Oct 2024 12:25:52 +0200 Subject: [PATCH 25/33] remove import of Foundation.ProcessInfo --- Examples/APIGateway/Package.swift | 1 - Examples/HelloWorld/Package.swift | 1 - Examples/S3_AWSSDK/Package.swift | 1 - Examples/S3_Soto/Package.swift | 1 - 4 files changed, 4 deletions(-) diff --git a/Examples/APIGateway/Package.swift b/Examples/APIGateway/Package.swift index 6d182eda..216c89a0 100644 --- a/Examples/APIGateway/Package.swift +++ b/Examples/APIGateway/Package.swift @@ -3,7 +3,6 @@ import PackageDescription // needed for CI to test the local version of the library -import class Foundation.ProcessInfo import struct Foundation.URL #if os(macOS) diff --git a/Examples/HelloWorld/Package.swift b/Examples/HelloWorld/Package.swift index 58d6e1c7..b668071e 100644 --- a/Examples/HelloWorld/Package.swift +++ b/Examples/HelloWorld/Package.swift @@ -3,7 +3,6 @@ import PackageDescription // needed for CI to test the local version of the library -import class Foundation.ProcessInfo import struct Foundation.URL #if os(macOS) diff --git a/Examples/S3_AWSSDK/Package.swift b/Examples/S3_AWSSDK/Package.swift index 1babdd34..730200a1 100644 --- a/Examples/S3_AWSSDK/Package.swift +++ b/Examples/S3_AWSSDK/Package.swift @@ -3,7 +3,6 @@ import PackageDescription // needed for CI to test the local version of the library -import class Foundation.ProcessInfo import struct Foundation.URL #if os(macOS) diff --git a/Examples/S3_Soto/Package.swift b/Examples/S3_Soto/Package.swift index c647d9db..cda1859d 100644 --- a/Examples/S3_Soto/Package.swift +++ b/Examples/S3_Soto/Package.swift @@ -3,7 +3,6 @@ import PackageDescription // needed for CI to test the local version of the library -import class Foundation.ProcessInfo import struct Foundation.URL #if os(macOS) From 56b07b54a6cbf4250a08b0df18f543567df525dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Thu, 10 Oct 2024 12:27:55 +0200 Subject: [PATCH 26/33] change log level and add comment in template.yaml --- Examples/APIGateway/template.yaml | 4 ++-- Examples/S3_AWSSDK/template.yaml | 4 ++-- Examples/S3_Soto/template.yaml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Examples/APIGateway/template.yaml b/Examples/APIGateway/template.yaml index 3388be16..99a00da9 100644 --- a/Examples/APIGateway/template.yaml +++ b/Examples/APIGateway/template.yaml @@ -9,7 +9,7 @@ Resources: Properties: CodeUri: .build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/APIGatewayLambda/APIGatewayLambda.zip Timeout: 60 - Handler: swift.bootstrap + Handler: swift.bootstrap # ignored by the Swift runtime Runtime: provided.al2 MemorySize: 512 Architectures: @@ -19,7 +19,7 @@ Resources: # by default, AWS Lambda runtime produces no log # use `LOG_LEVEL: debug` for for lifecycle and event handling information # use `LOG_LEVEL: trace` for detailed input event information - LOG_LEVEL: trace + LOG_LEVEL: debug Events: HttpApiEvent: Type: HttpApi diff --git a/Examples/S3_AWSSDK/template.yaml b/Examples/S3_AWSSDK/template.yaml index 7499ae40..b1e02416 100644 --- a/Examples/S3_AWSSDK/template.yaml +++ b/Examples/S3_AWSSDK/template.yaml @@ -9,7 +9,7 @@ Resources: Properties: CodeUri: .build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/AWSSDKExample/AWSSDKExample.zip Timeout: 60 - Handler: swift.bootstrap + Handler: swift.bootstrap # ignored by the Swift runtime Runtime: provided.al2 MemorySize: 512 Architectures: @@ -19,7 +19,7 @@ Resources: # by default, AWS Lambda runtime produces no log # use `LOG_LEVEL: debug` for for lifecycle and event handling information # use `LOG_LEVEL: trace` for detailed input event information - LOG_LEVEL: trace + LOG_LEVEL: debug # Handles all methods of the REST API Events: diff --git a/Examples/S3_Soto/template.yaml b/Examples/S3_Soto/template.yaml index 9f9854af..50093169 100644 --- a/Examples/S3_Soto/template.yaml +++ b/Examples/S3_Soto/template.yaml @@ -10,7 +10,7 @@ Resources: Properties: CodeUri: .build/plugins/AWSLambdaPackager/outputs/AWSLambdaPackager/SotoExample/SotoExample.zip Timeout: 60 - Handler: swift.bootstrap + Handler: swift.bootstrap # ignored by the Swift runtime Runtime: provided.al2 MemorySize: 512 Architectures: @@ -20,7 +20,7 @@ Resources: # by default, AWS Lambda runtime produces no log # use `LOG_LEVEL: debug` for for lifecycle and event handling information # use `LOG_LEVEL: trace` for detailed input event information - LOG_LEVEL: trace + LOG_LEVEL: debug # Handles all methods of the REST API Events: From 156c7e776dfe10b055e0f4d6be1077b57ead3a99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Thu, 10 Oct 2024 12:31:03 +0200 Subject: [PATCH 27/33] downgrade actions/checkout to v3 to workaround dependency on mazonLinux 2 --- .github/workflows/examples_matrix.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/examples_matrix.yml b/.github/workflows/examples_matrix.yml index be66358a..c062048d 100644 --- a/.github/workflows/examples_matrix.yml +++ b/.github/workflows/examples_matrix.yml @@ -44,7 +44,8 @@ jobs: image: ${{ matrix.swift.image }} steps: - name: Checkout repository - uses: actions/checkout@v4 + # use v3 until this is fixed https://github.com/actions/checkout/issues/1487 + uses: actions/checkout@v3 with: persist-credentials: false - name: Mark the workspace as safe From b747e5d80586948ca8213e2819f701933021c4b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Thu, 10 Oct 2024 12:35:44 +0200 Subject: [PATCH 28/33] Swift format --- Examples/APIGateway/Package.swift | 10 +++++++--- Examples/HelloWorld/Package.swift | 10 +++++++--- Examples/S3_AWSSDK/Package.swift | 10 +++++++--- Examples/S3_Soto/Package.swift | 8 ++++++-- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Examples/APIGateway/Package.swift b/Examples/APIGateway/Package.swift index 216c89a0..ebaac99a 100644 --- a/Examples/APIGateway/Package.swift +++ b/Examples/APIGateway/Package.swift @@ -20,7 +20,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", branch: "main"), ], targets: [ .executableTarget( @@ -41,7 +41,11 @@ if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], { // 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 { + if case .sourceControl( + name: _, + location: "https://github.com/swift-server/swift-aws-lambda-runtime.git", + requirement: _ + ) = dependency.kind { return true } return false @@ -49,7 +53,7 @@ if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], 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 += [ diff --git a/Examples/HelloWorld/Package.swift b/Examples/HelloWorld/Package.swift index b668071e..adb4b1f9 100644 --- a/Examples/HelloWorld/Package.swift +++ b/Examples/HelloWorld/Package.swift @@ -19,7 +19,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-runtime.git", branch: "main") ], targets: [ .executableTarget( @@ -39,7 +39,11 @@ if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], { // 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 { + if case .sourceControl( + name: _, + location: "https://github.com/swift-server/swift-aws-lambda-runtime.git", + requirement: _ + ) = dependency.kind { return true } return false @@ -47,7 +51,7 @@ if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], 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 += [ diff --git a/Examples/S3_AWSSDK/Package.swift b/Examples/S3_AWSSDK/Package.swift index 730200a1..5417fbdd 100644 --- a/Examples/S3_AWSSDK/Package.swift +++ b/Examples/S3_AWSSDK/Package.swift @@ -42,7 +42,11 @@ if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], { // 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 { + if case .sourceControl( + name: _, + location: "https://github.com/swift-server/swift-aws-lambda-runtime.git", + requirement: _ + ) = dependency.kind { return true } return false @@ -50,10 +54,10 @@ if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], 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) ] -} \ No newline at end of file +} diff --git a/Examples/S3_Soto/Package.swift b/Examples/S3_Soto/Package.swift index cda1859d..4b4eead1 100644 --- a/Examples/S3_Soto/Package.swift +++ b/Examples/S3_Soto/Package.swift @@ -43,7 +43,11 @@ if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], { // 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 { + if case .sourceControl( + name: _, + location: "https://github.com/swift-server/swift-aws-lambda-runtime.git", + requirement: _ + ) = dependency.kind { return true } return false @@ -51,7 +55,7 @@ if let localDepsPath = Context.environment["LAMBDA_USE_LOCAL_DEPS"], 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 += [ From 34ec3ed3a8676833a9eb933e66d70e3774eba8d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Thu, 10 Oct 2024 12:45:24 +0200 Subject: [PATCH 29/33] workaround https://github.com/actions/checkout/issues/1487 --- .github/workflows/examples_matrix.yml | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/workflows/examples_matrix.yml b/.github/workflows/examples_matrix.yml index c062048d..c4a050f4 100644 --- a/.github/workflows/examples_matrix.yml +++ b/.github/workflows/examples_matrix.yml @@ -44,14 +44,25 @@ jobs: image: ${{ matrix.swift.image }} steps: - name: Checkout repository - # use v3 until this is fixed https://github.com/actions/checkout/issues/1487 - uses: actions/checkout@v3 - with: - persist-credentials: false + # GitHub checkout action has a dep on NodeJS 20 which is not running on Amazonlinux2 + # workaround is to manually checkout the repository + # https://github.com/actions/checkout/issues/1487 + + # uses: actions/checkout@v4 + # with: + # persist-credentials: false + run: | + git clone https://github.com/${{ github.repository }} + cd ${{ github.event.repository.name }} + git checkout ${{ github.sha }} + - name: Mark the workspace as safe - # https://github.com/actions/checkout/issues/766 + working-directory: ${{ github.event.repository.name }} # until we can use action/checkout@v4 + # https://github.com/actions/checkout/issues/766 run: git config --global --add safe.directory ${GITHUB_WORKSPACE} + - name: Run matrix job + working-directory: ${{ github.event.repository.name }} # until we can use action/checkout@v4 env: SWIFT_VERSION: ${{ matrix.swift.swift_version }} COMMAND: ${{ inputs.matrix_linux_command }} From d40d3249dc04204a0dc94018ec986644bbba8986 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Thu, 10 Oct 2024 12:47:50 +0200 Subject: [PATCH 30/33] fix CI --- .github/workflows/examples_matrix.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/examples_matrix.yml b/.github/workflows/examples_matrix.yml index c4a050f4..6e0fbfaa 100644 --- a/.github/workflows/examples_matrix.yml +++ b/.github/workflows/examples_matrix.yml @@ -54,7 +54,6 @@ jobs: run: | git clone https://github.com/${{ github.repository }} cd ${{ github.event.repository.name }} - git checkout ${{ github.sha }} - name: Mark the workspace as safe working-directory: ${{ github.event.repository.name }} # until we can use action/checkout@v4 From 6998a50b69d418527147a5889043487b9908de9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Thu, 10 Oct 2024 12:55:25 +0200 Subject: [PATCH 31/33] fix ci --- .github/workflows/examples_matrix.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/examples_matrix.yml b/.github/workflows/examples_matrix.yml index 6e0fbfaa..8e841a63 100644 --- a/.github/workflows/examples_matrix.yml +++ b/.github/workflows/examples_matrix.yml @@ -54,6 +54,7 @@ jobs: run: | git clone https://github.com/${{ github.repository }} cd ${{ github.event.repository.name }} + git checkout ${{ github.ref }} - name: Mark the workspace as safe working-directory: ${{ github.event.repository.name }} # until we can use action/checkout@v4 From c5039eaa2f09345c11906c3b75cf9a37c9e1a748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Thu, 10 Oct 2024 12:59:43 +0200 Subject: [PATCH 32/33] fix ci --- .github/workflows/examples_matrix.yml | 29 ++++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/.github/workflows/examples_matrix.yml b/.github/workflows/examples_matrix.yml index 8e841a63..54f6d8a9 100644 --- a/.github/workflows/examples_matrix.yml +++ b/.github/workflows/examples_matrix.yml @@ -43,18 +43,27 @@ jobs: container: image: ${{ matrix.swift.image }} steps: - - name: Checkout repository - # GitHub checkout action has a dep on NodeJS 20 which is not running on Amazonlinux2 - # workaround is to manually checkout the repository - # https://github.com/actions/checkout/issues/1487 - # uses: actions/checkout@v4 - # with: - # persist-credentials: false + # GitHub checkout action has a dep on NodeJS 20 which is not running on Amazonlinux2 + # workaround is to manually checkout the repository + # https://github.com/actions/checkout/issues/1487 + - name: Manually Clone repository and checkout PR + env: + PR_NUMBER: ${{ github.event.pull_request.number }} run: | - git clone https://github.com/${{ github.repository }} - cd ${{ github.event.repository.name }} - git checkout ${{ github.ref }} + # Clone the repository + git clone https://github.com/${{ github.repository }}.git . + + # Fetch the pull request + git fetch origin +refs/pull/$PR_NUMBER/merge: + + # Checkout the pull request + git checkout -qf FETCH_HEAD + + # - name: Checkout repository + # uses: actions/checkout@v4 + # with: + # persist-credentials: false - name: Mark the workspace as safe working-directory: ${{ github.event.repository.name }} # until we can use action/checkout@v4 From f5506f5e783051e28c90f330c521b0c294668c09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Stormacq?= Date: Thu, 10 Oct 2024 13:02:08 +0200 Subject: [PATCH 33/33] fix ci --- .github/workflows/examples_matrix.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/examples_matrix.yml b/.github/workflows/examples_matrix.yml index 54f6d8a9..15e4e859 100644 --- a/.github/workflows/examples_matrix.yml +++ b/.github/workflows/examples_matrix.yml @@ -52,8 +52,9 @@ jobs: PR_NUMBER: ${{ github.event.pull_request.number }} run: | # Clone the repository - git clone https://github.com/${{ github.repository }}.git . - + git clone https://github.com/${{ github.repository }} + cd ${{ github.event.repository.name }} + # Fetch the pull request git fetch origin +refs/pull/$PR_NUMBER/merge: