Skip to content
This repository was archived by the owner on Jul 14, 2020. It is now read-only.

Commit def35b2

Browse files
fabianfettAntonio Favataalfavata
authored
Use Swift 5.2 (#30)
- Made sure everything compiles with Swift 5.2 - Updated documentation Co-authored-by: Antonio Favata <[email protected]> Co-authored-by: Antonio Favata <[email protected]>
1 parent e85dac1 commit def35b2

File tree

12 files changed

+62
-57
lines changed

12 files changed

+62
-57
lines changed

.github/workflows/ci.yaml

+7-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- TodoAPIGateway
1919
- URLRequestWithSession
2020
env:
21-
SWIFT_VERSION: 5.1.4
21+
SWIFT_VERSION: 5.2.1
2222
steps:
2323
- name: Checkout
2424
uses: actions/checkout@v1
@@ -51,11 +51,13 @@ jobs:
5151
runs-on: ubuntu-latest
5252
strategy:
5353
matrix:
54-
tag: ['5.1']
54+
images:
55+
- swift:5.1.5
56+
- swift:5.2.1
5557
container:
56-
image: swift:${{ matrix.tag }}
58+
image: ${{ matrix.images }}
5759
volumes:
58-
- $GITHUB_WORKSPACE:/src
60+
- /workspace:/src
5961
options: --workdir /src
6062
steps:
6163
- name: Checkout
@@ -83,7 +85,7 @@ jobs:
8385
- name: Show all Xcode versions
8486
run: ls -an /Applications/ | grep Xcode*
8587
- name: Change Xcode command line tools
86-
run: sudo xcode-select -s /Applications/Xcode_11.2.app/Contents/Developer
88+
run: sudo xcode-select -s /Applications/Xcode_11.4.app/Contents/Developer
8789
- name: SPM Build
8890
run: swift build
8991
- name: SPM Tests

Package.swift

+18-18
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,30 @@ let package = Package(
2727
],
2828
targets: [
2929
.target(name: "LambdaEvents", dependencies: [
30-
"NIO",
31-
"NIOHTTP1",
32-
"NIOFoundationCompat",
33-
"Base64Kit"
30+
.product(name: "NIO", package: "swift-nio"),
31+
.product(name: "NIOHTTP1", package: "swift-nio"),
32+
.product(name: "NIOFoundationCompat", package: "swift-nio"),
33+
.product(name: "Base64Kit", package: "swift-base64-kit")
3434
]),
3535
.target(name: "LambdaRuntime", dependencies: [
36-
"LambdaEvents",
37-
"AsyncHTTPClient",
38-
"NIO",
39-
"NIOHTTP1",
40-
"NIOFoundationCompat",
41-
"Logging"
36+
.byName(name: "LambdaEvents"),
37+
.product(name: "AsyncHTTPClient", package: "async-http-client"),
38+
.product(name: "NIO", package: "swift-nio"),
39+
.product(name: "NIOHTTP1", package: "swift-nio"),
40+
.product(name: "NIOFoundationCompat", package: "swift-nio"),
41+
.product(name: "Logging", package: "swift-log"),
4242
]),
4343
.target(name: "LambdaRuntimeTestUtils", dependencies: [
44-
"NIOHTTP1",
45-
"LambdaRuntime"
44+
.byName(name: "LambdaRuntime"),
45+
.product(name: "NIOHTTP1", package: "swift-nio"),
4646
]),
4747
.testTarget(name: "LambdaRuntimeTests", dependencies: [
48-
"LambdaEvents",
49-
"LambdaRuntime",
50-
"LambdaRuntimeTestUtils",
51-
"NIO",
52-
"NIOTestUtils",
53-
"Logging",
48+
.byName(name: "LambdaEvents"),
49+
.byName(name: "LambdaRuntime"),
50+
.byName(name: "LambdaRuntimeTestUtils"),
51+
.product(name: "NIO", package: "swift-nio"),
52+
.product(name: "NIOTestUtils", package: "swift-nio"),
53+
.product(name: "Logging", package: "swift-log"),
5454
])
5555
]
5656
)

README.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# swift-lambda-runtime
22

3-
[![Swift 5.1](https://img.shields.io/badge/Swift-5.1-blue.svg)](https://swift.org/download/)
3+
[![Swift 5.2](https://img.shields.io/badge/Swift-5.2-blue.svg)](https://swift.org/download/)
44
[![github-actions](https://github.com/fabianfett/swift-lambda-runtime/workflows/CI/badge.svg)](https://github.com/fabianfett/swift-lambda-runtime/actions)
55
[![codecov](https://codecov.io/gh/fabianfett/swift-lambda-runtime/branch/master/graph/badge.svg)](https://codecov.io/gh/fabianfett/swift-lambda-runtime)
66

@@ -65,7 +65,7 @@ This should help you to get started with Swift on AWS Lambda. The focus is prima
6565

6666
*Note: The following instructions were recorded on 19.12.2019 and the GUI may have changed since then. Feel free to start an issue if you see a different one.*
6767

68-
The Swift version used here is `5.1.3`. You can look up available versions of Swift on Amazonlinux [here](https://fabianfett.de/amazonlinux-swift). You may want to use a later version if that works for you!
68+
The Swift version used here is `5.2.1`. You can look up available versions of Swift on Amazonlinux [here](https://fabianfett.de/amazonlinux-swift). You may want to use a later version if that works for you!
6969

7070
### Step 1: Develop your lambda
7171

@@ -82,7 +82,7 @@ The easiest way to go forward from here is to drag the newly created `Package.sw
8282
Next, we will need to include the `LambdaRuntime` and `SwiftNIO` as dependencies. For that open the `Package.swift` and modify it so that it looks like this:
8383

8484
```swift
85-
// swift-tools-version:5.1
85+
// swift-tools-version:5.2
8686
// The swift-tools-version declares the minimum version of Swift required to build this package.
8787

8888
import PackageDescription
@@ -96,7 +96,10 @@ let package = Package(
9696
targets: [
9797
.target(
9898
name: "SquareNumber",
99-
dependencies: ["LambdaRuntime", "NIO"]
99+
dependencies: [
100+
.product(name: "LambdaRuntime", package: "swift-lambda-runtime"),
101+
.product(name: "NIO", package: "swift-nio"),
102+
]
100103
),
101104
]
102105
)
@@ -158,14 +161,14 @@ RUN yum -y update && \
158161
To create your Docker image run:
159162

160163
```bash
161-
docker build --build-arg SWIFT_VERSION=5.1.3 -t lambda-swift-dev:5.1.3 .
164+
docker build --build-arg SWIFT_VERSION=5.2.1 -t lambda-swift-dev:5.2.1 .
162165
```
163166

164167
Now we can compile our lambda with the new image.
165168

166169
```bash
167170
# build your lambda in the linux environment
168-
$ docker run --rm --volume "$(pwd)/:/src" --workdir "/src/" lambda-swift-dev:5.1.3 swift build -c release
171+
$ docker run --rm --volume "$(pwd)/:/src" --workdir "/src/" lambda-swift-dev:5.2.1 swift build -c release
169172
```
170173

171174
This will create a `SquareNumber` executable in your `./build/release` folder. Let's grab the executable and rename it to `bootstrap`.
@@ -190,7 +193,7 @@ You'll see a screen that looks like this.
190193

191194
![Create your function](docs/Function-Create.png)
192195

193-
First we need to select our Swift runtime. We do so by clicking "Layers" below the function name in the center of the screen. The lower part of the screen changes and we can see an "Add Layer" button in the center. Let's click that button. On the next screen we need to select "Provide a layer version ARN" and there we enter the ARN that fits the Swift version that we've used to compile. For Swift `5.1.3` this is `arn:aws:lambda:<region>:426836788079:layer:Swift:8`. Do not forget to replace `<region>` with the AWS region identifier you operate in. Next we click "Add".
196+
First we need to select our Swift runtime. We do so by clicking "Layers" below the function name in the center of the screen. The lower part of the screen changes and we can see an "Add Layer" button in the center. Let's click that button. On the next screen we need to select "Provide a layer version ARN" and there we enter the ARN that fits the Swift version that we've used to compile. For Swift `5.2.1` this is `arn:aws:lambda:<region>:426836788079:layer:Swift:12`. Do not forget to replace `<region>` with the AWS region identifier you operate in. Next we click "Add".
194197

195198
![Add the Swift layer to your Function](docs/Add-Layer-to-Function.png)
196199

examples/EventSources/makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ LAMBDA_NAME=EventSources
33
EXECUTABLE=$(LAMBDA_NAME)
44
LAMBDA_ZIP=lambda.zip
55

6-
SWIFT_VERSION=5.1.4
6+
SWIFT_VERSION=5.2.1
77
SWIFT_DOCKER_IMAGE=fabianfett/amazonlinux-swift:${SWIFT_VERSION}-amazonlinux2-dev
88

99
clean_lambda:

examples/EventSources/template.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Parameters:
44
SwiftLayer:
55
Type: String
66
Description: The arn of the swift layer.
7-
Default: arn:aws:lambda:eu-central-1:426836788079:layer:Swift:9
7+
Default: arn:aws:lambda:eu-central-1:426836788079:layer:Swift:11
88

99
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
1010
Globals:

examples/SquareNumber/makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ LAMBDA_NAME=SquareNumber
33
EXECUTABLE=$(LAMBDA_NAME)
44
LAMBDA_ZIP=lambda.zip
55

6-
SWIFT_VERSION=5.1.4
6+
SWIFT_VERSION=5.2.1
77
SWIFT_DOCKER_IMAGE=fabianfett/amazonlinux-swift:${SWIFT_VERSION}-amazonlinux2-dev
88

99
clean_lambda:

examples/TodoAPIGateway/Package.resolved

+14-14
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@
66
"repositoryURL": "https://github.com/swift-server/async-http-client.git",
77
"state": {
88
"branch": null,
9-
"revision": "48e284d1ea6d0e8baac1af1c4ad8bd298670caf6",
10-
"version": "1.0.1"
9+
"revision": "037b70291941fe43de668066eb6fb802c5e181d2",
10+
"version": "1.1.1"
1111
}
1212
},
1313
{
1414
"package": "AWSSDKSwift",
1515
"repositoryURL": "https://github.com/swift-aws/aws-sdk-swift.git",
1616
"state": {
1717
"branch": null,
18-
"revision": "22c57f8ec403a28d89dccf5450b928998f82fdc6",
19-
"version": "4.0.0"
18+
"revision": "baddfc4e750a961d7bb00fc6258541807b460ec1",
19+
"version": "4.4.0"
2020
}
2121
},
2222
{
2323
"package": "AWSSDKSwiftCore",
2424
"repositoryURL": "https://github.com/swift-aws/aws-sdk-swift-core.git",
2525
"state": {
2626
"branch": null,
27-
"revision": "29d059a323c079c731bca969909321142034a036",
28-
"version": "4.0.0"
27+
"revision": "76502e37e04c94fd4da99ecb407cc7edbd371ed0",
28+
"version": "4.3.1"
2929
}
3030
},
3131
{
@@ -69,35 +69,35 @@
6969
"repositoryURL": "https://github.com/apple/swift-nio.git",
7070
"state": {
7171
"branch": null,
72-
"revision": "f6487a11d80bfb9a0a0a752b7442847c7e3a8253",
73-
"version": "2.12.0"
72+
"revision": "e876fb37410e0036b98b5361bb18e6854739572b",
73+
"version": "2.16.0"
7474
}
7575
},
7676
{
7777
"package": "swift-nio-extras",
7878
"repositoryURL": "https://github.com/apple/swift-nio-extras.git",
7979
"state": {
8080
"branch": null,
81-
"revision": "53808818c2015c45247cad74dc05c7a032c96a2f",
82-
"version": "1.3.2"
81+
"revision": "b4dbfacff47fb8d0f9e0a422d8d37935a9f10570",
82+
"version": "1.4.0"
8383
}
8484
},
8585
{
8686
"package": "swift-nio-ssl",
8787
"repositoryURL": "https://github.com/apple/swift-nio-ssl.git",
8888
"state": {
8989
"branch": null,
90-
"revision": "b75ffaba05b2cffdb1420d558f1a90b4e6c46dcc",
91-
"version": "2.5.0"
90+
"revision": "ae213938e151964aa691f0e902462fbe06baeeb6",
91+
"version": "2.7.1"
9292
}
9393
},
9494
{
9595
"package": "swift-nio-transport-services",
9696
"repositoryURL": "https://github.com/apple/swift-nio-transport-services.git",
9797
"state": {
9898
"branch": null,
99-
"revision": "c7f06384dc5ce7e8506de5ed9b59e35b4d88c64b",
100-
"version": "1.3.0"
99+
"revision": "85a67aea7caf5396ed599543dd23cffeb6dbbf96",
100+
"version": "1.5.1"
101101
}
102102
}
103103
]

examples/TodoAPIGateway/Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let package = Package(
1212
dependencies: [
1313
.package(url: "https://github.com/apple/swift-nio.git", .upToNextMajor(from: "2.9.0")),
1414
.package(url: "https://github.com/apple/swift-log.git", .upToNextMajor(from: "1.1.1")),
15-
.package(url: "https://github.com/swift-aws/aws-sdk-swift.git", .upToNextMajor(from: "4.0.0")),
15+
.package(url: "https://github.com/swift-aws/aws-sdk-swift.git", .upToNextMajor(from: "4.4.0")),
1616
.package(path: "../../"),
1717
],
1818
targets: [

examples/TodoAPIGateway/makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ LAMBDA_NAME=TodoAPIGateway
33
EXECUTABLE=$(LAMBDA_NAME)
44
LAMBDA_ZIP=lambda.zip
55

6-
SWIFT_VERSION=5.1.4
6+
SWIFT_VERSION=5.2.1
77
SWIFT_DOCKER_IMAGE=fabianfett/amazonlinux-swift:${SWIFT_VERSION}-amazonlinux2-dev
88

99
clean_lambda:

examples/TodoAPIGateway/template.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Resources:
4545
Handler: "list"
4646
Runtime: provided
4747
Layers:
48-
- arn:aws:lambda:eu-central-1:426836788079:layer:Swift:9
48+
- arn:aws:lambda:eu-central-1:426836788079:layer:Swift:11
4949
Policies:
5050
- DynamoDBReadPolicy:
5151
TableName: "SwiftLambdaTodos"
@@ -64,7 +64,7 @@ Resources:
6464
Handler: "create"
6565
Runtime: provided
6666
Layers:
67-
- arn:aws:lambda:eu-central-1:426836788079:layer:Swift:9
67+
- arn:aws:lambda:eu-central-1:426836788079:layer:Swift:11
6868
Policies:
6969
- DynamoDBCrudPolicy:
7070
TableName: "SwiftLambdaTodos"
@@ -83,7 +83,7 @@ Resources:
8383
Handler: "deleteAll"
8484
Runtime: provided
8585
Layers:
86-
- arn:aws:lambda:eu-central-1:426836788079:layer:Swift:9
86+
- arn:aws:lambda:eu-central-1:426836788079:layer:Swift:11
8787
Policies:
8888
- DynamoDBCrudPolicy:
8989
TableName: "SwiftLambdaTodos"
@@ -102,7 +102,7 @@ Resources:
102102
Handler: "getTodo"
103103
Runtime: provided
104104
Layers:
105-
- arn:aws:lambda:eu-central-1:426836788079:layer:Swift:9
105+
- arn:aws:lambda:eu-central-1:426836788079:layer:Swift:11
106106
Policies:
107107
- DynamoDBReadPolicy:
108108
TableName: "SwiftLambdaTodos"
@@ -121,7 +121,7 @@ Resources:
121121
Handler: "deleteTodo"
122122
Runtime: provided
123123
Layers:
124-
- arn:aws:lambda:eu-central-1:426836788079:layer:Swift:9
124+
- arn:aws:lambda:eu-central-1:426836788079:layer:Swift:11
125125
Policies:
126126
- DynamoDBCrudPolicy:
127127
TableName: "SwiftLambdaTodos"
@@ -140,7 +140,7 @@ Resources:
140140
Handler: "patchTodo"
141141
Runtime: provided
142142
Layers:
143-
- arn:aws:lambda:eu-central-1:426836788079:layer:Swift:9
143+
- arn:aws:lambda:eu-central-1:426836788079:layer:Swift:11
144144
Policies:
145145
- DynamoDBCrudPolicy:
146146
TableName: "SwiftLambdaTodos"

examples/URLRequestWithSession/makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ LAMBDA_NAME=URLRequestWithSession
33
EXECUTABLE=$(LAMBDA_NAME)
44
LAMBDA_ZIP=lambda.zip
55

6-
SWIFT_VERSION=5.1.4
6+
SWIFT_VERSION=5.2.1
77
SWIFT_DOCKER_IMAGE=fabianfett/amazonlinux-swift:${SWIFT_VERSION}-amazonlinux2-dev
88

99
clean_lambda:

examples/URLRequestWithSession/template.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Resources:
1919
Handler: "echoCall"
2020
Runtime: provided
2121
Layers:
22-
- arn:aws:lambda:eu-central-1:426836788079:layer:Swift:9
22+
- arn:aws:lambda:eu-central-1:426836788079:layer:Swift:11
2323

2424

2525

0 commit comments

Comments
 (0)