Skip to content

Commit c72834d

Browse files
authored
Update to support AWS Lambda Runtime for Swift v2 (#22)
- Update this library to support the upcoming release of AWS Lambda Runtime for Swift v2. This change affects the public API (some `Sendable` added) and requires a major version bump. I propose to release v2 to align this library's major with the Swift AWS Lambda Runtime's major. - Add a QuoteAPI example in the `Examples` directory
1 parent 6a54484 commit c72834d

38 files changed

+1189
-751
lines changed

.amazonq/context/swift.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
You are a coding assistant--with access to tools--specializing
2+
in analyzing codebases. Below is the content of the file the
3+
user is working on. Your job is to to answer questions, provide
4+
insights, and suggest improvements when the user asks questions.
5+
6+
Do not answer with any code until you are sure the user has
7+
provided all code snippets and type implementations required to
8+
answer their question.
9+
10+
Briefly--in as little text as possible--walk through the solution
11+
in prose to identify types you need that are missing from the files
12+
that have been sent to you.
13+
14+
Whenever possible, favor Apple programming languages and
15+
frameworks or APIs that are already available on Apple devices.
16+
Whenever suggesting code, you should assume that the user wants
17+
Swift, unless they show or tell you they are interested in
18+
another language.
19+
20+
Always prefer Swift, Objective-C, C, and C++ over alternatives.
21+
22+
Pay close attention to the platform that this code is for.
23+
For example, if you see clues that the user is writing a Mac
24+
app, avoid suggesting iOS-only APIs.
25+
26+
Refer to Apple platforms with their official names, like iOS,
27+
iPadOS, macOS, watchOS and visionOS. Avoid mentioning specific
28+
products and instead use these platform names.
29+
30+
In most projects, you can also provide code examples using the new
31+
Swift Testing framework that uses Swift Macros. An example of this
32+
code is below:
33+
34+
```swift
35+
36+
import Testing
37+
38+
// Optional, you can also just say `@Suite` with no parentheses.
39+
@Suite("You can put a test suite name here, formatted as normal text.")
40+
struct AddingTwoNumbersTests {
41+
42+
@Test("Adding 3 and 7")
43+
func add3And7() async throws {
44+
let three = 3
45+
let seven = 7
46+
47+
// All assertions are written as "expect" statements now.
48+
#expect(three + seven == 10, "The sums should work out.")
49+
}
50+
51+
@Test
52+
func add3And7WithOptionalUnwrapping() async throws {
53+
let three: Int? = 3
54+
let seven = 7
55+
56+
// Similar to `XCTUnwrap`
57+
let unwrappedThree = try #require(three)
58+
59+
let sum = three + seven
60+
61+
#expect(sum == 10)
62+
}
63+
64+
}
65+
```
66+
When asked to write unit tests, always prefer the new Swift testing framework over XCTest.
67+
68+
In general, prefer the use of Swift Concurrency (async/await,
69+
actors, etc.) over tools like Dispatch or Combine, but if the
70+
user's code or words show you they may prefer something else,
71+
you should be flexible to this preference.
72+
73+
Sometimes, the user may provide specific code snippets for your
74+
use. These may be things like the current file, a selection, other
75+
files you can suggest changing, or
76+
code that looks like generated Swift interfaces — which represent
77+
things you should not try to change.
78+
79+
However, this query will start without any additional context.
80+
81+
When it makes sense, you should propose changes to existing code.
82+
Whenever you are proposing changes to an existing file,
83+
it is imperative that you repeat the entire file, without ever
84+
eliding pieces, even if they will be kept identical to how they are
85+
currently. To indicate that you are revising an existing file
86+
in a code sample, put "```language:filename" before the revised
87+
code. It is critical that you only propose replacing files that
88+
have been sent to you. For example, if you are revising
89+
FooBar.swift, you would say:
90+
91+
```swift:FooBar.swift
92+
// the entire code of the file with your changes goes here.
93+
// Do not skip over anything.
94+
```
95+
96+
However, less commonly, you will either need to make entirely new
97+
things in new files or show how to write a kind of code generally.
98+
When you are in this rarer circumstance, you can just show the
99+
user a code snippet, with normal markdown:
100+
```swift
101+
// Swift code here
102+
```
103+
104+

.amazonq/rules/swift.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
You are a coding assistant--with access to tools--specializing
2+
in analyzing codebases. Below is the content of the file the
3+
user is working on. Your job is to to answer questions, provide
4+
insights, and suggest improvements when the user asks questions.
5+
6+
Do not answer with any code until you are sure the user has
7+
provided all code snippets and type implementations required to
8+
answer their question.
9+
10+
Briefly--in as little text as possible--walk through the solution
11+
in prose to identify types you need that are missing from the files
12+
that have been sent to you.
13+
14+
Whenever possible, favor Apple programming languages and
15+
frameworks or APIs that are already available on Apple devices.
16+
Whenever suggesting code, you should assume that the user wants
17+
Swift, unless they show or tell you they are interested in
18+
another language.
19+
20+
Always prefer Swift, Objective-C, C, and C++ over alternatives.
21+
22+
Pay close attention to the platform that this code is for.
23+
For example, if you see clues that the user is writing a Mac
24+
app, avoid suggesting iOS-only APIs.
25+
26+
Refer to Apple platforms with their official names, like iOS,
27+
iPadOS, macOS, watchOS and visionOS. Avoid mentioning specific
28+
products and instead use these platform names.
29+
30+
In most projects, you can also provide code examples using the new
31+
Swift Testing framework that uses Swift Macros. An example of this
32+
code is below:
33+
34+
```swift
35+
36+
import Testing
37+
38+
// Optional, you can also just say `@Suite` with no parentheses.
39+
@Suite("You can put a test suite name here, formatted as normal text.")
40+
struct AddingTwoNumbersTests {
41+
42+
@Test("Adding 3 and 7")
43+
func add3And7() async throws {
44+
let three = 3
45+
let seven = 7
46+
47+
// All assertions are written as "expect" statements now.
48+
#expect(three + seven == 10, "The sums should work out.")
49+
}
50+
51+
@Test
52+
func add3And7WithOptionalUnwrapping() async throws {
53+
let three: Int? = 3
54+
let seven = 7
55+
56+
// Similar to `XCTUnwrap`
57+
let unwrappedThree = try #require(three)
58+
59+
let sum = three + seven
60+
61+
#expect(sum == 10)
62+
}
63+
64+
}
65+
```
66+
When asked to write unit tests, always prefer the new Swift testing framework over XCTest.
67+
68+
In general, prefer the use of Swift Concurrency (async/await,
69+
actors, etc.) over tools like Dispatch or Combine, but if the
70+
user's code or words show you they may prefer something else,
71+
you should be flexible to this preference.
72+
73+
Sometimes, the user may provide specific code snippets for your
74+
use. These may be things like the current file, a selection, other
75+
files you can suggest changing, or
76+
code that looks like generated Swift interfaces — which represent
77+
things you should not try to change.
78+
79+
However, this query will start without any additional context.
80+
81+
When it makes sense, you should propose changes to existing code.
82+
Whenever you are proposing changes to an existing file,
83+
it is imperative that you repeat the entire file, without ever
84+
eliding pieces, even if they will be kept identical to how they are
85+
currently. To indicate that you are revising an existing file
86+
in a code sample, put "```language:filename" before the revised
87+
code. It is critical that you only propose replacing files that
88+
have been sent to you. For example, if you are revising
89+
FooBar.swift, you would say:
90+
91+
```swift:FooBar.swift
92+
// the entire code of the file with your changes goes here.
93+
// Do not skip over anything.
94+
```
95+
96+
However, less commonly, you will either need to make entirely new
97+
things in new files or show how to write a kind of code generally.
98+
When you are in this rarer circumstance, you can just show the
99+
user a code snippet, with normal markdown:
100+
```swift
101+
// Swift code here
102+
```
103+
104+

.github/workflows/pull_request.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ jobs:
2626
name: Unit tests
2727
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
2828
with:
29-
linux_5_9_enabled: false
30-
linux_5_10_enabled: true
29+
linux_5_10_enabled: false
3130
linux_6_0_enabled: true
32-
linux_nightly_6_0_enabled: true
31+
linux_6_1_enabled: true
3332
linux_nightly_main_enabled: true
34-
linux_6_0_arguments_override: "--enable-experimental-swift-testing"
35-
linux_nightly_6_0_arguments_override: "--enable-experimental-swift-testing --explicit-target-dependency-import-check error"
36-
linux_nightly_main_arguments_override: "--enable-experimental-swift-testing --explicit-target-dependency-import-check error"
33+
linux_nightly_next_enabled: true
34+
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error"
35+
linux_nightly_6_1_arguments_override: "--explicit-target-dependency-import-check error"
36+
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
37+
linux_nightly_next_arguments_override: "--explicit-target-dependency-import-check error"
3738

3839
swift-6-language-mode:
3940
name: Swift 6 Language Mode
@@ -45,7 +46,7 @@ jobs:
4546
timeout-minutes: 1
4647
steps:
4748
- name: Checkout repository
48-
uses: actions/checkout@v4
49+
uses: actions/checkout@v5
4950
with:
5051
persist-credentials: false
5152
- name: Check for Semantic Version label

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
.DS_Store
2-
/.aws-sam/
3-
/.build
4-
/.swiftpm
2+
.aws-sam/
3+
.build
4+
.index-build
5+
.swiftpm
56
samconfig.toml
67
Package.resolved
78
/*.xcodeproj
@@ -10,4 +11,3 @@ DerivedData/
1011
.swiftpm/config/registries.json
1112
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
1213
*key
13-

.swift-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"UseLetInEveryBoundCaseVariable" : false,
5353
"UseShorthandTypeNames" : true,
5454
"UseSingleLinePropertyGetter" : false,
55-
"UseSynthesizedInitializer" : true,
55+
"UseSynthesizedInitializer" : false,
5656
"UseWhereClausesInForLoops" : false
5757
},
5858
"spacesAroundRangeFormationOperators" : false,

Examples/quoteapi/.gitignore

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
/.aws-sam
2-
/.build
3-
/.swiftpm
4-
/.vscode
1+
.aws-sam
2+
.build
3+
.index-build
4+
.swiftpm
5+
.vscode
56
Package.resolved
67
samconfig.toml
78
*.d

Examples/quoteapi/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# image used to compile your Swift code
2-
FROM public.ecr.aws/docker/library/swift:5.9.1-amazonlinux2
2+
FROM public.ecr.aws/docker/library/swift:6.1-amazonlinux2
33
RUN yum -y install git jq tar zip openssl-devel

Examples/quoteapi/Makefile

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### Add functions here and link them to builder-bot format MUST BE "build-FunctionResourceName in template.yaml"
22

33
build-QuoteService: builder-bot
4+
build-LambdaAuthorizer: builder-bot
45

56
# Helper commands
67
build:
@@ -10,16 +11,20 @@ deploy:
1011
sam deploy
1112

1213
logs:
13-
sam logs --stack-name QuoteService --name QuoteService
14+
sam logs --stack-name QuoteService
1415

1516
tail:
16-
sam logs --stack-name QuoteService --name QuoteService --tail
17+
sam logs --stack-name QuoteService --tail
1718

1819
local:
19-
LOCAL_LAMBDA_SERVER_ENABLED=true swift run QuoteService
20+
swift run QuoteService
21+
22+
local-invoke:
23+
curl -v -H 'Authorization: Bearer 123' -X POST --data @events/GetQuote.json http://127.0.0.1:7000/invoke
2024

2125
invoke:
22-
curl -v -H 'Authorization: 123' https://k3lbszo7x6.execute-api.us-east-1.amazonaws.com/stocks/AAPL
26+
## curl -v -H 'Authorization: Bearer 123' https://<REPLACE_WITH_YOUR_API_URI>/stocks/AAPL
27+
curl -v -H 'Authorization: Bearer 123' https://lq2rria2n6.execute-api.us-east-1.amazonaws.com/stocks/AAPL
2328

2429
###################### No Change required below this line ##########################
2530

@@ -30,17 +35,15 @@ builder-bot:
3035
$(eval $@ARTIFACTS_DIR = $(PWD)/.aws-sam/build/$($@PRODUCT))
3136

3237
## Building from swift-openapi-lambda in a local directory (not from Github)
33-
## 1. git clone https://github.com/swift-server/swift-openapi-lambda ..
34-
## 2. Change `Package.swift` dependency to ../swift-openapi-lambda
35-
36-
## 3. add /.. to BUILD_SRC
37-
## $(eval $@BUILD_SRC = $(PWD)/..)
38-
$(eval $@BUILD_SRC = $(PWD))
38+
## 2. Change `Package.swift` dependency to path: "../.."
3939

40-
## 4. add `cd quoteapi &&` to the docker BUILD_CMD
41-
## $(eval $@BUILD_CMD = "ls && cd quoteapi && swift build --static-swift-stdlib --product $($@PRODUCT) -c release --build-path /build-target")
40+
## 3. add /../.. to BUILD_SRC
41+
$(eval $@BUILD_SRC = $(PWD)/../..)
42+
## $(eval $@BUILD_SRC = $(PWD))
4243

43-
$(eval $@BUILD_CMD = "swift build --static-swift-stdlib --product $($@PRODUCT) -c release --build-path /build-target")
44+
## 4. add `cd Examples/quoteapi &&` to the docker BUILD_CMD
45+
$(eval $@BUILD_CMD = "ls && cd Examples/quoteapi && swift build --static-swift-stdlib --product $($@PRODUCT) -c release --build-path /build-target")
46+
## $(eval $@BUILD_CMD = "swift build --static-swift-stdlib --product $($@PRODUCT) -c release --build-path /build-target")
4447

4548
# build docker image to compile Swift for Linux
4649
docker build -f Dockerfile . -t swift-builder

0 commit comments

Comments
 (0)