From 721ff560683d8a85e4f5bbec3c5cfeb4dcf5fef3 Mon Sep 17 00:00:00 2001 From: YR Chen Date: Mon, 6 Dec 2021 17:56:55 +0800 Subject: [PATCH 1/2] Adopt Concurrency adoption guidelines --- Sources/AWSLambdaRuntimeCore/Lambda.swift | 2 +- Sources/AWSLambdaRuntimeCore/LambdaHandler.swift | 2 +- Sources/AWSLambdaTesting/Lambda+Testing.swift | 2 +- Tests/AWSLambdaRuntimeCoreTests/LambdaHandlerTest.swift | 2 +- .../{Lambda+CodeableTest.swift => Lambda+CodableTest.swift} | 4 ++-- Tests/AWSLambdaTestingTests/Tests.swift | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) rename Tests/AWSLambdaRuntimeTests/{Lambda+CodeableTest.swift => Lambda+CodableTest.swift} (98%) diff --git a/Sources/AWSLambdaRuntimeCore/Lambda.swift b/Sources/AWSLambdaRuntimeCore/Lambda.swift index a4a04cd7..d54d0192 100644 --- a/Sources/AWSLambdaRuntimeCore/Lambda.swift +++ b/Sources/AWSLambdaRuntimeCore/Lambda.swift @@ -53,7 +53,7 @@ public enum Lambda { return String(cString: value) } - #if swift(>=5.5) + #if compiler(>=5.5) && canImport(_Concurrency) // for testing and internal use @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) internal static func run(configuration: Configuration = .init(), handlerType: Handler.Type) -> Result { diff --git a/Sources/AWSLambdaRuntimeCore/LambdaHandler.swift b/Sources/AWSLambdaRuntimeCore/LambdaHandler.swift index d9fd68f8..f0a9d256 100644 --- a/Sources/AWSLambdaRuntimeCore/LambdaHandler.swift +++ b/Sources/AWSLambdaRuntimeCore/LambdaHandler.swift @@ -17,7 +17,7 @@ import NIOCore // MARK: - LambdaHandler -#if compiler(>=5.5) +#if compiler(>=5.5) && canImport(_Concurrency) /// Strongly typed, processing protocol for a Lambda that takes a user defined `Event` and returns a user defined `Output` async. @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) public protocol LambdaHandler: EventLoopLambdaHandler { diff --git a/Sources/AWSLambdaTesting/Lambda+Testing.swift b/Sources/AWSLambdaTesting/Lambda+Testing.swift index 7180a204..85955f69 100644 --- a/Sources/AWSLambdaTesting/Lambda+Testing.swift +++ b/Sources/AWSLambdaTesting/Lambda+Testing.swift @@ -33,7 +33,7 @@ // XCTAssertEqual(result, "echo" + input) // } -#if swift(>=5.5) +#if compiler(>=5.5) && canImport(_Concurrency) import AWSLambdaRuntime import AWSLambdaRuntimeCore import Dispatch diff --git a/Tests/AWSLambdaRuntimeCoreTests/LambdaHandlerTest.swift b/Tests/AWSLambdaRuntimeCoreTests/LambdaHandlerTest.swift index 27c79e98..27290d54 100644 --- a/Tests/AWSLambdaRuntimeCoreTests/LambdaHandlerTest.swift +++ b/Tests/AWSLambdaRuntimeCoreTests/LambdaHandlerTest.swift @@ -17,7 +17,7 @@ import NIOCore import XCTest class LambdaHandlerTest: XCTestCase { - #if compiler(>=5.5) + #if compiler(>=5.5) && canImport(_Concurrency) // MARK: - LambdaHandler diff --git a/Tests/AWSLambdaRuntimeTests/Lambda+CodeableTest.swift b/Tests/AWSLambdaRuntimeTests/Lambda+CodableTest.swift similarity index 98% rename from Tests/AWSLambdaRuntimeTests/Lambda+CodeableTest.swift rename to Tests/AWSLambdaRuntimeTests/Lambda+CodableTest.swift index 6f10bfc9..214631ad 100644 --- a/Tests/AWSLambdaRuntimeTests/Lambda+CodeableTest.swift +++ b/Tests/AWSLambdaRuntimeTests/Lambda+CodableTest.swift @@ -82,7 +82,7 @@ class CodableLambdaTest: XCTestCase { XCTAssertEqual(response?.requestId, request.requestId) } - #if swift(>=5.5) + #if compiler(>=5.5) && canImport(_Concurrency) @available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) func testCodableVoidHandler() { struct Handler: LambdaHandler { @@ -183,7 +183,7 @@ private struct Response: Codable, Equatable { } } -#if swift(>=5.5) +#if compiler(>=5.5) && canImport(_Concurrency) // NOTE: workaround until we have async test support on linux // https://github.com/apple/swift-corelibs-xctest/pull/326 extension XCTestCase { diff --git a/Tests/AWSLambdaTestingTests/Tests.swift b/Tests/AWSLambdaTestingTests/Tests.swift index 83ac4217..5801f605 100644 --- a/Tests/AWSLambdaTestingTests/Tests.swift +++ b/Tests/AWSLambdaTestingTests/Tests.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// -#if swift(>=5.5) +#if compiler(>=5.5) && canImport(_Concurrency) import AWSLambdaRuntime import AWSLambdaTesting import NIOCore From b78e4a02720043dfcd188bddf6700d7aa8f30bfa Mon Sep 17 00:00:00 2001 From: YR Chen Date: Mon, 6 Dec 2021 18:32:33 +0800 Subject: [PATCH 2/2] Do some code cleaning --- Examples/Deployment/README.md | 4 +-- .../scripts/SAM/APIGateway-template.yml | 30 ------------------- .../serverless/APIGateway-template.yml | 28 ----------------- .../scripts/serverless/Benchmark-template.yml | 2 +- .../serverless/HelloWorld-template.yml | 2 +- Sources/AWSLambdaTesting/Lambda+Testing.swift | 1 - readme.md | 4 +-- 7 files changed, 6 insertions(+), 65 deletions(-) delete mode 100644 Examples/Deployment/scripts/SAM/APIGateway-template.yml delete mode 100644 Examples/Deployment/scripts/serverless/APIGateway-template.yml diff --git a/Examples/Deployment/README.md b/Examples/Deployment/README.md index 6066383d..33d27fc9 100644 --- a/Examples/Deployment/README.md +++ b/Examples/Deployment/README.md @@ -87,7 +87,7 @@ The SAM template will provide an output labelled `LambdaApiGatewayEndpoint` whic ``` curl <> - ``` + ``` ***Warning:*** This SAM template is only intended as a sample and creates a publicly accessible HTTP endpoint. @@ -162,7 +162,7 @@ For example: ``` curl https://r39lvhfng3.execute-api.us-east-1.amazonaws.com/api - ``` + ``` ***Warning:*** This Serverless template is only intended as a sample and creates a publicly accessible HTTP endpoint. diff --git a/Examples/Deployment/scripts/SAM/APIGateway-template.yml b/Examples/Deployment/scripts/SAM/APIGateway-template.yml deleted file mode 100644 index 7776921b..00000000 --- a/Examples/Deployment/scripts/SAM/APIGateway-template.yml +++ /dev/null @@ -1,30 +0,0 @@ -AWSTemplateFormatVersion : '2010-09-09' -Transform: AWS::Serverless-2016-10-31 -Description: A sample SAM template for deploying Lambda functions. - -Resources: -# APIGateway Function - apiGatewayFunction: - Type: AWS::Serverless::Function - Properties: - Handler: Provided - Runtime: provided - CodeUri: ../../.build/lambda/APIGateway/lambda.zip -# Add an API Gateway event source for the Lambda - Events: - HttpGet: - Type: HttpApi - Properties: - ApiId: !Ref lambdaApiGateway - Path: '/samples/apig' - Method: GET -# Instructs new versions to be published to an alias named "live". - AutoPublishAlias: live - - lambdaApiGateway: - Type: AWS::Serverless::HttpApi - -Outputs: - LambdaApiGatewayEndpoint: - Description: 'API Gateway endpoint URL.' - Value: !Sub 'https://${lambdaApiGateway}.execute-api.${AWS::Region}.amazonaws.com/samples/apig' diff --git a/Examples/Deployment/scripts/serverless/APIGateway-template.yml b/Examples/Deployment/scripts/serverless/APIGateway-template.yml deleted file mode 100644 index 6787ad0f..00000000 --- a/Examples/Deployment/scripts/serverless/APIGateway-template.yml +++ /dev/null @@ -1,28 +0,0 @@ -service: apigateway-swift-aws - -package: - artifact: .build/lambda/APIGateway/lambda.zip - -provider: - name: aws - httpApi: - payload: '2.0' - runtime: provided - logs: - httpApi: true - iamRoleStatements: - - Effect: Allow - Action: - - logs:CreateLogGroup - - logs:CreateLogStream - - logs:PutLogEvents - Resource: "*" - -functions: - httpGet: - handler: APIGateway - memorySize: 128 - events: - - httpApi: - method: GET - path: /api \ No newline at end of file diff --git a/Examples/Deployment/scripts/serverless/Benchmark-template.yml b/Examples/Deployment/scripts/serverless/Benchmark-template.yml index 74099441..1b2b1940 100644 --- a/Examples/Deployment/scripts/serverless/Benchmark-template.yml +++ b/Examples/Deployment/scripts/serverless/Benchmark-template.yml @@ -12,7 +12,7 @@ provider: - logs:CreateLogGroup - logs:CreateLogStream - logs:PutLogEvents - Resource: "*" + Resource: "*" functions: benchmarkFunction: diff --git a/Examples/Deployment/scripts/serverless/HelloWorld-template.yml b/Examples/Deployment/scripts/serverless/HelloWorld-template.yml index 276f9909..8d12bb74 100644 --- a/Examples/Deployment/scripts/serverless/HelloWorld-template.yml +++ b/Examples/Deployment/scripts/serverless/HelloWorld-template.yml @@ -12,7 +12,7 @@ provider: - logs:CreateLogGroup - logs:CreateLogStream - logs:PutLogEvents - Resource: "*" + Resource: "*" functions: hello: diff --git a/Sources/AWSLambdaTesting/Lambda+Testing.swift b/Sources/AWSLambdaTesting/Lambda+Testing.swift index 85955f69..f514f38f 100644 --- a/Sources/AWSLambdaTesting/Lambda+Testing.swift +++ b/Sources/AWSLambdaTesting/Lambda+Testing.swift @@ -35,7 +35,6 @@ #if compiler(>=5.5) && canImport(_Concurrency) import AWSLambdaRuntime -import AWSLambdaRuntimeCore import Dispatch import Logging import NIOCore diff --git a/readme.md b/readme.md index a4e5238f..38d71d2c 100644 --- a/readme.md +++ b/readme.md @@ -144,7 +144,7 @@ First, add a dependency on the event packages: Beyond the small cognitive complexity of using the `EventLoopFuture` based APIs, note these APIs should be used with extra care. An `EventLoopLambdaHandler` will execute the user code on the same `EventLoop` (thread) as the library, making processing faster but requiring the user code to never call blocking APIs as it might prevent the underlying process from functioning. -## Deploying to AWS Lambda +## Deploying to AWS Lambda To deploy Lambda functions to AWS Lambda, you need to compile the code for Amazon Linux which is the OS used on AWS Lambda microVMs, package it as a Zip file, and upload to AWS. @@ -160,7 +160,7 @@ The library defines three protocols for the implementation of a Lambda Handler. ### ByteBufferLambdaHandler -An `EventLoopFuture` based processing protocol for a Lambda that takes a `ByteBuffer` and returns a `ByteBuffer?` asynchronously. +An `EventLoopFuture` based processing protocol for a Lambda that takes a `ByteBuffer` and returns a `ByteBuffer?` asynchronously. `ByteBufferLambdaHandler` is the lowest level protocol designed to power the higher level `EventLoopLambdaHandler` and `LambdaHandler` based APIs. Users are not expected to use this protocol, though some performance sensitive applications that operate at the `ByteBuffer` level or have special serialization needs may choose to do so.